From 1fd0aae2e5f15d0584ec4a5d23e28c01e9a2997a Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Fri, 8 Nov 2024 13:59:46 +0700 Subject: [PATCH 1/8] refactor requestMoney function --- ios/NewExpensify.xcodeproj/project.pbxproj | 6 +- src/libs/actions/IOU.ts | 78 +++-- .../iou/request/step/IOURequestStepAmount.tsx | 24 +- .../step/IOURequestStepConfirmation.tsx | 53 ++-- .../step/IOURequestStepScan/index.native.tsx | 64 ++-- .../request/step/IOURequestStepScan/index.tsx | 64 ++-- tests/actions/IOUTest.ts | 278 ++++++++++++++---- 7 files changed, 373 insertions(+), 194 deletions(-) diff --git a/ios/NewExpensify.xcodeproj/project.pbxproj b/ios/NewExpensify.xcodeproj/project.pbxproj index d8eceab72b95..cd38fcaaaf6c 100644 --- a/ios/NewExpensify.xcodeproj/project.pbxproj +++ b/ios/NewExpensify.xcodeproj/project.pbxproj @@ -45,7 +45,7 @@ D27CE6B77196EF3EF450EEAC /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 0D3F9E814828D91464DF9D35 /* PrivacyInfo.xcprivacy */; }; DD79042B2792E76D004484B4 /* RCTBootSplash.mm in Sources */ = {isa = PBXBuildFile; fileRef = DD79042A2792E76D004484B4 /* RCTBootSplash.mm */; }; DDCB2E57F334C143AC462B43 /* ExpoModulesProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D20D83B0E39BA6D21761E72 /* ExpoModulesProvider.swift */; }; - E51DC681C7DEE40AEBDDFBFE /* (null) in Frameworks */ = {isa = PBXBuildFile; }; + E51DC681C7DEE40AEBDDFBFE /* BuildFile in Frameworks */ = {isa = PBXBuildFile; }; E9DF872D2525201700607FDC /* AirshipConfig.plist in Resources */ = {isa = PBXBuildFile; fileRef = E9DF872C2525201700607FDC /* AirshipConfig.plist */; }; ED222ED90E074A5481A854FA /* ExpensifyNeue-BoldItalic.otf in Resources */ = {isa = PBXBuildFile; fileRef = 8B28D84EF339436DBD42A203 /* ExpensifyNeue-BoldItalic.otf */; }; F0C450EA2705020500FD2970 /* colors.json in Resources */ = {isa = PBXBuildFile; fileRef = F0C450E92705020500FD2970 /* colors.json */; }; @@ -178,8 +178,8 @@ buildActionMask = 2147483647; files = ( 383643682B6D4AE2005BB9AE /* DeviceCheck.framework in Frameworks */, - E51DC681C7DEE40AEBDDFBFE /* (null) in Frameworks */, - E51DC681C7DEE40AEBDDFBFE /* (null) in Frameworks */, + E51DC681C7DEE40AEBDDFBFE /* BuildFile in Frameworks */, + E51DC681C7DEE40AEBDDFBFE /* BuildFile in Frameworks */, 8744C5400E24E379441C04A4 /* libPods-NewExpensify.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 1db2555f3393..87f35902a36a 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -164,6 +164,37 @@ type GPSPoint = { long: number; }; +type RequestMoneyInformation = { + report: OnyxEntry; + payeeEmail: string | undefined; + payeeAccountID: number; + participant: Participant; + policy?: OnyxEntry; + policyTagList?: OnyxEntry; + policyCategories?: OnyxEntry; + gpsPoints?: GPSPoint; + action?: IOUAction; + reimbursible?: boolean; +}; + +type RequestMoneyTransactionData = { + attendees: Attendee[] | undefined; + amount: number; + currency: string; + comment?: string; + receipt?: Receipt; + category?: string; + tag?: string; + taxCode?: string; + taxAmount?: number; + billable?: boolean; + merchant: string; + created: string; + actionableWhisperReportActionID?: string; + linkedTrackedExpenseReportAction?: OnyxTypes.ReportAction; + linkedTrackedExpenseReportID?: string; +}; + let allPersonalDetails: OnyxTypes.PersonalDetailsList = {}; Onyx.connect({ key: ONYXKEYS.PERSONAL_DETAILS_LIST, @@ -3558,33 +3589,26 @@ function shareTrackedExpense( /** * Submit expense to another user */ -function requestMoney( - report: OnyxEntry, - amount: number, - attendees: Attendee[] | undefined, - currency: string, - created: string, - merchant: string, - payeeEmail: string | undefined, - payeeAccountID: number, - participant: Participant, - comment: string, - receipt: Receipt | undefined, - category?: string, - tag?: string, - taxCode = '', - taxAmount = 0, - billable?: boolean, - policy?: OnyxEntry, - policyTagList?: OnyxEntry, - policyCategories?: OnyxEntry, - gpsPoints?: GPSPoint, - action?: IOUAction, - actionableWhisperReportActionID?: string, - linkedTrackedExpenseReportAction?: OnyxTypes.ReportAction, - linkedTrackedExpenseReportID?: string, - reimbursible?: boolean, -) { +function requestMoney(requestMoneyInformation: RequestMoneyInformation, requestMoneyTransactionData: RequestMoneyTransactionData) { + const {report, payeeEmail, payeeAccountID, participant, policy, policyTagList, policyCategories, gpsPoints, action, reimbursible} = requestMoneyInformation; + const { + amount, + currency, + merchant, + comment = '', + receipt, + category, + tag, + taxCode = '', + taxAmount = 0, + billable, + created, + attendees, + actionableWhisperReportActionID, + linkedTrackedExpenseReportAction, + linkedTrackedExpenseReportID, + } = requestMoneyTransactionData; + // If the report is iou or expense report, we should get the linked chat report to be passed to the getMoneyRequestInformation function const isMoneyRequestReport = ReportUtils.isMoneyRequestReport(report); const currentChatReport = isMoneyRequestReport ? ReportUtils.getReportOrDraftReport(report?.chatReportID) : report; diff --git a/src/pages/iou/request/step/IOURequestStepAmount.tsx b/src/pages/iou/request/step/IOURequestStepAmount.tsx index 9c6f39ea8c5a..8aced83515f4 100644 --- a/src/pages/iou/request/step/IOURequestStepAmount.tsx +++ b/src/pages/iou/request/step/IOURequestStepAmount.tsx @@ -210,17 +210,19 @@ function IOURequestStepAmount({ if (iouType === CONST.IOU.TYPE.SUBMIT || iouType === CONST.IOU.TYPE.REQUEST) { playSound(SOUNDS.DONE); IOU.requestMoney( - report, - backendAmount, - transaction?.attendees, - currency, - transaction?.created ?? '', - CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT, - currentUserPersonalDetails.login, - currentUserPersonalDetails.accountID, - participants.at(0) ?? {}, - '', - {}, + { + report, + participant: participants.at(0) ?? {}, + payeeEmail: currentUserPersonalDetails.login, + payeeAccountID: currentUserPersonalDetails.accountID, + }, + { + amount: backendAmount, + currency, + created: transaction?.created ?? '', + merchant: CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT, + attendees: transaction?.attendees, + }, ); return; } diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index aa3a432a0e5a..f268e7a03477 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -237,32 +237,35 @@ function IOURequestStepConfirmation({ if (!participant) { return; } - IOU.requestMoney( - report, - transaction.amount, - transaction.attendees, - transaction.currency, - transaction.created, - transaction.merchant, - currentUserPersonalDetails.login, - currentUserPersonalDetails.accountID, - participant, - trimmedComment, - receiptObj, - transaction.category, - transaction.tag, - transactionTaxCode, - transactionTaxAmount, - transaction.billable, - policy, - policyTags, - policyCategories, - gpsPoints, - action, - transaction.actionableWhisperReportActionID, - transaction.linkedTrackedExpenseReportAction, - transaction.linkedTrackedExpenseReportID, + { + report, + payeeEmail: currentUserPersonalDetails.login, + payeeAccountID: currentUserPersonalDetails.accountID, + participant, + policy, + policyTagList: policyTags, + policyCategories, + gpsPoints, + action, + }, + { + amount: transaction.amount, + attendees: transaction.attendees, + currency: transaction.currency, + created: transaction.created, + merchant: transaction.merchant, + comment: trimmedComment, + receipt: receiptObj, + category: transaction.category, + tag: transaction.tag, + taxCode: transactionTaxCode, + taxAmount: transactionTaxAmount, + billable: transaction.billable, + actionableWhisperReportActionID: transaction.actionableWhisperReportActionID, + linkedTrackedExpenseReportAction: transaction.linkedTrackedExpenseReportAction, + linkedTrackedExpenseReportID: transaction.linkedTrackedExpenseReportID, + }, ); }, [report, transaction, transactionTaxCode, transactionTaxAmount, currentUserPersonalDetails.login, currentUserPersonalDetails.accountID, policy, policyTags, policyCategories, action], diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx index f7e575b898fd..ff649dc303e1 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx @@ -255,17 +255,20 @@ function IOURequestStepScan({ ); } else { IOU.requestMoney( - report, - 0, - transaction?.attendees, - transaction?.currency ?? 'USD', - transaction?.created ?? '', - '', - currentUserPersonalDetails.login, - currentUserPersonalDetails.accountID, - participant, - '', - receipt, + { + report, + payeeEmail: currentUserPersonalDetails.login, + payeeAccountID: currentUserPersonalDetails.accountID, + participant, + }, + { + amount: 0, + attendees: transaction?.attendees, + currency: transaction?.currency ?? 'USD', + created: transaction?.created ?? '', + merchant: '', + receipt, + }, ); } }, @@ -351,28 +354,25 @@ function IOURequestStepScan({ ); } else { IOU.requestMoney( - report, - 0, - transaction?.attendees, - transaction?.currency ?? 'USD', - transaction?.created ?? '', - '', - currentUserPersonalDetails.login, - currentUserPersonalDetails.accountID, - participant, - '', - receipt, - '', - '', - '', - 0, - false, - policy, - {}, - {}, { - lat: successData.coords.latitude, - long: successData.coords.longitude, + report, + payeeEmail: currentUserPersonalDetails.login, + payeeAccountID: currentUserPersonalDetails.accountID, + participant, + policy, + gpsPoints: { + lat: successData.coords.latitude, + long: successData.coords.longitude, + }, + }, + { + amount: 0, + attendees: transaction?.attendees, + currency: transaction?.currency ?? 'USD', + created: transaction?.created ?? '', + merchant: '', + receipt, + billable: false, }, ); } diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.tsx index ecf84c877496..b2984c19af05 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.tsx @@ -284,17 +284,20 @@ function IOURequestStepScan({ ); } else { IOU.requestMoney( - report, - 0, - transaction?.attendees, - transaction?.currency ?? 'USD', - transaction?.created ?? '', - '', - currentUserPersonalDetails.login, - currentUserPersonalDetails.accountID, - participant, - '', - receipt, + { + report, + payeeEmail: currentUserPersonalDetails.login, + payeeAccountID: currentUserPersonalDetails.accountID, + participant, + }, + { + amount: 0, + attendees: transaction?.attendees, + currency: transaction?.currency ?? 'USD', + created: transaction?.created ?? '', + merchant: '', + receipt, + }, ); } }, @@ -381,28 +384,25 @@ function IOURequestStepScan({ ); } else { IOU.requestMoney( - report, - 0, - transaction?.attendees, - transaction?.currency ?? 'USD', - transaction?.created ?? '', - '', - currentUserPersonalDetails.login, - currentUserPersonalDetails.accountID, - participant, - '', - receipt, - '', - '', - '', - 0, - false, - policy, - {}, - {}, { - lat: successData.coords.latitude, - long: successData.coords.longitude, + report, + payeeEmail: currentUserPersonalDetails.login, + payeeAccountID: currentUserPersonalDetails.accountID, + participant, + policy, + gpsPoints: { + lat: successData.coords.latitude, + long: successData.coords.longitude, + }, + }, + { + amount: 0, + attendees: transaction?.attendees, + currency: transaction?.currency ?? 'USD', + created: transaction?.created ?? '', + merchant: '', + receipt, + billable: false, }, ); } diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index c2005d221273..7c0748d5404e 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -80,7 +80,22 @@ describe('actions/IOU', () => { let transactionThread: OnyxEntry; let transactionThreadCreatedAction: OnyxEntry; mockFetch?.pause?.(); - IOU.requestMoney({reportID: ''}, amount, [], CONST.CURRENCY.USD, '', merchant, RORY_EMAIL, RORY_ACCOUNT_ID, {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, comment, {}); + IOU.requestMoney( + { + report: {reportID: ''}, + payeeEmail: RORY_EMAIL, + payeeAccountID: RORY_ACCOUNT_ID, + participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, + }, + { + amount, + attendees: [], + currency: CONST.CURRENCY.USD, + created: '', + merchant, + comment, + }, + ); return waitForBatchedUpdates() .then( () => @@ -279,7 +294,22 @@ describe('actions/IOU', () => { }), ) .then(() => { - IOU.requestMoney(chatReport, amount, [], CONST.CURRENCY.USD, '', '', RORY_EMAIL, RORY_ACCOUNT_ID, {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, comment, {}); + IOU.requestMoney( + { + report: chatReport, + payeeEmail: RORY_EMAIL, + payeeAccountID: RORY_ACCOUNT_ID, + participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, + }, + { + amount, + attendees: [], + currency: CONST.CURRENCY.USD, + created: '', + merchant: '', + comment, + }, + ); return waitForBatchedUpdates(); }) .then( @@ -483,7 +513,22 @@ describe('actions/IOU', () => { .then(() => Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION}${existingTransaction.transactionID}`, existingTransaction)) .then(() => { if (chatReport) { - IOU.requestMoney(chatReport, amount, [], CONST.CURRENCY.USD, '', '', RORY_EMAIL, RORY_ACCOUNT_ID, {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, comment, {}); + IOU.requestMoney( + { + report: chatReport, + payeeEmail: RORY_EMAIL, + payeeAccountID: RORY_ACCOUNT_ID, + participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, + }, + { + amount, + attendees: [], + currency: CONST.CURRENCY.USD, + created: '', + merchant: '', + comment, + }, + ); } return waitForBatchedUpdates(); }) @@ -623,7 +668,22 @@ describe('actions/IOU', () => { let transactionThreadReport: OnyxEntry; let transactionThreadAction: OnyxEntry; mockFetch?.pause?.(); - IOU.requestMoney({reportID: ''}, amount, [], CONST.CURRENCY.USD, '', '', RORY_EMAIL, RORY_ACCOUNT_ID, {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, comment, {}); + IOU.requestMoney( + { + report: {reportID: ''}, + payeeEmail: RORY_EMAIL, + payeeAccountID: RORY_ACCOUNT_ID, + participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, + }, + { + amount, + attendees: [], + currency: CONST.CURRENCY.USD, + created: '', + merchant: '', + comment, + }, + ); return ( waitForBatchedUpdates() .then( @@ -1424,7 +1484,22 @@ describe('actions/IOU', () => { let createIOUAction: OnyxEntry>; let payIOUAction: OnyxEntry; let transaction: OnyxEntry; - IOU.requestMoney({reportID: ''}, amount, [], CONST.CURRENCY.USD, '', '', RORY_EMAIL, RORY_ACCOUNT_ID, {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, comment, {}); + IOU.requestMoney( + { + report: {reportID: ''}, + payeeEmail: RORY_EMAIL, + payeeAccountID: RORY_ACCOUNT_ID, + participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, + }, + { + amount, + attendees: [], + currency: CONST.CURRENCY.USD, + created: '', + merchant: '', + comment, + }, + ); return waitForBatchedUpdates() .then( () => @@ -1624,7 +1699,22 @@ describe('actions/IOU', () => { let transaction: OnyxEntry; mockFetch?.pause?.(); - IOU.requestMoney({reportID: ''}, amount, [], CONST.CURRENCY.USD, '', merchant, RORY_EMAIL, RORY_ACCOUNT_ID, {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, comment, {}); + IOU.requestMoney( + { + report: {reportID: ''}, + payeeEmail: RORY_EMAIL, + payeeAccountID: RORY_ACCOUNT_ID, + participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, + }, + { + amount, + attendees: [], + currency: CONST.CURRENCY.USD, + created: '', + merchant, + comment, + }, + ); return waitForBatchedUpdates() .then(() => { Onyx.set(ONYXKEYS.SESSION, {email: RORY_EMAIL, accountID: RORY_ACCOUNT_ID}); @@ -1778,7 +1868,22 @@ describe('actions/IOU', () => { let iouAction: OnyxEntry>; let transaction: OnyxEntry; - IOU.requestMoney({reportID: ''}, amount, [], CONST.CURRENCY.USD, '', merchant, RORY_EMAIL, RORY_ACCOUNT_ID, {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, comment, {}); + IOU.requestMoney( + { + report: {reportID: ''}, + payeeEmail: RORY_EMAIL, + payeeAccountID: RORY_ACCOUNT_ID, + participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, + }, + { + amount, + attendees: [], + currency: CONST.CURRENCY.USD, + created: '', + merchant, + comment, + }, + ); return waitForBatchedUpdates() .then(() => { Onyx.set(ONYXKEYS.SESSION, {email: RORY_EMAIL, accountID: RORY_ACCOUNT_ID}); @@ -1961,17 +2066,20 @@ describe('actions/IOU', () => { .then(() => { if (chatReport) { IOU.requestMoney( - chatReport, - amount, - [], - CONST.CURRENCY.USD, - '', - merchant, - RORY_EMAIL, - RORY_ACCOUNT_ID, - {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, - comment, - {}, + { + report: {reportID: ''}, + payeeEmail: RORY_EMAIL, + payeeAccountID: RORY_ACCOUNT_ID, + participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, + }, + { + amount, + attendees: [], + currency: CONST.CURRENCY.USD, + created: '', + merchant, + comment, + }, ); } return waitForBatchedUpdates(); @@ -2086,17 +2194,20 @@ describe('actions/IOU', () => { .then(() => { if (chatReport) { IOU.requestMoney( - chatReport, - amount, - [], - CONST.CURRENCY.USD, - '', - merchant, - RORY_EMAIL, - RORY_ACCOUNT_ID, - {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, - comment, - {}, + { + report: {reportID: ''}, + payeeEmail: RORY_EMAIL, + payeeAccountID: RORY_ACCOUNT_ID, + participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, + }, + { + amount, + attendees: [], + currency: CONST.CURRENCY.USD, + created: '', + merchant, + comment, + }, ); } return waitForBatchedUpdates(); @@ -2183,7 +2294,22 @@ describe('actions/IOU', () => { await TestHelper.setPersonalDetails(TEST_USER_LOGIN, TEST_USER_ACCOUNT_ID); // When a submit IOU expense is made - IOU.requestMoney({reportID: ''}, amount, [], CONST.CURRENCY.USD, '', '', TEST_USER_LOGIN, TEST_USER_ACCOUNT_ID, {login: RORY_EMAIL, accountID: RORY_ACCOUNT_ID}, comment, {}); + IOU.requestMoney( + { + report: {reportID: ''}, + payeeEmail: TEST_USER_LOGIN, + payeeAccountID: TEST_USER_ACCOUNT_ID, + participant: {login: RORY_EMAIL, accountID: RORY_ACCOUNT_ID}, + }, + { + amount, + attendees: [], + currency: CONST.CURRENCY.USD, + created: '', + merchant: '', + comment, + }, + ); await waitForBatchedUpdates(); // When fetching all reports from Onyx @@ -2914,7 +3040,22 @@ describe('actions/IOU', () => { const amount2 = 20000; const comment2 = 'Send me money please 2'; if (chatReport) { - IOU.requestMoney(chatReport, amount2, [], CONST.CURRENCY.USD, '', '', TEST_USER_LOGIN, TEST_USER_ACCOUNT_ID, {login: RORY_EMAIL, accountID: RORY_ACCOUNT_ID}, comment2, {}); + IOU.requestMoney( + { + report: chatReport, + payeeEmail: TEST_USER_LOGIN, + payeeAccountID: TEST_USER_ACCOUNT_ID, + participant: {login: RORY_EMAIL, accountID: RORY_ACCOUNT_ID}, + }, + { + amount: amount2, + attendees: [], + currency: CONST.CURRENCY.USD, + created: '', + merchant: '', + comment: comment2, + }, + ); } await waitForBatchedUpdates(); @@ -3118,17 +3259,20 @@ describe('actions/IOU', () => { .then(() => { if (chatReport) { IOU.requestMoney( - chatReport, - amount, - [], - CONST.CURRENCY.USD, - '', - merchant, - RORY_EMAIL, - RORY_ACCOUNT_ID, - {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID, isPolicyExpenseChat: true, reportID: chatReport.reportID}, - comment, - {}, + { + report: chatReport, + payeeEmail: RORY_EMAIL, + payeeAccountID: RORY_ACCOUNT_ID, + participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID, isPolicyExpenseChat: true, reportID: chatReport.reportID}, + }, + { + amount, + attendees: [], + currency: CONST.CURRENCY.USD, + created: '', + merchant, + comment, + }, ); } return waitForBatchedUpdates(); @@ -3222,17 +3366,20 @@ describe('actions/IOU', () => { .then(() => { if (chatReport) { IOU.requestMoney( - chatReport, - amount, - [], - CONST.CURRENCY.USD, - '', - merchant, - RORY_EMAIL, - RORY_ACCOUNT_ID, - {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID, isPolicyExpenseChat: true, reportID: chatReport.reportID}, - comment, - {}, + { + report: chatReport, + payeeEmail: RORY_EMAIL, + payeeAccountID: RORY_ACCOUNT_ID, + participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID, isPolicyExpenseChat: true, reportID: chatReport.reportID}, + }, + { + amount, + attendees: [], + currency: CONST.CURRENCY.USD, + created: '', + merchant, + comment, + }, ); } return waitForBatchedUpdates(); @@ -3327,17 +3474,20 @@ describe('actions/IOU', () => { .then(() => { if (chatReport) { IOU.requestMoney( - chatReport, - amount, - [], - CONST.CURRENCY.USD, - '', - merchant, - RORY_EMAIL, - RORY_ACCOUNT_ID, - {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID, isPolicyExpenseChat: true, reportID: chatReport.reportID}, - comment, - {}, + { + report: chatReport, + payeeEmail: RORY_EMAIL, + payeeAccountID: RORY_ACCOUNT_ID, + participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID, isPolicyExpenseChat: true, reportID: chatReport.reportID}, + }, + { + amount, + attendees: [], + currency: CONST.CURRENCY.USD, + created: '', + merchant, + comment, + }, ); } return waitForBatchedUpdates(); From 91caa85e86a9baaecdd933e96533f0356e448757 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Fri, 8 Nov 2024 14:08:26 +0700 Subject: [PATCH 2/8] revert change --- ios/NewExpensify.xcodeproj/project.pbxproj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ios/NewExpensify.xcodeproj/project.pbxproj b/ios/NewExpensify.xcodeproj/project.pbxproj index cd38fcaaaf6c..d8eceab72b95 100644 --- a/ios/NewExpensify.xcodeproj/project.pbxproj +++ b/ios/NewExpensify.xcodeproj/project.pbxproj @@ -45,7 +45,7 @@ D27CE6B77196EF3EF450EEAC /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 0D3F9E814828D91464DF9D35 /* PrivacyInfo.xcprivacy */; }; DD79042B2792E76D004484B4 /* RCTBootSplash.mm in Sources */ = {isa = PBXBuildFile; fileRef = DD79042A2792E76D004484B4 /* RCTBootSplash.mm */; }; DDCB2E57F334C143AC462B43 /* ExpoModulesProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D20D83B0E39BA6D21761E72 /* ExpoModulesProvider.swift */; }; - E51DC681C7DEE40AEBDDFBFE /* BuildFile in Frameworks */ = {isa = PBXBuildFile; }; + E51DC681C7DEE40AEBDDFBFE /* (null) in Frameworks */ = {isa = PBXBuildFile; }; E9DF872D2525201700607FDC /* AirshipConfig.plist in Resources */ = {isa = PBXBuildFile; fileRef = E9DF872C2525201700607FDC /* AirshipConfig.plist */; }; ED222ED90E074A5481A854FA /* ExpensifyNeue-BoldItalic.otf in Resources */ = {isa = PBXBuildFile; fileRef = 8B28D84EF339436DBD42A203 /* ExpensifyNeue-BoldItalic.otf */; }; F0C450EA2705020500FD2970 /* colors.json in Resources */ = {isa = PBXBuildFile; fileRef = F0C450E92705020500FD2970 /* colors.json */; }; @@ -178,8 +178,8 @@ buildActionMask = 2147483647; files = ( 383643682B6D4AE2005BB9AE /* DeviceCheck.framework in Frameworks */, - E51DC681C7DEE40AEBDDFBFE /* BuildFile in Frameworks */, - E51DC681C7DEE40AEBDDFBFE /* BuildFile in Frameworks */, + E51DC681C7DEE40AEBDDFBFE /* (null) in Frameworks */, + E51DC681C7DEE40AEBDDFBFE /* (null) in Frameworks */, 8744C5400E24E379441C04A4 /* libPods-NewExpensify.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; From 6fc82cf9fa7ecd0dd79d146d6437b2a173909588 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Fri, 8 Nov 2024 14:20:33 +0700 Subject: [PATCH 3/8] fix test --- tests/actions/IOUTest.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 7c0748d5404e..dc32f4e99b58 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -2067,7 +2067,7 @@ describe('actions/IOU', () => { if (chatReport) { IOU.requestMoney( { - report: {reportID: ''}, + report: chatReport, payeeEmail: RORY_EMAIL, payeeAccountID: RORY_ACCOUNT_ID, participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, @@ -2195,7 +2195,7 @@ describe('actions/IOU', () => { if (chatReport) { IOU.requestMoney( { - report: {reportID: ''}, + report: chatReport, payeeEmail: RORY_EMAIL, payeeAccountID: RORY_ACCOUNT_ID, participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, From 9bd88a2ac22f9273e27fd1f41fd4090cea8e8920 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Wed, 20 Nov 2024 12:30:56 +0700 Subject: [PATCH 4/8] resolve conflict --- tests/actions/IOUTest.ts | 345 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 345 insertions(+) diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 28004d3dc7a5..7a8284b4c3b8 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -1683,6 +1683,351 @@ describe('actions/IOU', () => { }); }); + describe('edit expense', () => { + const amount = 10000; + const comment = '💸💸💸💸'; + const merchant = 'NASDAQ'; + + afterEach(() => { + mockFetch?.resume?.(); + }); + + it('updates the IOU request and IOU report when offline', () => { + let thread: OptimisticChatReport; + let iouReport: OnyxEntry; + let iouAction: OnyxEntry>; + let transaction: OnyxEntry; + + mockFetch?.pause?.(); + IOU.requestMoney( + { + report: {reportID: ''}, + payeeEmail: RORY_EMAIL, + payeeAccountID: RORY_ACCOUNT_ID, + participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, + }, + { + amount, + attendees: [], + currency: CONST.CURRENCY.USD, + created: '', + merchant, + comment, + }, + ); + return waitForBatchedUpdates() + .then(() => { + Onyx.set(ONYXKEYS.SESSION, {email: RORY_EMAIL, accountID: RORY_ACCOUNT_ID}); + return waitForBatchedUpdates(); + }) + .then( + () => + new Promise((resolve) => { + const connection = Onyx.connect({ + key: ONYXKEYS.COLLECTION.REPORT, + waitForCollectionCallback: true, + callback: (allReports) => { + Onyx.disconnect(connection); + iouReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.IOU); + + resolve(); + }, + }); + }), + ) + .then( + () => + new Promise((resolve) => { + const connection = Onyx.connect({ + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport?.reportID}`, + waitForCollectionCallback: false, + callback: (reportActionsForIOUReport) => { + Onyx.disconnect(connection); + + [iouAction] = Object.values(reportActionsForIOUReport ?? {}).filter( + (reportAction): reportAction is OnyxTypes.ReportAction => ReportActionsUtils.isMoneyRequestAction(reportAction), + ); + resolve(); + }, + }); + }), + ) + .then( + () => + new Promise((resolve) => { + const connection = Onyx.connect({ + key: ONYXKEYS.COLLECTION.TRANSACTION, + waitForCollectionCallback: true, + callback: (allTransactions) => { + Onyx.disconnect(connection); + + transaction = Object.values(allTransactions ?? {}).find((t) => !isEmptyObject(t)); + resolve(); + }, + }); + }), + ) + .then(() => { + thread = ReportUtils.buildTransactionThread(iouAction, iouReport) ?? null; + Onyx.set(`report_${thread?.reportID ?? '-1'}`, thread); + return waitForBatchedUpdates(); + }) + .then(() => { + if (transaction) { + IOU.editMoneyRequest( + transaction, + thread.reportID, + {amount: 20000, comment: 'Double the amount!'}, + { + id: '123', + role: 'user', + type: CONST.POLICY.TYPE.TEAM, + name: '', + owner: '', + outputCurrency: '', + isPolicyExpenseChatEnabled: false, + }, + {}, + {}, + ); + } + return waitForBatchedUpdates(); + }) + .then( + () => + new Promise((resolve) => { + const connection = Onyx.connect({ + key: ONYXKEYS.COLLECTION.TRANSACTION, + waitForCollectionCallback: true, + callback: (allTransactions) => { + Onyx.disconnect(connection); + + const updatedTransaction = Object.values(allTransactions ?? {}).find((t) => !isEmptyObject(t)); + expect(updatedTransaction?.modifiedAmount).toBe(20000); + expect(updatedTransaction?.comment).toMatchObject({comment: 'Double the amount!'}); + resolve(); + }, + }); + }), + ) + .then( + () => + new Promise((resolve) => { + const connection = Onyx.connect({ + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${thread.reportID}`, + waitForCollectionCallback: false, + callback: (allActions) => { + Onyx.disconnect(connection); + const updatedAction = Object.values(allActions ?? {}).find((reportAction) => !isEmptyObject(reportAction)); + expect(updatedAction?.actionName).toEqual('MODIFIEDEXPENSE'); + expect(updatedAction && ReportActionsUtils.getOriginalMessage(updatedAction)).toEqual( + expect.objectContaining({amount: 20000, newComment: 'Double the amount!', oldAmount: amount, oldComment: comment}), + ); + resolve(); + }, + }); + }), + ) + .then( + () => + new Promise((resolve) => { + const connection = Onyx.connect({ + key: ONYXKEYS.COLLECTION.REPORT, + waitForCollectionCallback: true, + callback: (allReports) => { + Onyx.disconnect(connection); + const updatedIOUReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.IOU); + const updatedChatReport = Object.values(allReports ?? {}).find((report) => report?.reportID === iouReport?.chatReportID); + expect(updatedIOUReport).toEqual( + expect.objectContaining({ + total: 20000, + cachedTotal: '$200.00', + lastMessageHtml: 'submitted $200.00', + lastMessageText: 'submitted $200.00', + }), + ); + expect(updatedChatReport).toEqual( + expect.objectContaining({ + lastMessageHtml: `${CARLOS_EMAIL} owes $200.00`, + lastMessageText: `${CARLOS_EMAIL} owes $200.00`, + }), + ); + resolve(); + }, + }); + }), + ) + .then(() => { + mockFetch?.resume?.(); + }); + }); + + it('resets the IOU request and IOU report when api returns an error', () => { + let thread: OptimisticChatReport; + let iouReport: OnyxEntry; + let iouAction: OnyxEntry>; + let transaction: OnyxEntry; + + IOU.requestMoney( + { + report: {reportID: ''}, + payeeEmail: RORY_EMAIL, + payeeAccountID: RORY_ACCOUNT_ID, + participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, + }, + { + amount, + attendees: [], + currency: CONST.CURRENCY.USD, + created: '', + merchant, + comment, + }, + ); + return waitForBatchedUpdates() + .then(() => { + Onyx.set(ONYXKEYS.SESSION, {email: RORY_EMAIL, accountID: RORY_ACCOUNT_ID}); + return waitForBatchedUpdates(); + }) + .then( + () => + new Promise((resolve) => { + const connection = Onyx.connect({ + key: ONYXKEYS.COLLECTION.REPORT, + waitForCollectionCallback: true, + callback: (allReports) => { + Onyx.disconnect(connection); + [iouReport] = Object.values(allReports ?? {}).filter((report) => report?.type === CONST.REPORT.TYPE.IOU); + resolve(); + }, + }); + }), + ) + .then( + () => + new Promise((resolve) => { + const connection = Onyx.connect({ + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport?.reportID}`, + waitForCollectionCallback: false, + callback: (reportActionsForIOUReport) => { + Onyx.disconnect(connection); + + [iouAction] = Object.values(reportActionsForIOUReport ?? {}).filter( + (reportAction): reportAction is OnyxTypes.ReportAction => ReportActionsUtils.isMoneyRequestAction(reportAction), + ); + resolve(); + }, + }); + }), + ) + .then( + () => + new Promise((resolve) => { + const connection = Onyx.connect({ + key: ONYXKEYS.COLLECTION.TRANSACTION, + waitForCollectionCallback: true, + callback: (allTransactions) => { + Onyx.disconnect(connection); + + transaction = Object.values(allTransactions ?? {}).find((t) => !isEmptyObject(t)); + resolve(); + }, + }); + }), + ) + .then(() => { + thread = ReportUtils.buildTransactionThread(iouAction, iouReport); + Onyx.set(`report_${thread.reportID}`, thread); + return waitForBatchedUpdates(); + }) + .then(() => { + mockFetch?.fail?.(); + + if (transaction) { + IOU.editMoneyRequest( + transaction, + thread.reportID, + {amount: 20000, comment: 'Double the amount!'}, + { + id: '123', + role: 'user', + type: CONST.POLICY.TYPE.TEAM, + name: '', + owner: '', + outputCurrency: '', + isPolicyExpenseChatEnabled: false, + }, + {}, + {}, + ); + } + return waitForBatchedUpdates(); + }) + .then( + () => + new Promise((resolve) => { + const connection = Onyx.connect({ + key: ONYXKEYS.COLLECTION.TRANSACTION, + waitForCollectionCallback: true, + callback: (allTransactions) => { + Onyx.disconnect(connection); + + const updatedTransaction = Object.values(allTransactions ?? {}).find((t) => !isEmptyObject(t)); + expect(updatedTransaction?.modifiedAmount).toBe(undefined); + expect(updatedTransaction?.amount).toBe(10000); + expect(updatedTransaction?.comment).toMatchObject({comment}); + resolve(); + }, + }); + }), + ) + .then( + () => + new Promise((resolve) => { + const connection = Onyx.connect({ + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${thread.reportID}`, + waitForCollectionCallback: false, + callback: (allActions) => { + Onyx.disconnect(connection); + const updatedAction = Object.values(allActions ?? {}).find((reportAction) => !isEmptyObject(reportAction)); + expect(updatedAction?.actionName).toEqual('MODIFIEDEXPENSE'); + expect(Object.values(updatedAction?.errors ?? {}).at(0)).toEqual(Localize.translateLocal('iou.error.genericEditFailureMessage')); + resolve(); + }, + }); + }), + ) + .then( + () => + new Promise((resolve) => { + const connection = Onyx.connect({ + key: ONYXKEYS.COLLECTION.REPORT, + waitForCollectionCallback: true, + callback: (allReports) => { + Onyx.disconnect(connection); + const updatedIOUReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.IOU); + const updatedChatReport = Object.values(allReports ?? {}).find((report) => report?.reportID === iouReport?.chatReportID); + expect(updatedIOUReport).toEqual( + expect.objectContaining({ + total: 10000, + cachedTotal: '$100.00', + lastMessageHtml: `submitted $${amount / 100}.00 for ${comment}`, + lastMessageText: `submitted $${amount / 100}.00 for ${comment}`, + }), + ); + expect(updatedChatReport).toEqual( + expect.objectContaining({ + lastMessageHtml: '', + }), + ); + resolve(); + }, + }); + }), + ); + }); + }); + describe('pay expense report via ACH', () => { const amount = 10000; const comment = '💸💸💸💸'; From b5ad2c19f9176ac7022d198c7f622304907c28d0 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Wed, 20 Nov 2024 12:35:47 +0700 Subject: [PATCH 5/8] remove change --- tests/actions/IOUTest.ts | 345 --------------------------------------- 1 file changed, 345 deletions(-) diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 7a8284b4c3b8..28004d3dc7a5 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -1683,351 +1683,6 @@ describe('actions/IOU', () => { }); }); - describe('edit expense', () => { - const amount = 10000; - const comment = '💸💸💸💸'; - const merchant = 'NASDAQ'; - - afterEach(() => { - mockFetch?.resume?.(); - }); - - it('updates the IOU request and IOU report when offline', () => { - let thread: OptimisticChatReport; - let iouReport: OnyxEntry; - let iouAction: OnyxEntry>; - let transaction: OnyxEntry; - - mockFetch?.pause?.(); - IOU.requestMoney( - { - report: {reportID: ''}, - payeeEmail: RORY_EMAIL, - payeeAccountID: RORY_ACCOUNT_ID, - participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, - }, - { - amount, - attendees: [], - currency: CONST.CURRENCY.USD, - created: '', - merchant, - comment, - }, - ); - return waitForBatchedUpdates() - .then(() => { - Onyx.set(ONYXKEYS.SESSION, {email: RORY_EMAIL, accountID: RORY_ACCOUNT_ID}); - return waitForBatchedUpdates(); - }) - .then( - () => - new Promise((resolve) => { - const connection = Onyx.connect({ - key: ONYXKEYS.COLLECTION.REPORT, - waitForCollectionCallback: true, - callback: (allReports) => { - Onyx.disconnect(connection); - iouReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.IOU); - - resolve(); - }, - }); - }), - ) - .then( - () => - new Promise((resolve) => { - const connection = Onyx.connect({ - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport?.reportID}`, - waitForCollectionCallback: false, - callback: (reportActionsForIOUReport) => { - Onyx.disconnect(connection); - - [iouAction] = Object.values(reportActionsForIOUReport ?? {}).filter( - (reportAction): reportAction is OnyxTypes.ReportAction => ReportActionsUtils.isMoneyRequestAction(reportAction), - ); - resolve(); - }, - }); - }), - ) - .then( - () => - new Promise((resolve) => { - const connection = Onyx.connect({ - key: ONYXKEYS.COLLECTION.TRANSACTION, - waitForCollectionCallback: true, - callback: (allTransactions) => { - Onyx.disconnect(connection); - - transaction = Object.values(allTransactions ?? {}).find((t) => !isEmptyObject(t)); - resolve(); - }, - }); - }), - ) - .then(() => { - thread = ReportUtils.buildTransactionThread(iouAction, iouReport) ?? null; - Onyx.set(`report_${thread?.reportID ?? '-1'}`, thread); - return waitForBatchedUpdates(); - }) - .then(() => { - if (transaction) { - IOU.editMoneyRequest( - transaction, - thread.reportID, - {amount: 20000, comment: 'Double the amount!'}, - { - id: '123', - role: 'user', - type: CONST.POLICY.TYPE.TEAM, - name: '', - owner: '', - outputCurrency: '', - isPolicyExpenseChatEnabled: false, - }, - {}, - {}, - ); - } - return waitForBatchedUpdates(); - }) - .then( - () => - new Promise((resolve) => { - const connection = Onyx.connect({ - key: ONYXKEYS.COLLECTION.TRANSACTION, - waitForCollectionCallback: true, - callback: (allTransactions) => { - Onyx.disconnect(connection); - - const updatedTransaction = Object.values(allTransactions ?? {}).find((t) => !isEmptyObject(t)); - expect(updatedTransaction?.modifiedAmount).toBe(20000); - expect(updatedTransaction?.comment).toMatchObject({comment: 'Double the amount!'}); - resolve(); - }, - }); - }), - ) - .then( - () => - new Promise((resolve) => { - const connection = Onyx.connect({ - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${thread.reportID}`, - waitForCollectionCallback: false, - callback: (allActions) => { - Onyx.disconnect(connection); - const updatedAction = Object.values(allActions ?? {}).find((reportAction) => !isEmptyObject(reportAction)); - expect(updatedAction?.actionName).toEqual('MODIFIEDEXPENSE'); - expect(updatedAction && ReportActionsUtils.getOriginalMessage(updatedAction)).toEqual( - expect.objectContaining({amount: 20000, newComment: 'Double the amount!', oldAmount: amount, oldComment: comment}), - ); - resolve(); - }, - }); - }), - ) - .then( - () => - new Promise((resolve) => { - const connection = Onyx.connect({ - key: ONYXKEYS.COLLECTION.REPORT, - waitForCollectionCallback: true, - callback: (allReports) => { - Onyx.disconnect(connection); - const updatedIOUReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.IOU); - const updatedChatReport = Object.values(allReports ?? {}).find((report) => report?.reportID === iouReport?.chatReportID); - expect(updatedIOUReport).toEqual( - expect.objectContaining({ - total: 20000, - cachedTotal: '$200.00', - lastMessageHtml: 'submitted $200.00', - lastMessageText: 'submitted $200.00', - }), - ); - expect(updatedChatReport).toEqual( - expect.objectContaining({ - lastMessageHtml: `${CARLOS_EMAIL} owes $200.00`, - lastMessageText: `${CARLOS_EMAIL} owes $200.00`, - }), - ); - resolve(); - }, - }); - }), - ) - .then(() => { - mockFetch?.resume?.(); - }); - }); - - it('resets the IOU request and IOU report when api returns an error', () => { - let thread: OptimisticChatReport; - let iouReport: OnyxEntry; - let iouAction: OnyxEntry>; - let transaction: OnyxEntry; - - IOU.requestMoney( - { - report: {reportID: ''}, - payeeEmail: RORY_EMAIL, - payeeAccountID: RORY_ACCOUNT_ID, - participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, - }, - { - amount, - attendees: [], - currency: CONST.CURRENCY.USD, - created: '', - merchant, - comment, - }, - ); - return waitForBatchedUpdates() - .then(() => { - Onyx.set(ONYXKEYS.SESSION, {email: RORY_EMAIL, accountID: RORY_ACCOUNT_ID}); - return waitForBatchedUpdates(); - }) - .then( - () => - new Promise((resolve) => { - const connection = Onyx.connect({ - key: ONYXKEYS.COLLECTION.REPORT, - waitForCollectionCallback: true, - callback: (allReports) => { - Onyx.disconnect(connection); - [iouReport] = Object.values(allReports ?? {}).filter((report) => report?.type === CONST.REPORT.TYPE.IOU); - resolve(); - }, - }); - }), - ) - .then( - () => - new Promise((resolve) => { - const connection = Onyx.connect({ - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport?.reportID}`, - waitForCollectionCallback: false, - callback: (reportActionsForIOUReport) => { - Onyx.disconnect(connection); - - [iouAction] = Object.values(reportActionsForIOUReport ?? {}).filter( - (reportAction): reportAction is OnyxTypes.ReportAction => ReportActionsUtils.isMoneyRequestAction(reportAction), - ); - resolve(); - }, - }); - }), - ) - .then( - () => - new Promise((resolve) => { - const connection = Onyx.connect({ - key: ONYXKEYS.COLLECTION.TRANSACTION, - waitForCollectionCallback: true, - callback: (allTransactions) => { - Onyx.disconnect(connection); - - transaction = Object.values(allTransactions ?? {}).find((t) => !isEmptyObject(t)); - resolve(); - }, - }); - }), - ) - .then(() => { - thread = ReportUtils.buildTransactionThread(iouAction, iouReport); - Onyx.set(`report_${thread.reportID}`, thread); - return waitForBatchedUpdates(); - }) - .then(() => { - mockFetch?.fail?.(); - - if (transaction) { - IOU.editMoneyRequest( - transaction, - thread.reportID, - {amount: 20000, comment: 'Double the amount!'}, - { - id: '123', - role: 'user', - type: CONST.POLICY.TYPE.TEAM, - name: '', - owner: '', - outputCurrency: '', - isPolicyExpenseChatEnabled: false, - }, - {}, - {}, - ); - } - return waitForBatchedUpdates(); - }) - .then( - () => - new Promise((resolve) => { - const connection = Onyx.connect({ - key: ONYXKEYS.COLLECTION.TRANSACTION, - waitForCollectionCallback: true, - callback: (allTransactions) => { - Onyx.disconnect(connection); - - const updatedTransaction = Object.values(allTransactions ?? {}).find((t) => !isEmptyObject(t)); - expect(updatedTransaction?.modifiedAmount).toBe(undefined); - expect(updatedTransaction?.amount).toBe(10000); - expect(updatedTransaction?.comment).toMatchObject({comment}); - resolve(); - }, - }); - }), - ) - .then( - () => - new Promise((resolve) => { - const connection = Onyx.connect({ - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${thread.reportID}`, - waitForCollectionCallback: false, - callback: (allActions) => { - Onyx.disconnect(connection); - const updatedAction = Object.values(allActions ?? {}).find((reportAction) => !isEmptyObject(reportAction)); - expect(updatedAction?.actionName).toEqual('MODIFIEDEXPENSE'); - expect(Object.values(updatedAction?.errors ?? {}).at(0)).toEqual(Localize.translateLocal('iou.error.genericEditFailureMessage')); - resolve(); - }, - }); - }), - ) - .then( - () => - new Promise((resolve) => { - const connection = Onyx.connect({ - key: ONYXKEYS.COLLECTION.REPORT, - waitForCollectionCallback: true, - callback: (allReports) => { - Onyx.disconnect(connection); - const updatedIOUReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.IOU); - const updatedChatReport = Object.values(allReports ?? {}).find((report) => report?.reportID === iouReport?.chatReportID); - expect(updatedIOUReport).toEqual( - expect.objectContaining({ - total: 10000, - cachedTotal: '$100.00', - lastMessageHtml: `submitted $${amount / 100}.00 for ${comment}`, - lastMessageText: `submitted $${amount / 100}.00 for ${comment}`, - }), - ); - expect(updatedChatReport).toEqual( - expect.objectContaining({ - lastMessageHtml: '', - }), - ); - resolve(); - }, - }); - }), - ); - }); - }); - describe('pay expense report via ACH', () => { const amount = 10000; const comment = '💸💸💸💸'; From 8d99484a22b27bfde3993848d7d2305e0fb678b5 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Fri, 22 Nov 2024 01:00:15 +0700 Subject: [PATCH 6/8] merge param into one param --- src/libs/actions/IOU.ts | 43 ++++--- .../iou/request/step/IOURequestStepAmount.tsx | 10 +- .../step/IOURequestStepConfirmation.tsx | 16 ++- .../step/IOURequestStepScan/index.native.tsx | 30 +++-- .../request/step/IOURequestStepScan/index.tsx | 30 +++-- tests/actions/IOUTest.ts | 120 +++++++++--------- 6 files changed, 133 insertions(+), 116 deletions(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 7809b9ac0303..5c1affb89299 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -165,19 +165,6 @@ type GPSPoint = { long: number; }; -type RequestMoneyInformation = { - report: OnyxEntry; - payeeEmail: string | undefined; - payeeAccountID: number; - participant: Participant; - policy?: OnyxEntry; - policyTagList?: OnyxEntry; - policyCategories?: OnyxEntry; - gpsPoints?: GPSPoint; - action?: IOUAction; - reimbursible?: boolean; -}; - type RequestMoneyTransactionData = { attendees: Attendee[] | undefined; amount: number; @@ -196,6 +183,28 @@ type RequestMoneyTransactionData = { linkedTrackedExpenseReportID?: string; }; +type RequestMoneyPolicyParams = { + policy?: OnyxEntry; + policyTagList?: OnyxEntry; + policyCategories?: OnyxEntry; +}; + +type RequestMoneyParticipantParams = { + payeeEmail: string | undefined; + payeeAccountID: number; + participant: Participant; +}; + +type RequestMoneyInformation = { + report: OnyxEntry; + participantData: RequestMoneyParticipantParams; + policyData?: RequestMoneyPolicyParams; + gpsPoints?: GPSPoint; + action?: IOUAction; + reimbursible?: boolean; + transactionData: RequestMoneyTransactionData; +}; + let allPersonalDetails: OnyxTypes.PersonalDetailsList = {}; Onyx.connect({ key: ONYXKEYS.PERSONAL_DETAILS_LIST, @@ -3555,8 +3564,10 @@ function shareTrackedExpense( /** * Submit expense to another user */ -function requestMoney(requestMoneyInformation: RequestMoneyInformation, requestMoneyTransactionData: RequestMoneyTransactionData) { - const {report, payeeEmail, payeeAccountID, participant, policy, policyTagList, policyCategories, gpsPoints, action, reimbursible} = requestMoneyInformation; +function requestMoney(requestMoneyInformation: RequestMoneyInformation) { + const {report, participantData, policyData = {}, transactionData, gpsPoints, action, reimbursible} = requestMoneyInformation; + const {participant, payeeAccountID, payeeEmail} = participantData; + const {policy, policyCategories, policyTagList} = policyData; const { amount, currency, @@ -3573,7 +3584,7 @@ function requestMoney(requestMoneyInformation: RequestMoneyInformation, requestM actionableWhisperReportActionID, linkedTrackedExpenseReportAction, linkedTrackedExpenseReportID, - } = requestMoneyTransactionData; + } = transactionData; // If the report is iou or expense report, we should get the linked chat report to be passed to the getMoneyRequestInformation function const isMoneyRequestReport = ReportUtils.isMoneyRequestReport(report); diff --git a/src/pages/iou/request/step/IOURequestStepAmount.tsx b/src/pages/iou/request/step/IOURequestStepAmount.tsx index 327b325d989f..83cdfa194777 100644 --- a/src/pages/iou/request/step/IOURequestStepAmount.tsx +++ b/src/pages/iou/request/step/IOURequestStepAmount.tsx @@ -210,21 +210,21 @@ function IOURequestStepAmount({ } if (iouType === CONST.IOU.TYPE.SUBMIT || iouType === CONST.IOU.TYPE.REQUEST) { playSound(SOUNDS.DONE); - IOU.requestMoney( - { - report, + IOU.requestMoney({ + report, + participantData: { participant: participants.at(0) ?? {}, payeeEmail: currentUserPersonalDetails.login, payeeAccountID: currentUserPersonalDetails.accountID, }, - { + transactionData: { amount: backendAmount, currency, created: transaction?.created ?? '', merchant: CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT, attendees: transaction?.attendees, }, - ); + }); return; } if (iouType === CONST.IOU.TYPE.TRACK) { diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index d91ed84313d2..7df544e967f9 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -238,19 +238,21 @@ function IOURequestStepConfirmation({ if (!participant) { return; } - IOU.requestMoney( - { - report, + IOU.requestMoney({ + report, + participantData: { payeeEmail: currentUserPersonalDetails.login, payeeAccountID: currentUserPersonalDetails.accountID, participant, + }, + policyData: { policy, policyTagList: policyTags, policyCategories, - gpsPoints, - action, }, - { + gpsPoints, + action, + transactionData: { amount: transaction.amount, attendees: transaction.attendees, currency: transaction.currency, @@ -267,7 +269,7 @@ function IOURequestStepConfirmation({ linkedTrackedExpenseReportAction: transaction.linkedTrackedExpenseReportAction, linkedTrackedExpenseReportID: transaction.linkedTrackedExpenseReportID, }, - ); + }); }, [report, transaction, transactionTaxCode, transactionTaxAmount, currentUserPersonalDetails.login, currentUserPersonalDetails.accountID, policy, policyTags, policyCategories, action], ); diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx index e22e550d3eb8..0416315bbafc 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx @@ -255,14 +255,14 @@ function IOURequestStepScan({ receipt, ); } else { - IOU.requestMoney( - { - report, + IOU.requestMoney({ + report, + participantData: { payeeEmail: currentUserPersonalDetails.login, payeeAccountID: currentUserPersonalDetails.accountID, participant, }, - { + transactionData: { amount: 0, attendees: transaction?.attendees, currency: transaction?.currency ?? 'USD', @@ -270,7 +270,7 @@ function IOURequestStepScan({ merchant: '', receipt, }, - ); + }); } }, [currentUserPersonalDetails.accountID, currentUserPersonalDetails.login, iouType, report, transaction?.attendees, transaction?.created, transaction?.currency], @@ -355,19 +355,21 @@ function IOURequestStepScan({ }, ); } else { - IOU.requestMoney( - { - report, + IOU.requestMoney({ + report, + participantData: { payeeEmail: currentUserPersonalDetails.login, payeeAccountID: currentUserPersonalDetails.accountID, participant, + }, + policyData: { policy, - gpsPoints: { - lat: successData.coords.latitude, - long: successData.coords.longitude, - }, }, - { + gpsPoints: { + lat: successData.coords.latitude, + long: successData.coords.longitude, + }, + transactionData: { amount: 0, attendees: transaction?.attendees, currency: transaction?.currency ?? 'USD', @@ -376,7 +378,7 @@ function IOURequestStepScan({ receipt, billable: false, }, - ); + }); } }, (errorData) => { diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.tsx index 4ae8c0e72688..e646583bb67b 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.tsx @@ -284,14 +284,14 @@ function IOURequestStepScan({ receipt, ); } else { - IOU.requestMoney( - { - report, + IOU.requestMoney({ + report, + participantData: { payeeEmail: currentUserPersonalDetails.login, payeeAccountID: currentUserPersonalDetails.accountID, participant, }, - { + transactionData: { amount: 0, attendees: transaction?.attendees, currency: transaction?.currency ?? 'USD', @@ -299,7 +299,7 @@ function IOURequestStepScan({ merchant: '', receipt, }, - ); + }); } }, [currentUserPersonalDetails.accountID, currentUserPersonalDetails.login, iouType, report, transaction?.attendees, transaction?.created, transaction?.currency], @@ -385,19 +385,21 @@ function IOURequestStepScan({ }, ); } else { - IOU.requestMoney( - { - report, + IOU.requestMoney({ + report, + participantData: { payeeEmail: currentUserPersonalDetails.login, payeeAccountID: currentUserPersonalDetails.accountID, participant, + }, + policyData: { policy, - gpsPoints: { - lat: successData.coords.latitude, - long: successData.coords.longitude, - }, }, - { + gpsPoints: { + lat: successData.coords.latitude, + long: successData.coords.longitude, + }, + transactionData: { amount: 0, attendees: transaction?.attendees, currency: transaction?.currency ?? 'USD', @@ -406,7 +408,7 @@ function IOURequestStepScan({ receipt, billable: false, }, - ); + }); } }, (errorData) => { diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 28004d3dc7a5..909ec1b2068a 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -80,14 +80,14 @@ describe('actions/IOU', () => { let transactionThread: OnyxEntry; let transactionThreadCreatedAction: OnyxEntry; mockFetch?.pause?.(); - IOU.requestMoney( - { - report: {reportID: ''}, + IOU.requestMoney({ + report: {reportID: ''}, + participantData: { payeeEmail: RORY_EMAIL, payeeAccountID: RORY_ACCOUNT_ID, participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, }, - { + transactionData: { amount, attendees: [], currency: CONST.CURRENCY.USD, @@ -95,7 +95,7 @@ describe('actions/IOU', () => { merchant, comment, }, - ); + }); return waitForBatchedUpdates() .then( () => @@ -294,14 +294,14 @@ describe('actions/IOU', () => { }), ) .then(() => { - IOU.requestMoney( - { - report: chatReport, + IOU.requestMoney({ + report: chatReport, + participantData: { payeeEmail: RORY_EMAIL, payeeAccountID: RORY_ACCOUNT_ID, participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, }, - { + transactionData: { amount, attendees: [], currency: CONST.CURRENCY.USD, @@ -309,7 +309,7 @@ describe('actions/IOU', () => { merchant: '', comment, }, - ); + }); return waitForBatchedUpdates(); }) .then( @@ -513,14 +513,14 @@ describe('actions/IOU', () => { .then(() => Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION}${existingTransaction.transactionID}`, existingTransaction)) .then(() => { if (chatReport) { - IOU.requestMoney( - { - report: chatReport, + IOU.requestMoney({ + report: chatReport, + participantData: { payeeEmail: RORY_EMAIL, payeeAccountID: RORY_ACCOUNT_ID, participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, }, - { + transactionData: { amount, attendees: [], currency: CONST.CURRENCY.USD, @@ -528,7 +528,7 @@ describe('actions/IOU', () => { merchant: '', comment, }, - ); + }); } return waitForBatchedUpdates(); }) @@ -668,14 +668,14 @@ describe('actions/IOU', () => { let transactionThreadReport: OnyxEntry; let transactionThreadAction: OnyxEntry; mockFetch?.pause?.(); - IOU.requestMoney( - { - report: {reportID: ''}, + IOU.requestMoney({ + report: {reportID: ''}, + participantData: { payeeEmail: RORY_EMAIL, payeeAccountID: RORY_ACCOUNT_ID, participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, }, - { + transactionData: { amount, attendees: [], currency: CONST.CURRENCY.USD, @@ -683,7 +683,7 @@ describe('actions/IOU', () => { merchant: '', comment, }, - ); + }); return ( waitForBatchedUpdates() .then( @@ -1484,14 +1484,14 @@ describe('actions/IOU', () => { let createIOUAction: OnyxEntry>; let payIOUAction: OnyxEntry; let transaction: OnyxEntry; - IOU.requestMoney( - { - report: {reportID: ''}, + IOU.requestMoney({ + report: {reportID: ''}, + participantData: { payeeEmail: RORY_EMAIL, payeeAccountID: RORY_ACCOUNT_ID, participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, }, - { + transactionData: { amount, attendees: [], currency: CONST.CURRENCY.USD, @@ -1499,7 +1499,7 @@ describe('actions/IOU', () => { merchant: '', comment, }, - ); + }); return waitForBatchedUpdates() .then( () => @@ -1720,14 +1720,14 @@ describe('actions/IOU', () => { ) .then(() => { if (chatReport) { - IOU.requestMoney( - { - report: chatReport, + IOU.requestMoney({ + report: chatReport, + participantData: { payeeEmail: RORY_EMAIL, payeeAccountID: RORY_ACCOUNT_ID, participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, }, - { + transactionData: { amount, attendees: [], currency: CONST.CURRENCY.USD, @@ -1735,7 +1735,7 @@ describe('actions/IOU', () => { merchant, comment, }, - ); + }); } return waitForBatchedUpdates(); }) @@ -1848,14 +1848,14 @@ describe('actions/IOU', () => { ) .then(() => { if (chatReport) { - IOU.requestMoney( - { - report: chatReport, + IOU.requestMoney({ + report: chatReport, + participantData: { payeeEmail: RORY_EMAIL, payeeAccountID: RORY_ACCOUNT_ID, participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, }, - { + transactionData: { amount, attendees: [], currency: CONST.CURRENCY.USD, @@ -1863,7 +1863,7 @@ describe('actions/IOU', () => { merchant, comment, }, - ); + }); } return waitForBatchedUpdates(); }) @@ -1949,14 +1949,14 @@ describe('actions/IOU', () => { await TestHelper.setPersonalDetails(TEST_USER_LOGIN, TEST_USER_ACCOUNT_ID); // When a submit IOU expense is made - IOU.requestMoney( - { - report: {reportID: ''}, + IOU.requestMoney({ + report: chatReport, + participantData: { payeeEmail: TEST_USER_LOGIN, payeeAccountID: TEST_USER_ACCOUNT_ID, participant: {login: RORY_EMAIL, accountID: RORY_ACCOUNT_ID}, }, - { + transactionData: { amount, attendees: [], currency: CONST.CURRENCY.USD, @@ -1964,7 +1964,7 @@ describe('actions/IOU', () => { merchant: '', comment, }, - ); + }); await waitForBatchedUpdates(); // When fetching all reports from Onyx @@ -2698,14 +2698,14 @@ describe('actions/IOU', () => { const amount2 = 20000; const comment2 = 'Send me money please 2'; if (chatReport) { - IOU.requestMoney( - { - report: chatReport, + IOU.requestMoney({ + report: chatReport, + participantData: { payeeEmail: TEST_USER_LOGIN, payeeAccountID: TEST_USER_ACCOUNT_ID, participant: {login: RORY_EMAIL, accountID: RORY_ACCOUNT_ID}, }, - { + transactionData: { amount: amount2, attendees: [], currency: CONST.CURRENCY.USD, @@ -2713,7 +2713,7 @@ describe('actions/IOU', () => { merchant: '', comment: comment2, }, - ); + }); } await waitForBatchedUpdates(); @@ -2916,14 +2916,14 @@ describe('actions/IOU', () => { ) .then(() => { if (chatReport) { - IOU.requestMoney( - { - report: chatReport, + IOU.requestMoney({ + report: chatReport, + participantData: { payeeEmail: RORY_EMAIL, payeeAccountID: RORY_ACCOUNT_ID, participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID, isPolicyExpenseChat: true, reportID: chatReport.reportID}, }, - { + transactionData: { amount, attendees: [], currency: CONST.CURRENCY.USD, @@ -2931,7 +2931,7 @@ describe('actions/IOU', () => { merchant, comment, }, - ); + }); } return waitForBatchedUpdates(); }) @@ -3023,14 +3023,14 @@ describe('actions/IOU', () => { ) .then(() => { if (chatReport) { - IOU.requestMoney( - { - report: chatReport, + IOU.requestMoney({ + report: chatReport, + participantData: { payeeEmail: RORY_EMAIL, payeeAccountID: RORY_ACCOUNT_ID, participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID, isPolicyExpenseChat: true, reportID: chatReport.reportID}, }, - { + transactionData: { amount, attendees: [], currency: CONST.CURRENCY.USD, @@ -3038,7 +3038,7 @@ describe('actions/IOU', () => { merchant, comment, }, - ); + }); } return waitForBatchedUpdates(); }) @@ -3131,14 +3131,14 @@ describe('actions/IOU', () => { ) .then(() => { if (chatReport) { - IOU.requestMoney( - { - report: chatReport, + IOU.requestMoney({ + report: chatReport, + participantData: { payeeEmail: RORY_EMAIL, payeeAccountID: RORY_ACCOUNT_ID, participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID, isPolicyExpenseChat: true, reportID: chatReport.reportID}, }, - { + transactionData: { amount, attendees: [], currency: CONST.CURRENCY.USD, @@ -3146,7 +3146,7 @@ describe('actions/IOU', () => { merchant, comment, }, - ); + }); } return waitForBatchedUpdates(); }) From d0918fe29b8597d3ef834ce33c0b87d65c57c5ff Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Fri, 22 Nov 2024 23:12:10 +0700 Subject: [PATCH 7/8] rename param --- src/libs/actions/IOU.ts | 10 ++++---- .../iou/request/step/IOURequestStepAmount.tsx | 2 +- .../step/IOURequestStepConfirmation.tsx | 4 ++-- .../step/IOURequestStepScan/index.native.tsx | 6 ++--- .../request/step/IOURequestStepScan/index.tsx | 6 ++--- tests/actions/IOUTest.ts | 24 +++++++++---------- 6 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index b72b95a0c44f..a28c4490c7c9 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -197,8 +197,8 @@ type RequestMoneyParticipantParams = { type RequestMoneyInformation = { report: OnyxEntry; - participantData: RequestMoneyParticipantParams; - policyData?: RequestMoneyPolicyParams; + participantParams: RequestMoneyParticipantParams; + policyParams?: RequestMoneyPolicyParams; gpsPoints?: GPSPoint; action?: IOUAction; reimbursible?: boolean; @@ -3565,9 +3565,9 @@ function shareTrackedExpense( * Submit expense to another user */ function requestMoney(requestMoneyInformation: RequestMoneyInformation) { - const {report, participantData, policyData = {}, transactionData, gpsPoints, action, reimbursible} = requestMoneyInformation; - const {participant, payeeAccountID, payeeEmail} = participantData; - const {policy, policyCategories, policyTagList} = policyData; + const {report, participantParams, policyParams = {}, transactionData, gpsPoints, action, reimbursible} = requestMoneyInformation; + const {participant, payeeAccountID, payeeEmail} = participantParams; + const {policy, policyCategories, policyTagList} = policyParams; const { amount, currency, diff --git a/src/pages/iou/request/step/IOURequestStepAmount.tsx b/src/pages/iou/request/step/IOURequestStepAmount.tsx index 83cdfa194777..5a9fa9358355 100644 --- a/src/pages/iou/request/step/IOURequestStepAmount.tsx +++ b/src/pages/iou/request/step/IOURequestStepAmount.tsx @@ -212,7 +212,7 @@ function IOURequestStepAmount({ playSound(SOUNDS.DONE); IOU.requestMoney({ report, - participantData: { + participantParams: { participant: participants.at(0) ?? {}, payeeEmail: currentUserPersonalDetails.login, payeeAccountID: currentUserPersonalDetails.accountID, diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index 7df544e967f9..1c3a34bfff42 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -240,12 +240,12 @@ function IOURequestStepConfirmation({ } IOU.requestMoney({ report, - participantData: { + participantParams: { payeeEmail: currentUserPersonalDetails.login, payeeAccountID: currentUserPersonalDetails.accountID, participant, }, - policyData: { + policyParams: { policy, policyTagList: policyTags, policyCategories, diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx index 0416315bbafc..29dccaa0f9f1 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx @@ -257,7 +257,7 @@ function IOURequestStepScan({ } else { IOU.requestMoney({ report, - participantData: { + participantParams: { payeeEmail: currentUserPersonalDetails.login, payeeAccountID: currentUserPersonalDetails.accountID, participant, @@ -357,12 +357,12 @@ function IOURequestStepScan({ } else { IOU.requestMoney({ report, - participantData: { + participantParams: { payeeEmail: currentUserPersonalDetails.login, payeeAccountID: currentUserPersonalDetails.accountID, participant, }, - policyData: { + policyParams: { policy, }, gpsPoints: { diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.tsx index e646583bb67b..eb40fba34ddf 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.tsx @@ -286,7 +286,7 @@ function IOURequestStepScan({ } else { IOU.requestMoney({ report, - participantData: { + participantParams: { payeeEmail: currentUserPersonalDetails.login, payeeAccountID: currentUserPersonalDetails.accountID, participant, @@ -387,12 +387,12 @@ function IOURequestStepScan({ } else { IOU.requestMoney({ report, - participantData: { + participantParams: { payeeEmail: currentUserPersonalDetails.login, payeeAccountID: currentUserPersonalDetails.accountID, participant, }, - policyData: { + policyParams: { policy, }, gpsPoints: { diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 909ec1b2068a..1928ed694228 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -82,7 +82,7 @@ describe('actions/IOU', () => { mockFetch?.pause?.(); IOU.requestMoney({ report: {reportID: ''}, - participantData: { + participantParams: { payeeEmail: RORY_EMAIL, payeeAccountID: RORY_ACCOUNT_ID, participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, @@ -296,7 +296,7 @@ describe('actions/IOU', () => { .then(() => { IOU.requestMoney({ report: chatReport, - participantData: { + participantParams: { payeeEmail: RORY_EMAIL, payeeAccountID: RORY_ACCOUNT_ID, participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, @@ -515,7 +515,7 @@ describe('actions/IOU', () => { if (chatReport) { IOU.requestMoney({ report: chatReport, - participantData: { + participantParams: { payeeEmail: RORY_EMAIL, payeeAccountID: RORY_ACCOUNT_ID, participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, @@ -670,7 +670,7 @@ describe('actions/IOU', () => { mockFetch?.pause?.(); IOU.requestMoney({ report: {reportID: ''}, - participantData: { + participantParams: { payeeEmail: RORY_EMAIL, payeeAccountID: RORY_ACCOUNT_ID, participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, @@ -1486,7 +1486,7 @@ describe('actions/IOU', () => { let transaction: OnyxEntry; IOU.requestMoney({ report: {reportID: ''}, - participantData: { + participantParams: { payeeEmail: RORY_EMAIL, payeeAccountID: RORY_ACCOUNT_ID, participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, @@ -1722,7 +1722,7 @@ describe('actions/IOU', () => { if (chatReport) { IOU.requestMoney({ report: chatReport, - participantData: { + participantParams: { payeeEmail: RORY_EMAIL, payeeAccountID: RORY_ACCOUNT_ID, participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, @@ -1850,7 +1850,7 @@ describe('actions/IOU', () => { if (chatReport) { IOU.requestMoney({ report: chatReport, - participantData: { + participantParams: { payeeEmail: RORY_EMAIL, payeeAccountID: RORY_ACCOUNT_ID, participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, @@ -1951,7 +1951,7 @@ describe('actions/IOU', () => { // When a submit IOU expense is made IOU.requestMoney({ report: chatReport, - participantData: { + participantParams: { payeeEmail: TEST_USER_LOGIN, payeeAccountID: TEST_USER_ACCOUNT_ID, participant: {login: RORY_EMAIL, accountID: RORY_ACCOUNT_ID}, @@ -2700,7 +2700,7 @@ describe('actions/IOU', () => { if (chatReport) { IOU.requestMoney({ report: chatReport, - participantData: { + participantParams: { payeeEmail: TEST_USER_LOGIN, payeeAccountID: TEST_USER_ACCOUNT_ID, participant: {login: RORY_EMAIL, accountID: RORY_ACCOUNT_ID}, @@ -2918,7 +2918,7 @@ describe('actions/IOU', () => { if (chatReport) { IOU.requestMoney({ report: chatReport, - participantData: { + participantParams: { payeeEmail: RORY_EMAIL, payeeAccountID: RORY_ACCOUNT_ID, participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID, isPolicyExpenseChat: true, reportID: chatReport.reportID}, @@ -3025,7 +3025,7 @@ describe('actions/IOU', () => { if (chatReport) { IOU.requestMoney({ report: chatReport, - participantData: { + participantParams: { payeeEmail: RORY_EMAIL, payeeAccountID: RORY_ACCOUNT_ID, participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID, isPolicyExpenseChat: true, reportID: chatReport.reportID}, @@ -3133,7 +3133,7 @@ describe('actions/IOU', () => { if (chatReport) { IOU.requestMoney({ report: chatReport, - participantData: { + participantParams: { payeeEmail: RORY_EMAIL, payeeAccountID: RORY_ACCOUNT_ID, participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID, isPolicyExpenseChat: true, reportID: chatReport.reportID}, From e08c53a2ea6a9a2aa3eba94c0f03453c80471f80 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Fri, 22 Nov 2024 23:23:50 +0700 Subject: [PATCH 8/8] rename transactionData --- src/libs/actions/IOU.ts | 8 +++---- .../iou/request/step/IOURequestStepAmount.tsx | 2 +- .../step/IOURequestStepConfirmation.tsx | 2 +- .../step/IOURequestStepScan/index.native.tsx | 4 ++-- .../request/step/IOURequestStepScan/index.tsx | 4 ++-- tests/actions/IOUTest.ts | 24 +++++++++---------- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index a28c4490c7c9..10eee66428e8 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -165,7 +165,7 @@ type GPSPoint = { long: number; }; -type RequestMoneyTransactionData = { +type RequestMoneyTransactionParams = { attendees: Attendee[] | undefined; amount: number; currency: string; @@ -202,7 +202,7 @@ type RequestMoneyInformation = { gpsPoints?: GPSPoint; action?: IOUAction; reimbursible?: boolean; - transactionData: RequestMoneyTransactionData; + transactionParams: RequestMoneyTransactionParams; }; let allPersonalDetails: OnyxTypes.PersonalDetailsList = {}; @@ -3565,7 +3565,7 @@ function shareTrackedExpense( * Submit expense to another user */ function requestMoney(requestMoneyInformation: RequestMoneyInformation) { - const {report, participantParams, policyParams = {}, transactionData, gpsPoints, action, reimbursible} = requestMoneyInformation; + const {report, participantParams, policyParams = {}, transactionParams, gpsPoints, action, reimbursible} = requestMoneyInformation; const {participant, payeeAccountID, payeeEmail} = participantParams; const {policy, policyCategories, policyTagList} = policyParams; const { @@ -3584,7 +3584,7 @@ function requestMoney(requestMoneyInformation: RequestMoneyInformation) { actionableWhisperReportActionID, linkedTrackedExpenseReportAction, linkedTrackedExpenseReportID, - } = transactionData; + } = transactionParams; // If the report is iou or expense report, we should get the linked chat report to be passed to the getMoneyRequestInformation function const isMoneyRequestReport = ReportUtils.isMoneyRequestReport(report); diff --git a/src/pages/iou/request/step/IOURequestStepAmount.tsx b/src/pages/iou/request/step/IOURequestStepAmount.tsx index 5a9fa9358355..72a931bf359c 100644 --- a/src/pages/iou/request/step/IOURequestStepAmount.tsx +++ b/src/pages/iou/request/step/IOURequestStepAmount.tsx @@ -217,7 +217,7 @@ function IOURequestStepAmount({ payeeEmail: currentUserPersonalDetails.login, payeeAccountID: currentUserPersonalDetails.accountID, }, - transactionData: { + transactionParams: { amount: backendAmount, currency, created: transaction?.created ?? '', diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index 1c3a34bfff42..d8c48dc3d587 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -252,7 +252,7 @@ function IOURequestStepConfirmation({ }, gpsPoints, action, - transactionData: { + transactionParams: { amount: transaction.amount, attendees: transaction.attendees, currency: transaction.currency, diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx index 29dccaa0f9f1..d491c196e9c2 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx @@ -262,7 +262,7 @@ function IOURequestStepScan({ payeeAccountID: currentUserPersonalDetails.accountID, participant, }, - transactionData: { + transactionParams: { amount: 0, attendees: transaction?.attendees, currency: transaction?.currency ?? 'USD', @@ -369,7 +369,7 @@ function IOURequestStepScan({ lat: successData.coords.latitude, long: successData.coords.longitude, }, - transactionData: { + transactionParams: { amount: 0, attendees: transaction?.attendees, currency: transaction?.currency ?? 'USD', diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.tsx index eb40fba34ddf..bc8622072226 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.tsx @@ -291,7 +291,7 @@ function IOURequestStepScan({ payeeAccountID: currentUserPersonalDetails.accountID, participant, }, - transactionData: { + transactionParams: { amount: 0, attendees: transaction?.attendees, currency: transaction?.currency ?? 'USD', @@ -399,7 +399,7 @@ function IOURequestStepScan({ lat: successData.coords.latitude, long: successData.coords.longitude, }, - transactionData: { + transactionParams: { amount: 0, attendees: transaction?.attendees, currency: transaction?.currency ?? 'USD', diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 1928ed694228..4430ec0ce052 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -87,7 +87,7 @@ describe('actions/IOU', () => { payeeAccountID: RORY_ACCOUNT_ID, participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, }, - transactionData: { + transactionParams: { amount, attendees: [], currency: CONST.CURRENCY.USD, @@ -301,7 +301,7 @@ describe('actions/IOU', () => { payeeAccountID: RORY_ACCOUNT_ID, participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, }, - transactionData: { + transactionParams: { amount, attendees: [], currency: CONST.CURRENCY.USD, @@ -520,7 +520,7 @@ describe('actions/IOU', () => { payeeAccountID: RORY_ACCOUNT_ID, participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, }, - transactionData: { + transactionParams: { amount, attendees: [], currency: CONST.CURRENCY.USD, @@ -675,7 +675,7 @@ describe('actions/IOU', () => { payeeAccountID: RORY_ACCOUNT_ID, participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, }, - transactionData: { + transactionParams: { amount, attendees: [], currency: CONST.CURRENCY.USD, @@ -1491,7 +1491,7 @@ describe('actions/IOU', () => { payeeAccountID: RORY_ACCOUNT_ID, participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, }, - transactionData: { + transactionParams: { amount, attendees: [], currency: CONST.CURRENCY.USD, @@ -1727,7 +1727,7 @@ describe('actions/IOU', () => { payeeAccountID: RORY_ACCOUNT_ID, participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, }, - transactionData: { + transactionParams: { amount, attendees: [], currency: CONST.CURRENCY.USD, @@ -1855,7 +1855,7 @@ describe('actions/IOU', () => { payeeAccountID: RORY_ACCOUNT_ID, participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, }, - transactionData: { + transactionParams: { amount, attendees: [], currency: CONST.CURRENCY.USD, @@ -1956,7 +1956,7 @@ describe('actions/IOU', () => { payeeAccountID: TEST_USER_ACCOUNT_ID, participant: {login: RORY_EMAIL, accountID: RORY_ACCOUNT_ID}, }, - transactionData: { + transactionParams: { amount, attendees: [], currency: CONST.CURRENCY.USD, @@ -2705,7 +2705,7 @@ describe('actions/IOU', () => { payeeAccountID: TEST_USER_ACCOUNT_ID, participant: {login: RORY_EMAIL, accountID: RORY_ACCOUNT_ID}, }, - transactionData: { + transactionParams: { amount: amount2, attendees: [], currency: CONST.CURRENCY.USD, @@ -2923,7 +2923,7 @@ describe('actions/IOU', () => { payeeAccountID: RORY_ACCOUNT_ID, participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID, isPolicyExpenseChat: true, reportID: chatReport.reportID}, }, - transactionData: { + transactionParams: { amount, attendees: [], currency: CONST.CURRENCY.USD, @@ -3030,7 +3030,7 @@ describe('actions/IOU', () => { payeeAccountID: RORY_ACCOUNT_ID, participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID, isPolicyExpenseChat: true, reportID: chatReport.reportID}, }, - transactionData: { + transactionParams: { amount, attendees: [], currency: CONST.CURRENCY.USD, @@ -3138,7 +3138,7 @@ describe('actions/IOU', () => { payeeAccountID: RORY_ACCOUNT_ID, participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID, isPolicyExpenseChat: true, reportID: chatReport.reportID}, }, - transactionData: { + transactionParams: { amount, attendees: [], currency: CONST.CURRENCY.USD,