From 768311c95648e3d98170e36d141c908c6b477e53 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Thu, 3 Jul 2025 21:01:19 +0800 Subject: [PATCH] remove original transaction from search snapshot optimistically --- src/libs/actions/IOU.ts | 8 ++---- tests/actions/IOUTest.ts | 60 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 6 deletions(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 43ed11ce5809..7e43a370b0e1 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -11631,7 +11631,6 @@ function saveSplitTransactions(draftTransaction: OnyxEntry { }); expect(originalTransactionThread).toBe(undefined); }); + + it('should remove the original transaction from the search snapshot data', async () => { + // Given a single expense + const expenseReport: Report = { + ...createRandomReport(1), + type: CONST.REPORT.TYPE.EXPENSE, + }; + const transaction: Transaction = { + amount: 100, + currency: 'USD', + transactionID: '1', + reportID: expenseReport.reportID, + created: DateUtils.getDBTime(), + merchant: 'test', + }; + const transactionThread: Report = { + ...createRandomReport(2), + }; + const iouAction: ReportAction = { + ...buildOptimisticIOUReportAction({ + type: CONST.IOU.REPORT_ACTION_TYPE.CREATE, + amount: transaction.amount, + currency: transaction.currency, + comment: '', + participants: [], + transactionID: transaction.transactionID, + iouReportID: expenseReport.reportID, + }), + childReportID: transactionThread.reportID, + }; + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${expenseReport.reportID}`, expenseReport); + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${transactionThread.reportID}`, transactionThread); + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.reportID}`, { + [iouAction.reportActionID]: iouAction, + }); + const draftTransaction: OnyxEntry = { + ...transaction, + comment: { + originalTransactionID: transaction.transactionID, + }, + }; + + // When splitting the expense + const hash = 1; + saveSplitTransactions(draftTransaction, hash); + + await waitForBatchedUpdates(); + + // Then the original expense/transaction should be removed from the search snapshot data + const searchSnapshot = await new Promise>((resolve) => { + const connection = Onyx.connect({ + key: `${ONYXKEYS.COLLECTION.SNAPSHOT}${hash}`, + callback: (val) => { + Onyx.disconnect(connection); + resolve(val); + }, + }); + }); + expect(searchSnapshot?.data[`${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`]).toBe(undefined); + }); }); describe('payMoneyRequestElsewhere', () => {