Skip to content

Commit 768311c

Browse files
committed
remove original transaction from search snapshot optimistically
1 parent ba687b4 commit 768311c

2 files changed

Lines changed: 62 additions & 6 deletions

File tree

src/libs/actions/IOU.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11631,7 +11631,6 @@ function saveSplitTransactions(draftTransaction: OnyxEntry<OnyxTypes.Transaction
1163111631

1163211632
const originalTransactionID = draftTransaction?.comment?.originalTransactionID ?? CONST.IOU.OPTIMISTIC_TRANSACTION_ID;
1163311633
const originalTransaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${originalTransactionID}`];
11634-
const originalTransactionViolations = allTransactionViolations[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${originalTransactionID}`] ?? [];
1163511634
const iouActions = getIOUActionForTransactions([originalTransactionID], expenseReport?.reportID);
1163611635

1163711636
// This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
@@ -11773,10 +11772,7 @@ function saveSplitTransactions(draftTransaction: OnyxEntry<OnyxTypes.Transaction
1177311772
key: `${ONYXKEYS.COLLECTION.SNAPSHOT}${hash}`,
1177411773
value: {
1177511774
data: {
11776-
[`${ONYXKEYS.COLLECTION.TRANSACTION}${originalTransactionID}`]: {
11777-
...originalTransactionViolations,
11778-
reportID: CONST.REPORT.SPLIT_REPORT_ID,
11779-
},
11775+
[`${ONYXKEYS.COLLECTION.TRANSACTION}${originalTransactionID}`]: null,
1178011776
},
1178111777
},
1178211778
});
@@ -11786,7 +11782,7 @@ function saveSplitTransactions(draftTransaction: OnyxEntry<OnyxTypes.Transaction
1178611782
key: `${ONYXKEYS.COLLECTION.SNAPSHOT}${hash}`,
1178711783
value: {
1178811784
data: {
11789-
[`${ONYXKEYS.COLLECTION.TRANSACTION}${originalTransactionID}`]: originalTransactionViolations,
11785+
[`${ONYXKEYS.COLLECTION.TRANSACTION}${originalTransactionID}`]: originalTransaction,
1179011786
},
1179111787
},
1179211788
});

tests/actions/IOUTest.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2364,6 +2364,66 @@ describe('actions/IOU', () => {
23642364
});
23652365
expect(originalTransactionThread).toBe(undefined);
23662366
});
2367+
2368+
it('should remove the original transaction from the search snapshot data', async () => {
2369+
// Given a single expense
2370+
const expenseReport: Report = {
2371+
...createRandomReport(1),
2372+
type: CONST.REPORT.TYPE.EXPENSE,
2373+
};
2374+
const transaction: Transaction = {
2375+
amount: 100,
2376+
currency: 'USD',
2377+
transactionID: '1',
2378+
reportID: expenseReport.reportID,
2379+
created: DateUtils.getDBTime(),
2380+
merchant: 'test',
2381+
};
2382+
const transactionThread: Report = {
2383+
...createRandomReport(2),
2384+
};
2385+
const iouAction: ReportAction = {
2386+
...buildOptimisticIOUReportAction({
2387+
type: CONST.IOU.REPORT_ACTION_TYPE.CREATE,
2388+
amount: transaction.amount,
2389+
currency: transaction.currency,
2390+
comment: '',
2391+
participants: [],
2392+
transactionID: transaction.transactionID,
2393+
iouReportID: expenseReport.reportID,
2394+
}),
2395+
childReportID: transactionThread.reportID,
2396+
};
2397+
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${expenseReport.reportID}`, expenseReport);
2398+
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${transactionThread.reportID}`, transactionThread);
2399+
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.reportID}`, {
2400+
[iouAction.reportActionID]: iouAction,
2401+
});
2402+
const draftTransaction: OnyxEntry<Transaction> = {
2403+
...transaction,
2404+
comment: {
2405+
originalTransactionID: transaction.transactionID,
2406+
},
2407+
};
2408+
2409+
// When splitting the expense
2410+
const hash = 1;
2411+
saveSplitTransactions(draftTransaction, hash);
2412+
2413+
await waitForBatchedUpdates();
2414+
2415+
// Then the original expense/transaction should be removed from the search snapshot data
2416+
const searchSnapshot = await new Promise<OnyxEntry<SearchResults>>((resolve) => {
2417+
const connection = Onyx.connect({
2418+
key: `${ONYXKEYS.COLLECTION.SNAPSHOT}${hash}`,
2419+
callback: (val) => {
2420+
Onyx.disconnect(connection);
2421+
resolve(val);
2422+
},
2423+
});
2424+
});
2425+
expect(searchSnapshot?.data[`${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`]).toBe(undefined);
2426+
});
23672427
});
23682428

23692429
describe('payMoneyRequestElsewhere', () => {

0 commit comments

Comments
 (0)