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
8 changes: 7 additions & 1 deletion src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
getTrackExpenseActionableWhisper,
isActionableTrackExpense,
isCreatedAction,
isDeletedAction,
isMoneyRequestAction,
isReportPreviewAction,
} from '@libs/ReportActionsUtils';
Expand Down Expand Up @@ -623,7 +624,7 @@
};

let allPersonalDetails: OnyxTypes.PersonalDetailsList = {};
Onyx.connect({

Check warning on line 627 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
allPersonalDetails = value ?? {};
Expand Down Expand Up @@ -663,7 +664,7 @@
};

let allTransactions: NonNullable<OnyxCollection<OnyxTypes.Transaction>> = {};
Onyx.connect({

Check warning on line 667 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -677,7 +678,7 @@
});

let allTransactionDrafts: NonNullable<OnyxCollection<OnyxTypes.Transaction>> = {};
Onyx.connect({

Check warning on line 681 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION_DRAFT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -686,7 +687,7 @@
});

let allTransactionViolations: NonNullable<OnyxCollection<OnyxTypes.TransactionViolations>> = {};
Onyx.connect({

Check warning on line 690 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -700,7 +701,7 @@
});

let allDraftSplitTransactions: NonNullable<OnyxCollection<OnyxTypes.Transaction>> = {};
Onyx.connect({

Check warning on line 704 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.SPLIT_TRANSACTION_DRAFT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -709,7 +710,7 @@
});

let allNextSteps: NonNullable<OnyxCollection<OnyxTypes.ReportNextStep>> = {};
Onyx.connect({

Check warning on line 713 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.NEXT_STEP,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -718,14 +719,14 @@
});

let allPolicyCategories: OnyxCollection<OnyxTypes.PolicyCategories> = {};
Onyx.connect({

Check warning on line 722 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY_CATEGORIES,
waitForCollectionCallback: true,
callback: (val) => (allPolicyCategories = val),
});

const allPolicies: OnyxCollection<OnyxTypes.Policy> = {};
Onyx.connect({

Check warning on line 729 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY,
callback: (val, key) => {
if (!key) {
Expand Down Expand Up @@ -758,7 +759,7 @@
});

let allReports: OnyxCollection<OnyxTypes.Report>;
Onyx.connect({

Check warning on line 762 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -767,7 +768,7 @@
});

let allReportNameValuePairs: OnyxCollection<OnyxTypes.ReportNameValuePairs>;
Onyx.connect({

Check warning on line 771 in src/libs/actions/IOU.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS,
waitForCollectionCallback: true,
callback: (value) => {
Expand Down Expand Up @@ -9239,7 +9240,12 @@
// eslint-disable-next-line deprecation/deprecation
const policy = getPolicy(iouReport?.policyID);
const shouldShowSettlementButton = canIOUBePaid(iouReport, chatReport, policy) || canApproveIOU(iouReport, policy);
return action.childReportID?.toString() !== excludedIOUReportID && action.actionName === CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW && shouldShowSettlementButton;
return (
action.childReportID?.toString() !== excludedIOUReportID &&
action.actionName === CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW &&
shouldShowSettlementButton &&
!isDeletedAction(action)
);
});
}

Expand Down
79 changes: 79 additions & 0 deletions tests/actions/IOUTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
canUnapproveIOU,
createDistanceRequest,
deleteMoneyRequest,
getIOUReportActionToApproveOrPay,
initMoneyRequest,
initSplitExpense,
payMoneyRequest,
Expand Down Expand Up @@ -6398,4 +6399,82 @@ describe('actions/IOU', () => {
});
});
});

describe('getIOUReportActionToApproveOrPay', () => {
it('should exclude deleted actions', async () => {
const reportID = '1';
const policyID = '2';
const fakePolicy: Policy = {
...createRandomPolicy(Number(policyID)),
approvalMode: CONST.POLICY.APPROVAL_MODE.BASIC,
type: CONST.POLICY.TYPE.TEAM,
};

const fakeReport: Report = {
...createRandomReport(Number(reportID)),
type: CONST.REPORT.TYPE.EXPENSE,
policyID,
stateNum: CONST.REPORT.STATE_NUM.SUBMITTED,
statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED,
managerID: RORY_ACCOUNT_ID,
chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT,
};
const fakeTransaction1: Transaction = {
...createRandomTransaction(0),
reportID,
bank: CONST.EXPENSIFY_CARD.BANK,
status: CONST.TRANSACTION.STATUS.PENDING,
};
const fakeTransaction2: Transaction = {
...createRandomTransaction(1),
reportID,
amount: 27,
receipt: {
source: 'test',
state: CONST.IOU.RECEIPT_STATE.SCAN_FAILED,
},
merchant: CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT,
modifiedMerchant: undefined,
};
const fakeTransaction3: Transaction = {
...createRandomTransaction(2),
reportID,
amount: 100,
};

await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${fakeReport.reportID}`, fakeReport);
await Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION}${fakeTransaction1.transactionID}`, fakeTransaction1);
await Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION}${fakeTransaction2.transactionID}`, fakeTransaction2);
await Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION}${fakeTransaction3.transactionID}`, fakeTransaction3);
await Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, fakePolicy);
await waitForBatchedUpdates();

const deletedReportAction = {
reportActionID: '0',
actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW,
created: '2024-08-08 18:70:44.171',
childReportID: reportID,
};

const MOCK_REPORT_ACTIONS: ReportActions = {
[deletedReportAction.reportActionID]: deletedReportAction,
[reportID]: {
reportActionID: reportID,
actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW,
created: '2024-08-08 19:70:44.171',
childReportID: reportID,
message: [
{
type: 'TEXT',
text: 'Hello world!',
},
],
},
};

await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${fakeReport.reportID}`, MOCK_REPORT_ACTIONS);

expect(getIOUReportActionToApproveOrPay(fakeReport, undefined)).toMatchObject(MOCK_REPORT_ACTIONS[reportID]);
});
});
});
12 changes: 12 additions & 0 deletions tests/unit/DebugUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1077,13 +1077,25 @@ describe('DebugUtils', () => {
reportActionID: '0',
actionName: CONST.REPORT.ACTIONS.TYPE.CREATED,
created: '2024-08-08 18:70:44.171',
message: [
{
type: 'TEXT',
text: 'Hello world!',
},
],
},
// eslint-disable-next-line @typescript-eslint/naming-convention
'1': {
reportActionID: '1',
actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW,
created: '2024-08-08 19:70:44.171',
childReportID: '2',
message: [
{
type: 'TEXT',
text: 'Hello world!',
},
],
},
};
await Onyx.multiSet({
Expand Down
Loading