From 63ee178d2588f50eecc90f54f87c19d3d4105a21 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Wed, 16 Oct 2024 11:29:59 +0700 Subject: [PATCH 01/15] fix: Not here page when create new request --- src/libs/actions/IOU.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 0f974566a98b..dad6dcd31c46 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -7481,6 +7481,13 @@ function cancelPayment(expenseReport: OnyxEntry, chatReport: O }, }, }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`, + value: { + iouReportID: chatReport?.iouReportID ? chatReport?.iouReportID : expenseReport.reportID, + }, + }, { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${expenseReport.reportID}`, From a3ee0881257c6d5248b61042f8256d86a9c8e6dc Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Mon, 21 Oct 2024 10:26:57 +0700 Subject: [PATCH 02/15] fix: logic merge chat report --- src/libs/actions/IOU.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 6c94d36a9e19..8df3cd913dac 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -7489,6 +7489,10 @@ function cancelPayment(expenseReport: OnyxEntry, chatReport: O const stateNum: ValueOf = approvalMode === CONST.POLICY.APPROVAL_MODE.OPTIONAL ? CONST.REPORT.STATE_NUM.SUBMITTED : CONST.REPORT.STATE_NUM.APPROVED; const statusNum: ValueOf = approvalMode === CONST.POLICY.APPROVAL_MODE.OPTIONAL ? CONST.REPORT.STATUS_NUM.CLOSED : CONST.REPORT.STATUS_NUM.APPROVED; const optimisticNextStep = NextStepUtils.buildNextStep(expenseReport, statusNum); + const iouReportActions = ReportActionsUtils.getAllReportActions(chatReport.iouReportID ?? '-1'); + const expenseReportActions = ReportActionsUtils.getAllReportActions(expenseReport.reportID ?? '-1'); + const iouCreatedAction = Object.values(iouReportActions).find((action) => ReportActionsUtils.isCreatedAction(action)); + const expenseCreatedAction = Object.values(expenseReportActions).find((action) => ReportActionsUtils.isCreatedAction(action)); const optimisticData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -7504,7 +7508,7 @@ function cancelPayment(expenseReport: OnyxEntry, chatReport: O onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`, value: { - iouReportID: chatReport?.iouReportID ? chatReport?.iouReportID : expenseReport.reportID, + iouReportID: (iouCreatedAction?.created ?? '') > (expenseCreatedAction?.created ?? '') ? chatReport?.iouReportID : expenseReport.reportID, }, }, { From 6194ced9e1295494f80aba7c4a8f3aba0e5202bb Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Mon, 25 Nov 2024 16:33:09 +0700 Subject: [PATCH 03/15] fix: not show create expense button when it closed --- src/libs/ReportUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 952e0c2fe4cc..002f69f9431d 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1794,7 +1794,7 @@ function canAddOrDeleteTransactions(moneyRequestReport: OnyxEntry): bool return isAwaitingFirstLevelApproval(moneyRequestReport); } - if (isReportApproved(moneyRequestReport) || isSettled(moneyRequestReport?.reportID)) { + if (isReportApproved(moneyRequestReport) || isClosedReport(moneyRequestReport) || isSettled(moneyRequestReport?.reportID)) { return false; } From 1680b850a851832ee8335e9933848a9bb4d7c452 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Wed, 27 Nov 2024 18:02:36 +0700 Subject: [PATCH 04/15] add comment --- src/libs/actions/IOU.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index da9f95382132..c1bfe02114b6 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -7336,6 +7336,7 @@ function cancelPayment(expenseReport: OnyxEntry, chatReport: O onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`, value: { + // The report created later will become the iouReportID of the chat report iouReportID: (iouCreatedAction?.created ?? '') > (expenseCreatedAction?.created ?? '') ? chatReport?.iouReportID : expenseReport.reportID, }, }, From 36bb786864dce8ddb7d7bd385655a48531aeadb1 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Thu, 28 Nov 2024 16:03:24 +0700 Subject: [PATCH 05/15] fix: add test for cancel payment --- tests/actions/IOUTest.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 4430ec0ce052..9b34578bbc66 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -1675,6 +1675,28 @@ describe('actions/IOU', () => { ); expect(payIOUAction).toBeTruthy(); + resolve(); + }, + }); + }), + ) + .then(() => { + mockFetch?.pause?.(); + if (chatReport && iouReport) { + IOU.cancelPayment(iouReport, chatReport); + } + return waitForBatchedUpdates(); + }) + .then( + () => + new Promise((resolve) => { + const connection = Onyx.connect({ + key: ONYXKEYS.COLLECTION.REPORT, + waitForCollectionCallback: true, + callback: (allReports) => { + Onyx.disconnect(connection); + const chatReportData = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReport?.reportID}`]; + expect(chatReportData?.iouReportID).toBe(iouReport?.reportID); resolve(); }, }); From ff6c9e8d5ea1a63bbe315cefe2bcb192d4df2e87 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Tue, 3 Dec 2024 15:55:55 +0700 Subject: [PATCH 06/15] Add test for cancel payment --- tests/actions/IOUTest.ts | 124 ++++++++++++++++++++++++++++++++------- 1 file changed, 102 insertions(+), 22 deletions(-) diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 9b34578bbc66..41edb0efc096 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -1675,28 +1675,6 @@ describe('actions/IOU', () => { ); expect(payIOUAction).toBeTruthy(); - resolve(); - }, - }); - }), - ) - .then(() => { - mockFetch?.pause?.(); - if (chatReport && iouReport) { - IOU.cancelPayment(iouReport, chatReport); - } - return waitForBatchedUpdates(); - }) - .then( - () => - new Promise((resolve) => { - const connection = Onyx.connect({ - key: ONYXKEYS.COLLECTION.REPORT, - waitForCollectionCallback: true, - callback: (allReports) => { - Onyx.disconnect(connection); - const chatReportData = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReport?.reportID}`]; - expect(chatReportData?.iouReportID).toBe(iouReport?.reportID); resolve(); }, }); @@ -1929,6 +1907,108 @@ describe('actions/IOU', () => { }); }); + describe('cancelPayment', () => { + const amount = 10000; + const comment = '💸💸💸💸'; + const merchant = 'NASDAQ'; + + afterEach(() => { + mockFetch?.resume?.(); + }); + + it('the report created later will become the iouReportID of the chat report', () => { + let expenseReport: OnyxEntry; + let chatReport: OnyxEntry; + + mockFetch?.pause?.(); + Onyx.set(ONYXKEYS.SESSION, {email: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}); + return waitForBatchedUpdates() + .then(() => { + PolicyActions.createWorkspace(CARLOS_EMAIL, true, "Carlos's Workspace"); + return waitForBatchedUpdates(); + }) + .then( + () => + new Promise((resolve) => { + const connection = Onyx.connect({ + key: ONYXKEYS.COLLECTION.REPORT, + waitForCollectionCallback: true, + callback: (allReports) => { + Onyx.disconnect(connection); + chatReport = Object.values(allReports ?? {}).find((report) => report?.chatType === CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT); + + resolve(); + }, + }); + }), + ) + .then(() => { + if (chatReport) { + IOU.requestMoney({ + report: chatReport, + participantParams: { + payeeEmail: RORY_EMAIL, + payeeAccountID: RORY_ACCOUNT_ID, + participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, + }, + transactionParams: { + amount, + attendees: [], + currency: CONST.CURRENCY.USD, + created: '', + merchant, + comment, + }, + }); + } + return waitForBatchedUpdates(); + }) + .then( + () => + new Promise((resolve) => { + const connection = Onyx.connect({ + key: ONYXKEYS.COLLECTION.REPORT, + waitForCollectionCallback: true, + callback: (allReports) => { + Onyx.disconnect(connection); + expenseReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.IOU); + + resolve(); + }, + }); + }), + ) + .then(() => { + if (chatReport && expenseReport) { + IOU.payMoneyRequest(CONST.IOU.PAYMENT_TYPE.ELSEWHERE, chatReport, expenseReport); + } + return waitForBatchedUpdates(); + }) + .then(() => { + mockFetch?.pause?.(); + if (chatReport && expenseReport) { + IOU.cancelPayment(expenseReport, chatReport); + } + return waitForBatchedUpdates(); + }) + .then( + () => + new Promise((resolve) => { + const connection = Onyx.connect({ + key: ONYXKEYS.COLLECTION.REPORT, + waitForCollectionCallback: true, + callback: (allReports) => { + Onyx.disconnect(connection); + const chatReportData = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReport?.reportID}`]; + expect(chatReportData?.iouReportID).toBe(expenseReport?.reportID); + resolve(); + }, + }); + }), + ); + }); + }); + describe('deleteMoneyRequest', () => { const amount = 10000; const comment = 'Send me money please'; From 09f92325dc2e64f2a9b4d4f0df77151a590bc4ef Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Thu, 5 Dec 2024 15:29:09 +0700 Subject: [PATCH 07/15] fix: add comment for cancel payment test --- tests/actions/IOUTest.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 47aaa8aa9a84..e1cf35bf441b 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -1907,7 +1907,7 @@ describe('actions/IOU', () => { }); }); - describe('cancelPayment', () => { + describe('a workspace chat with a cancelled payment', () => { const amount = 10000; const comment = '💸💸💸💸'; const merchant = 'NASDAQ'; @@ -1916,11 +1916,10 @@ describe('actions/IOU', () => { mockFetch?.resume?.(); }); - it('the report created later will become the iouReportID of the chat report', () => { + it("has an iouReportID of the cancelled payment's expense report", () => { let expenseReport: OnyxEntry; let chatReport: OnyxEntry; - mockFetch?.pause?.(); Onyx.set(ONYXKEYS.SESSION, {email: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}); return waitForBatchedUpdates() .then(() => { @@ -1944,6 +1943,7 @@ describe('actions/IOU', () => { ) .then(() => { if (chatReport) { + // When a submit IOU expense is made IOU.requestMoney({ report: chatReport, participantParams: { @@ -1985,8 +1985,8 @@ describe('actions/IOU', () => { return waitForBatchedUpdates(); }) .then(() => { - mockFetch?.pause?.(); if (chatReport && expenseReport) { + // When we attempt to cancle payment an expense from the expense report IOU.cancelPayment(expenseReport, chatReport); } return waitForBatchedUpdates(); @@ -1997,9 +1997,11 @@ describe('actions/IOU', () => { const connection = Onyx.connect({ key: ONYXKEYS.COLLECTION.REPORT, waitForCollectionCallback: true, + // When fetching all reports from Onyx callback: (allReports) => { Onyx.disconnect(connection); const chatReportData = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReport?.reportID}`]; + // Then we should find an IOU action with specific properties expect(chatReportData?.iouReportID).toBe(expenseReport?.reportID); resolve(); }, From 0a6267d53b3935a9fbc1052719c437c0e82772cc Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Fri, 6 Dec 2024 01:51:58 +0700 Subject: [PATCH 08/15] implement getOnyxData function --- tests/actions/IOUTest.ts | 22 ++++++++-------------- tests/utils/TestHelper.ts | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index e1cf35bf441b..fae75be322a4 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -1963,20 +1963,14 @@ describe('actions/IOU', () => { } return waitForBatchedUpdates(); }) - .then( - () => - new Promise((resolve) => { - const connection = Onyx.connect({ - key: ONYXKEYS.COLLECTION.REPORT, - waitForCollectionCallback: true, - callback: (allReports) => { - Onyx.disconnect(connection); - expenseReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.IOU); - - resolve(); - }, - }); - }), + .then(() => + TestHelper.getOnyxData({ + key: ONYXKEYS.COLLECTION.REPORT, + waitForCollectionCallback: true, + callback: (allReports) => { + expenseReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.IOU); + }, + }), ) .then(() => { if (chatReport && expenseReport) { diff --git a/tests/utils/TestHelper.ts b/tests/utils/TestHelper.ts index 394c05fe8b7c..f3814d4b91cb 100644 --- a/tests/utils/TestHelper.ts +++ b/tests/utils/TestHelper.ts @@ -2,6 +2,7 @@ import {fireEvent, screen} from '@testing-library/react-native'; import {Str} from 'expensify-common'; import {Linking} from 'react-native'; import Onyx from 'react-native-onyx'; +import type {ConnectOptions} from 'react-native-onyx/dist/types'; import type {ApiCommand, ApiRequestCommandParameters} from '@libs/API/types'; import * as Localize from '@libs/Localize'; import * as Pusher from '@libs/Pusher/pusher'; @@ -12,6 +13,7 @@ import * as Session from '@src/libs/actions/Session'; import HttpUtils from '@src/libs/HttpUtils'; import * as NumberUtils from '@src/libs/NumberUtils'; import ONYXKEYS from '@src/ONYXKEYS'; +import type {OnyxKey} from '@src/ONYXKEYS'; import appSetup from '@src/setup'; import type {Response as OnyxResponse, PersonalDetails, Report} from '@src/types/onyx'; import waitForBatchedUpdates from './waitForBatchedUpdates'; @@ -25,6 +27,9 @@ type MockFetch = jest.MockedFn & { mockAPICommand: (command: TCommand, responseHandler: (params: ApiRequestCommandParameters[TCommand]) => OnyxResponse) => void; }; +type ConnectionCallback = NonNullable['callback']>; +type ConnectionCallbackParams = Parameters>; + type QueueItem = { resolve: (value: Partial | PromiseLike>) => void; input: RequestInfo; @@ -65,6 +70,19 @@ function buildPersonalDetails(login: string, accountID: number, firstName = 'Tes }; } +function getOnyxData(options: ConnectOptions) { + return new Promise((resolve) => { + const connectionID = Onyx.connect({ + ...options, + callback: (...params: ConnectionCallbackParams) => { + Onyx.disconnect(connectionID); + (options.callback as (...args: ConnectionCallbackParams) => void)?.(...params); + resolve(); + }, + }); + }); +} + /** * Simulate signing in and make sure all API calls in this flow succeed. Every time we add * a mockImplementationOnce() we are altering what Network.post() will return. @@ -335,4 +353,5 @@ export { expectAPICommandToHaveBeenCalledWith, setupGlobalFetchMock, navigateToSidebarOption, + getOnyxData, }; From 852b2c7ef7b09b3c5f746bc400b19b4b3bc98a2c Mon Sep 17 00:00:00 2001 From: nkdengineer <161821005+nkdengineer@users.noreply.github.com> Date: Fri, 6 Dec 2024 02:52:38 +0700 Subject: [PATCH 09/15] Update tests/actions/IOUTest.ts Co-authored-by: Tim Golen --- tests/actions/IOUTest.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index fae75be322a4..ccdcafb816fa 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -1920,14 +1920,17 @@ describe('actions/IOU', () => { let expenseReport: OnyxEntry; let chatReport: OnyxEntry; + // Given a signed in account, which owns a workspace, and has a policy expense chat Onyx.set(ONYXKEYS.SESSION, {email: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}); return waitForBatchedUpdates() .then(() => { + // Which owns a workspace PolicyActions.createWorkspace(CARLOS_EMAIL, true, "Carlos's Workspace"); return waitForBatchedUpdates(); }) .then( () => + // And new Promise((resolve) => { const connection = Onyx.connect({ key: ONYXKEYS.COLLECTION.REPORT, @@ -1943,7 +1946,7 @@ describe('actions/IOU', () => { ) .then(() => { if (chatReport) { - // When a submit IOU expense is made + // When an IOU expense is submitted to that policy expense chat IOU.requestMoney({ report: chatReport, participantParams: { From 9cd80deda8744a3eaa5e22ea5ea3155f027b6051 Mon Sep 17 00:00:00 2001 From: nkdengineer <161821005+nkdengineer@users.noreply.github.com> Date: Fri, 6 Dec 2024 02:52:46 +0700 Subject: [PATCH 10/15] Update tests/actions/IOUTest.ts Co-authored-by: Tim Golen --- tests/actions/IOUTest.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index ccdcafb816fa..6eeb616837ac 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -1967,6 +1967,7 @@ describe('actions/IOU', () => { return waitForBatchedUpdates(); }) .then(() => + // And given an expense report has now been created which holds the IOU TestHelper.getOnyxData({ key: ONYXKEYS.COLLECTION.REPORT, waitForCollectionCallback: true, From 2e58d79d0915632b572f5995d418928b880e849a Mon Sep 17 00:00:00 2001 From: nkdengineer <161821005+nkdengineer@users.noreply.github.com> Date: Fri, 6 Dec 2024 02:52:57 +0700 Subject: [PATCH 11/15] Update tests/actions/IOUTest.ts Co-authored-by: Tim Golen --- tests/actions/IOUTest.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 6eeb616837ac..8f025066f56d 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -1977,6 +1977,7 @@ describe('actions/IOU', () => { }), ) .then(() => { + // When the expense report is paid elsewhere (but really, any payment option would work) if (chatReport && expenseReport) { IOU.payMoneyRequest(CONST.IOU.PAYMENT_TYPE.ELSEWHERE, chatReport, expenseReport); } From 534548005088e276952ff66c8c2672f1282d5e34 Mon Sep 17 00:00:00 2001 From: nkdengineer <161821005+nkdengineer@users.noreply.github.com> Date: Fri, 6 Dec 2024 02:53:08 +0700 Subject: [PATCH 12/15] Update tests/actions/IOUTest.ts Co-authored-by: Tim Golen --- tests/actions/IOUTest.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 8f025066f56d..370018f5660b 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -1985,7 +1985,7 @@ describe('actions/IOU', () => { }) .then(() => { if (chatReport && expenseReport) { - // When we attempt to cancle payment an expense from the expense report + // And when the payment is cancelled IOU.cancelPayment(expenseReport, chatReport); } return waitForBatchedUpdates(); From 8591f6616ecc33d80c7f63e2f4e1d881d9ab5ac5 Mon Sep 17 00:00:00 2001 From: nkdengineer <161821005+nkdengineer@users.noreply.github.com> Date: Fri, 6 Dec 2024 02:53:15 +0700 Subject: [PATCH 13/15] Update tests/actions/IOUTest.ts Co-authored-by: Tim Golen --- tests/actions/IOUTest.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 370018f5660b..260f397570f7 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -1996,7 +1996,6 @@ describe('actions/IOU', () => { const connection = Onyx.connect({ key: ONYXKEYS.COLLECTION.REPORT, waitForCollectionCallback: true, - // When fetching all reports from Onyx callback: (allReports) => { Onyx.disconnect(connection); const chatReportData = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReport?.reportID}`]; From 3c846b6122b577a8cd132c7ee450d926525b569d Mon Sep 17 00:00:00 2001 From: nkdengineer <161821005+nkdengineer@users.noreply.github.com> Date: Fri, 6 Dec 2024 02:53:22 +0700 Subject: [PATCH 14/15] Update tests/actions/IOUTest.ts Co-authored-by: Tim Golen --- tests/actions/IOUTest.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 260f397570f7..11ce0f05b1b2 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -1999,7 +1999,7 @@ describe('actions/IOU', () => { callback: (allReports) => { Onyx.disconnect(connection); const chatReportData = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReport?.reportID}`]; - // Then we should find an IOU action with specific properties + // Then the policy expense chat report has the iouReportID of the IOU expense report expect(chatReportData?.iouReportID).toBe(expenseReport?.reportID); resolve(); }, From 730f3ff5852456c113e7623d4aab2406d4b79761 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Mon, 9 Dec 2024 16:18:26 +0700 Subject: [PATCH 15/15] use getOnyxData --- tests/actions/IOUTest.ts | 48 +++++++++++++++------------------------- 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 11ce0f05b1b2..11ff821cb240 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -1928,21 +1928,14 @@ describe('actions/IOU', () => { PolicyActions.createWorkspace(CARLOS_EMAIL, true, "Carlos's Workspace"); return waitForBatchedUpdates(); }) - .then( - () => - // And - new Promise((resolve) => { - const connection = Onyx.connect({ - key: ONYXKEYS.COLLECTION.REPORT, - waitForCollectionCallback: true, - callback: (allReports) => { - Onyx.disconnect(connection); - chatReport = Object.values(allReports ?? {}).find((report) => report?.chatType === CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT); - - resolve(); - }, - }); - }), + .then(() => + TestHelper.getOnyxData({ + key: ONYXKEYS.COLLECTION.REPORT, + waitForCollectionCallback: true, + callback: (allReports) => { + chatReport = Object.values(allReports ?? {}).find((report) => report?.chatType === CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT); + }, + }), ) .then(() => { if (chatReport) { @@ -1990,21 +1983,16 @@ describe('actions/IOU', () => { } return waitForBatchedUpdates(); }) - .then( - () => - new Promise((resolve) => { - const connection = Onyx.connect({ - key: ONYXKEYS.COLLECTION.REPORT, - waitForCollectionCallback: true, - callback: (allReports) => { - Onyx.disconnect(connection); - const chatReportData = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReport?.reportID}`]; - // Then the policy expense chat report has the iouReportID of the IOU expense report - expect(chatReportData?.iouReportID).toBe(expenseReport?.reportID); - resolve(); - }, - }); - }), + .then(() => + TestHelper.getOnyxData({ + key: ONYXKEYS.COLLECTION.REPORT, + waitForCollectionCallback: true, + callback: (allReports) => { + const chatReportData = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReport?.reportID}`]; + // Then the policy expense chat report has the iouReportID of the IOU expense report + expect(chatReportData?.iouReportID).toBe(expenseReport?.reportID); + }, + }), ); }); });