@@ -70,11 +70,13 @@ function buildExpenseReport(overrides: Partial<Report> = {}): Report {
7070 } as Report ;
7171}
7272
73+ // Expense-report transactions are stored with the opposite sign, so a positive stored `amount` (e.g. 10000) is a
74+ // spend that `getAmount`/the snapshot total represent as negative (-10000). Mirrors real Onyx data.
7375function buildTransaction ( overrides : Partial < Transaction > = { } ) : Transaction {
7476 return {
7577 transactionID : 'reportMoveTxn' ,
7678 reportID : EXPENSE_REPORT_ID ,
77- amount : - 10000 ,
79+ amount : 10000 ,
7880 currency : CONST . CURRENCY . USD ,
7981 reimbursable : true ,
8082 created : '2026-01-15' ,
@@ -83,6 +85,8 @@ function buildTransaction(overrides: Partial<Transaction> = {}): Transaction {
8385 } as Transaction ;
8486}
8587
88+ const TRANSACTION_KEY = `${ ONYXKEYS . COLLECTION . TRANSACTION } reportMoveTxn` as const ;
89+
8690beforeAll ( ( ) => {
8791 Onyx . init ( {
8892 keys : ONYXKEYS ,
@@ -120,7 +124,7 @@ async function seedRepaidSnapshot(total: number, currency: string = CONST.CURREN
120124
121125describe ( 'getYourSpendSnapshotReportMoveUpdates' , ( ) => {
122126 it ( 'adds the report total to awaiting approval when a report is submitted (OPEN -> SUBMITTED)' , async ( ) => {
123- const snapshotKey = await seedAwaitingApprovalSnapshot ( 10000 ) ;
127+ const snapshotKey = await seedAwaitingApprovalSnapshot ( - 10000 ) ;
124128
125129 const { optimisticData, failureData} = getYourSpendSnapshotReportMoveUpdates ( {
126130 iouReport : buildExpenseReport ( SUBMITTED_STATUS ) ,
@@ -130,22 +134,32 @@ describe('getYourSpendSnapshotReportMoveUpdates', () => {
130134 currentUserAccountID : ACCOUNT_ID ,
131135 } ) ;
132136
137+ // Submitting adds the report's (negative) spend to the section total and injects the transaction into
138+ // `data` so the linked Search page is not empty offline.
133139 expect ( optimisticData ) . toEqual ( [
134140 expect . objectContaining ( {
135141 key : snapshotKey ,
136- value : { search : { total : 20000 , count : 2 , currency : CONST . CURRENCY . USD } } ,
142+ value : { search : { total : - 20000 , count : 2 , currency : CONST . CURRENCY . USD } } ,
143+ } ) ,
144+ expect . objectContaining ( {
145+ key : snapshotKey ,
146+ value : { data : { [ TRANSACTION_KEY ] : buildTransaction ( ) } } ,
137147 } ) ,
138148 ] ) ;
139149 expect ( failureData ) . toEqual ( [
140150 expect . objectContaining ( {
141151 key : snapshotKey ,
142- value : { search : { total : 10000 , count : 1 , currency : CONST . CURRENCY . USD } } ,
152+ value : { search : { total : - 10000 , count : 1 , currency : CONST . CURRENCY . USD } } ,
153+ } ) ,
154+ expect . objectContaining ( {
155+ key : snapshotKey ,
156+ value : { data : { [ TRANSACTION_KEY ] : null } } ,
143157 } ) ,
144158 ] ) ;
145159 } ) ;
146160
147161 it ( 'subtracts the report total from awaiting approval when a report is retracted (SUBMITTED -> OPEN)' , async ( ) => {
148- const snapshotKey = await seedAwaitingApprovalSnapshot ( 30000 ) ;
162+ const snapshotKey = await seedAwaitingApprovalSnapshot ( - 30000 ) ;
149163
150164 const { optimisticData} = getYourSpendSnapshotReportMoveUpdates ( {
151165 iouReport : buildExpenseReport ( OPEN_STATUS ) ,
@@ -155,16 +169,21 @@ describe('getYourSpendSnapshotReportMoveUpdates', () => {
155169 currentUserAccountID : ACCOUNT_ID ,
156170 } ) ;
157171
172+ // Leaving the section removes the (negative) spend from the total and removes the transaction from `data`.
158173 expect ( optimisticData ) . toEqual ( [
159174 expect . objectContaining ( {
160175 key : snapshotKey ,
161- value : { search : { total : 20000 , count : 0 , currency : CONST . CURRENCY . USD } } ,
176+ value : { search : { total : - 20000 , count : 0 , currency : CONST . CURRENCY . USD } } ,
177+ } ) ,
178+ expect . objectContaining ( {
179+ key : snapshotKey ,
180+ value : { data : { [ TRANSACTION_KEY ] : null } } ,
162181 } ) ,
163182 ] ) ;
164183 } ) ;
165184
166185 it ( 'subtracts the report total from awaiting approval when a report is rejected (SUBMITTED -> OPEN)' , async ( ) => {
167- const snapshotKey = await seedAwaitingApprovalSnapshot ( 30000 ) ;
186+ const snapshotKey = await seedAwaitingApprovalSnapshot ( - 30000 ) ;
168187
169188 const { optimisticData} = getYourSpendSnapshotReportMoveUpdates ( {
170189 iouReport : buildExpenseReport ( OPEN_STATUS ) ,
@@ -177,13 +196,17 @@ describe('getYourSpendSnapshotReportMoveUpdates', () => {
177196 expect ( optimisticData ) . toEqual ( [
178197 expect . objectContaining ( {
179198 key : snapshotKey ,
180- value : { search : { total : 20000 , count : 0 , currency : CONST . CURRENCY . USD } } ,
199+ value : { search : { total : - 20000 , count : 0 , currency : CONST . CURRENCY . USD } } ,
200+ } ) ,
201+ expect . objectContaining ( {
202+ key : snapshotKey ,
203+ value : { data : { [ TRANSACTION_KEY ] : null } } ,
181204 } ) ,
182205 ] ) ;
183206 } ) ;
184207
185208 it ( 'adds the report total back to awaiting approval when a report is unapproved (APPROVED -> SUBMITTED)' , async ( ) => {
186- const snapshotKey = await seedAwaitingApprovalSnapshot ( 10000 ) ;
209+ const snapshotKey = await seedAwaitingApprovalSnapshot ( - 10000 ) ;
187210
188211 const { optimisticData} = getYourSpendSnapshotReportMoveUpdates ( {
189212 iouReport : buildExpenseReport ( SUBMITTED_STATUS ) ,
@@ -196,17 +219,22 @@ describe('getYourSpendSnapshotReportMoveUpdates', () => {
196219 expect ( optimisticData ) . toEqual ( [
197220 expect . objectContaining ( {
198221 key : snapshotKey ,
199- value : { search : { total : 20000 , count : 2 , currency : CONST . CURRENCY . USD } } ,
222+ value : { search : { total : - 20000 , count : 2 , currency : CONST . CURRENCY . USD } } ,
223+ } ) ,
224+ expect . objectContaining ( {
225+ key : snapshotKey ,
226+ value : { data : { [ TRANSACTION_KEY ] : buildTransaction ( ) } } ,
200227 } ) ,
201228 ] ) ;
202229 } ) ;
203230
204231 it ( 'subtracts the report total from repaid when a payment is cancelled (REIMBURSED -> APPROVED)' , async ( ) => {
205- const snapshotKey = await seedRepaidSnapshot ( 30000 ) ;
232+ const snapshotKey = await seedRepaidSnapshot ( - 30000 ) ;
233+ const recentTransaction = buildTransaction ( { created : getRecentCreatedDate ( ) } ) ;
206234
207235 const { optimisticData} = getYourSpendSnapshotReportMoveUpdates ( {
208236 iouReport : buildExpenseReport ( APPROVED_STATUS ) ,
209- reportTransactions : [ buildTransaction ( { created : getRecentCreatedDate ( ) } ) ] ,
237+ reportTransactions : [ recentTransaction ] ,
210238 fromStatus : REIMBURSED_STATUS ,
211239 toStatus : APPROVED_STATUS ,
212240 currentUserAccountID : ACCOUNT_ID ,
@@ -215,7 +243,11 @@ describe('getYourSpendSnapshotReportMoveUpdates', () => {
215243 expect ( optimisticData ) . toEqual ( [
216244 expect . objectContaining ( {
217245 key : snapshotKey ,
218- value : { search : { total : 20000 , count : 0 , currency : CONST . CURRENCY . USD } } ,
246+ value : { search : { total : - 20000 , count : 0 , currency : CONST . CURRENCY . USD } } ,
247+ } ) ,
248+ expect . objectContaining ( {
249+ key : snapshotKey ,
250+ value : { data : { [ TRANSACTION_KEY ] : null } } ,
219251 } ) ,
220252 ] ) ;
221253 } ) ;
@@ -280,11 +312,12 @@ describe('getYourSpendSnapshotReportMoveUpdates', () => {
280312 } ) ;
281313
282314 it ( 'patches using convertedAmount when the snapshot currency differs from the transaction currency' , async ( ) => {
283- const snapshotKey = await seedAwaitingApprovalSnapshot ( 10000 ) ;
315+ const snapshotKey = await seedAwaitingApprovalSnapshot ( - 10000 ) ;
316+ const convertedTransaction = buildTransaction ( { currency : CONST . CURRENCY . EUR , amount : 10000 , convertedAmount : 5000 } ) ;
284317
285318 const { optimisticData} = getYourSpendSnapshotReportMoveUpdates ( {
286319 iouReport : buildExpenseReport ( { ...SUBMITTED_STATUS , currency : CONST . CURRENCY . EUR } ) ,
287- reportTransactions : [ buildTransaction ( { currency : CONST . CURRENCY . EUR , amount : - 10000 , convertedAmount : - 5000 } ) ] ,
320+ reportTransactions : [ convertedTransaction ] ,
288321 fromStatus : OPEN_STATUS ,
289322 toStatus : SUBMITTED_STATUS ,
290323 currentUserAccountID : ACCOUNT_ID ,
@@ -293,7 +326,11 @@ describe('getYourSpendSnapshotReportMoveUpdates', () => {
293326 expect ( optimisticData ) . toEqual ( [
294327 expect . objectContaining ( {
295328 key : snapshotKey ,
296- value : { search : { total : 15000 , count : 2 , currency : CONST . CURRENCY . USD } } ,
329+ value : { search : { total : - 15000 , count : 2 , currency : CONST . CURRENCY . USD } } ,
330+ } ) ,
331+ expect . objectContaining ( {
332+ key : snapshotKey ,
333+ value : { data : { [ TRANSACTION_KEY ] : convertedTransaction } } ,
297334 } ) ,
298335 ] ) ;
299336 } ) ;
@@ -307,7 +344,7 @@ describe('getYourSpendSnapshotReportMoveUpdates', () => {
307344
308345 const { optimisticData} = getYourSpendSnapshotReportMoveUpdates ( {
309346 iouReport : buildExpenseReport ( { ...SUBMITTED_STATUS , currency : CONST . CURRENCY . GBP } ) ,
310- reportTransactions : [ buildTransaction ( { currency : CONST . CURRENCY . GBP , amount : - 10000 , convertedAmount : - 5000 } ) ] ,
347+ reportTransactions : [ buildTransaction ( { currency : CONST . CURRENCY . GBP , amount : 10000 , convertedAmount : 5000 } ) ] ,
311348 fromStatus : OPEN_STATUS ,
312349 toStatus : SUBMITTED_STATUS ,
313350 currentUserAccountID : ACCOUNT_ID ,
@@ -334,7 +371,11 @@ describe('getYourSpendSnapshotReportMoveUpdates', () => {
334371 expect ( optimisticData ) . toEqual ( [
335372 expect . objectContaining ( {
336373 key : snapshotKey ,
337- value : { search : { total : 10000 , count : 1 , currency : CONST . CURRENCY . USD } } ,
374+ value : { search : { total : - 10000 , count : 1 , currency : CONST . CURRENCY . USD } } ,
375+ } ) ,
376+ expect . objectContaining ( {
377+ key : snapshotKey ,
378+ value : { data : { [ TRANSACTION_KEY ] : buildTransaction ( ) } } ,
338379 } ) ,
339380 ] ) ;
340381 } ) ;
0 commit comments