@@ -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