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