Skip to content

Commit 476c380

Browse files
authored
Merge pull request Expensify#87335 from DylanDylann/refactor-66578-p2
Part 2: Remove Onyx.connect() for the key: ONYXKEYS.COLLECTION.REPORT_ACTIONS in src/libs/actions/Policy/Policy.ts
2 parents 6c6d79c + ae690a6 commit 476c380

3 files changed

Lines changed: 71 additions & 3 deletions

File tree

src/components/KYCWall/BaseKYCWall.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ function KYCWall({
182182
localCurrency,
183183
lastWorkspaceNumber,
184184
translate,
185+
filteredReportActions,
185186
) ?? {};
186187
if (policyID && iouReport?.policyID) {
187188
savePreferredPaymentMethod(iouReport.policyID, policyID, CONST.LAST_PAYMENT_METHOD.IOU, lastPaymentMethod?.[iouReport?.policyID]);

src/libs/actions/Policy/Policy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3944,6 +3944,7 @@ function createWorkspaceFromIOUPayment(
39443944
currentUserLocalCurrency: string,
39453945
lastWorkspaceNumber: number | undefined,
39463946
localeTranslate: LocalizedTranslate,
3947+
reportActionsList: OnyxCollection<ReportActions>,
39473948
): WorkspaceFromIOUCreationData | undefined {
39483949
// This flow only works for IOU reports
39493950
if (!iouReport || !ReportUtils.isIOUReportUsingReport(iouReport)) {
@@ -3975,8 +3976,7 @@ function createWorkspaceFromIOUPayment(
39753976
}
39763977

39773978
// Create the expense chat for the employee whose IOU is being paid
3978-
// TODO: Update to include reportActionsList later (https://github.com/Expensify/App/issues/66578)
3979-
const employeeWorkspaceChat = createPolicyExpenseChats(policyID, {[iouReportOwnerEmail]: employeeAccountID}, undefined, true);
3979+
const employeeWorkspaceChat = createPolicyExpenseChats(policyID, {[iouReportOwnerEmail]: employeeAccountID}, reportActionsList, true);
39803980
const newWorkspace = {
39813981
id: policyID,
39823982

tests/actions/PolicyTest.ts

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6017,7 +6017,7 @@ describe('actions/Policy', () => {
60176017

60186018
// eslint-disable-next-line @typescript-eslint/naming-convention
60196019
const mockTranslate = ((key: string) => key) as unknown as Parameters<typeof Policy.createWorkspaceFromIOUPayment>[8];
6020-
Policy.createWorkspaceFromIOUPayment(iouReport, undefined, customAccountID, customEmail, iouReportOwnerEmail, undefined, CONST.CURRENCY.USD, undefined, mockTranslate);
6020+
Policy.createWorkspaceFromIOUPayment(iouReport, undefined, customAccountID, customEmail, iouReportOwnerEmail, undefined, CONST.CURRENCY.USD, undefined, mockTranslate, {});
60216021
await waitForBatchedUpdates();
60226022

60236023
const writeOptions = apiWriteSpy.mock.calls.at(0)?.at(2) as {
@@ -6059,8 +6059,75 @@ describe('actions/Policy', () => {
60596059
CONST.CURRENCY.USD,
60606060
undefined,
60616061
mockTranslate,
6062+
{},
60626063
);
60636064
expect(result).toBeUndefined();
60646065
});
6066+
6067+
it('should use reportActionsList parameter instead of deprecated Onyx connection', async () => {
6068+
await Onyx.set(ONYXKEYS.SESSION, {email: ESH_EMAIL, accountID: ESH_ACCOUNT_ID});
6069+
await waitForBatchedUpdates();
6070+
6071+
const employeeAccountID = 300;
6072+
const iouReportOwnerEmail = 'employee@example.com';
6073+
6074+
const existingChatReportID = '700';
6075+
6076+
// Create a report preview action for the existing chat
6077+
const reportPreviewAction: ReportAction = {
6078+
reportActionID: 'previewAction1',
6079+
actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW,
6080+
childReportID: 'childReport1',
6081+
created: '2024-01-01',
6082+
message: [],
6083+
};
6084+
6085+
// Pass reportActionsList explicitly - this should be used instead of the deprecated Onyx connection
6086+
const reportActionsList = {
6087+
[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${existingChatReportID}`]: {
6088+
[reportPreviewAction.reportActionID]: reportPreviewAction,
6089+
},
6090+
};
6091+
6092+
const iouReport: Report = {
6093+
...createRandomReport(1, undefined),
6094+
reportID: '800',
6095+
type: CONST.REPORT.TYPE.IOU,
6096+
ownerAccountID: employeeAccountID,
6097+
chatReportID: '801',
6098+
policyID: 'oldPolicyID',
6099+
currency: CONST.CURRENCY.USD,
6100+
total: 2000,
6101+
};
6102+
6103+
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`, iouReport);
6104+
await waitForBatchedUpdates();
6105+
6106+
const isIOUReportUsingReportSpy = jest.spyOn(ReportUtils, 'isIOUReportUsingReport').mockReturnValue(true);
6107+
const apiWriteSpy = jest.spyOn(require('@libs/API'), 'write').mockImplementation(() => Promise.resolve());
6108+
6109+
// eslint-disable-next-line @typescript-eslint/naming-convention
6110+
const mockTranslate = ((key: string) => key) as unknown as Parameters<typeof Policy.createWorkspaceFromIOUPayment>[8];
6111+
const result = Policy.createWorkspaceFromIOUPayment(
6112+
iouReport,
6113+
undefined,
6114+
ESH_ACCOUNT_ID,
6115+
ESH_EMAIL,
6116+
iouReportOwnerEmail,
6117+
undefined,
6118+
CONST.CURRENCY.USD,
6119+
undefined,
6120+
mockTranslate,
6121+
reportActionsList,
6122+
);
6123+
6124+
// Verify the function returns a valid result (not undefined)
6125+
expect(result).toBeDefined();
6126+
expect(result?.policyID).toBeDefined();
6127+
expect(result?.workspaceChatReportID).toBeDefined();
6128+
6129+
apiWriteSpy.mockRestore();
6130+
isIOUReportUsingReportSpy.mockRestore();
6131+
});
60656132
});
60666133
});

0 commit comments

Comments
 (0)