Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ import {
hasWarningTypeViolation,
isCardTransaction as isCardTransactionTransactionUtils,
isDistanceRequest,
isDuplicate,
isExpensifyCardTransaction,
isFetchingWaypointsFromServer,
isOnHold as isOnHoldTransactionUtils,
Expand Down Expand Up @@ -3972,7 +3971,7 @@ function canHoldUnholdReportAction(reportAction: OnyxInputOrEntry<ReportAction>)

const canHoldOrUnholdRequest = !isRequestSettled && !isApproved && !isDeletedParentActionLocal && !isClosed && !isDeletedParentAction(reportAction);
const canHoldRequest = canHoldOrUnholdRequest && !isOnHold && (isRequestIOU || canModifyStatus) && !isScanning;
const canUnholdRequest = !!(canHoldOrUnholdRequest && isOnHold && !isDuplicate(transaction.transactionID, true) && (isRequestIOU ? isHoldActionCreator : canModifyUnholdStatus));
const canUnholdRequest = !!(canHoldOrUnholdRequest && isOnHold && (isRequestIOU ? isHoldActionCreator : canModifyUnholdStatus));

return {canHoldRequest, canUnholdRequest};
}
Expand Down
62 changes: 62 additions & 0 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {addDays, format as formatDate} from 'date-fns';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import useReportIsArchived from '@hooks/useReportIsArchived';
import {putOnHold} from '@libs/actions/IOU';
import DateUtils from '@libs/DateUtils';
import {translateLocal} from '@libs/Localize';
import {getOriginalMessage} from '@libs/ReportActionsUtils';
Expand All @@ -13,11 +14,13 @@ import {
buildOptimisticCreatedReportAction,
buildOptimisticExpenseReport,
buildOptimisticIOUReportAction,
buildOptimisticReportPreview,
buildParticipantsFromAccountIDs,
buildReportNameFromParticipantNames,
buildTransactionThread,
canDeleteReportAction,
canEditWriteCapability,
canHoldUnholdReportAction,
findLastAccessedReport,
getAllAncestorReportActions,
getApprovalChain,
Expand Down Expand Up @@ -1386,6 +1389,65 @@ describe('ReportUtils', () => {
});
});

describe('canHoldUnholdReportAction', () => {
it.only('should return canUnholdRequest as true for a held duplicate transaction', async () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FitseTLT oops! it.only() means this is the only test that is running. It took me a while to figure out why everything else was skipped! I'll fix this in my current PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uff I left it there sorry will raise a quick one Thx

const chatReport: Report = {reportID: '1'};
const reportPreviewReportActionID = '8';
const expenseReport = buildOptimisticExpenseReport(chatReport.reportID, '123', currentUserAccountID, 122, 'USD', undefined, reportPreviewReportActionID);
const expenseTransaction = buildOptimisticTransaction({
transactionParams: {
amount: 100,
currency: 'USD',
reportID: expenseReport.reportID,
},
});
const reportPreview = buildOptimisticReportPreview(chatReport, expenseReport, '', expenseTransaction, expenseReport.reportID, reportPreviewReportActionID);
const expenseCreatedAction = buildOptimisticIOUReportAction({
type: 'create',
amount: 100,
currency: 'USD',
comment: '',
participants: [],
transactionID: expenseTransaction.transactionID,
iouReportID: expenseReport.reportID,
});
const transactionThreadReport = buildTransactionThread(expenseCreatedAction, expenseReport);
expenseCreatedAction.childReportID = transactionThreadReport.reportID;

await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, {
currentUserAccountID: {
accountID: currentUserAccountID,
displayName: currentUserEmail,
login: currentUserEmail,
},
});
await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${expenseTransaction.transactionID}`, {...expenseTransaction});
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${expenseReport.reportID}`, expenseReport);
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReport.reportID}`, transactionThreadReport);
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.reportID}`, {
[expenseCreatedAction.reportActionID]: expenseCreatedAction,
});
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, {
[reportPreview.reportActionID]: reportPreview,
});
// Given a transaction with duplicate transaction violation
await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${expenseTransaction.transactionID}`, [
{
name: CONST.VIOLATIONS.DUPLICATED_TRANSACTION,
type: CONST.VIOLATION_TYPES.WARNING,
},
]);

expect(canHoldUnholdReportAction(expenseCreatedAction)).toEqual({canHoldRequest: true, canUnholdRequest: false});

putOnHold(expenseTransaction.transactionID, 'hold', transactionThreadReport.reportID);
await waitForBatchedUpdates();

// canUnholdRequest should be true after the transaction is held.
expect(canHoldUnholdReportAction(expenseCreatedAction)).toEqual({canHoldRequest: false, canUnholdRequest: true});
});
});

describe('getQuickActionDetails', () => {
it('if the report is archived, the quick action will hide the subtitle and avatar', () => {
// Create a fake archived report as quick action report
Expand Down