11import Onyx from 'react-native-onyx' ;
2+ import type { OnyxCollection } from 'react-native-onyx' ;
23import { areTransactionsEligibleForMerge , mergeTransactionRequest , setMergeTransactionKey , setupMergeTransactionData } from '@libs/actions/MergeTransaction' ;
34import CONST from '@src/CONST' ;
45import ONYXKEYS from '@src/ONYXKEYS' ;
5- import type { MergeTransaction as MergeTransactionType , Report , Transaction , TransactionViolation } from '@src/types/onyx' ;
6+ import type { MergeTransaction as MergeTransactionType , Report , Transaction , TransactionViolation , TransactionViolations } from '@src/types/onyx' ;
67import createRandomMergeTransaction from '../utils/collections/mergeTransaction' ;
78import { createExpenseReport } from '../utils/collections/reports' ;
89import createRandomTransaction , { createRandomDistanceRequestTransaction } from '../utils/collections/transaction' ;
@@ -26,6 +27,23 @@ function createMockViolations(): TransactionViolation[] {
2627 ] ;
2728}
2829
30+ // Helper function to create allTransactionViolations collection
31+ function createAllTransactionViolations (
32+ targetTransactionID : string ,
33+ sourceTransactionID : string ,
34+ targetViolations ?: TransactionViolation [ ] ,
35+ sourceViolations ?: TransactionViolation [ ] ,
36+ ) : OnyxCollection < TransactionViolations > {
37+ const allViolations : OnyxCollection < TransactionViolations > = { } ;
38+ if ( targetViolations ) {
39+ allViolations [ `${ ONYXKEYS . COLLECTION . TRANSACTION_VIOLATIONS } ${ targetTransactionID } ` ] = targetViolations ;
40+ }
41+ if ( sourceViolations ) {
42+ allViolations [ `${ ONYXKEYS . COLLECTION . TRANSACTION_VIOLATIONS } ${ sourceTransactionID } ` ] = sourceViolations ;
43+ }
44+ return allViolations ;
45+ }
46+
2947describe ( 'mergeTransactionRequest' , ( ) => {
3048 let mockFetch : MockFetch ;
3149
@@ -76,6 +94,32 @@ describe('mergeTransactionRequest', () => {
7694 } ;
7795 const mergeTransactionID = 'merge789' ;
7896
97+ // Sample violations for testing
98+ const targetViolations : TransactionViolation [ ] = [
99+ {
100+ type : CONST . VIOLATION_TYPES . VIOLATION ,
101+ name : CONST . VIOLATIONS . DUPLICATED_TRANSACTION ,
102+ showInReview : true ,
103+ } ,
104+ {
105+ type : CONST . VIOLATION_TYPES . VIOLATION ,
106+ name : CONST . VIOLATIONS . MISSING_TAG ,
107+ showInReview : true ,
108+ } ,
109+ ] ;
110+ const sourceViolations : TransactionViolation [ ] = [
111+ {
112+ type : CONST . VIOLATION_TYPES . VIOLATION ,
113+ name : CONST . VIOLATIONS . DUPLICATED_TRANSACTION ,
114+ showInReview : true ,
115+ } ,
116+ {
117+ type : CONST . VIOLATION_TYPES . VIOLATION ,
118+ name : CONST . VIOLATIONS . OVER_LIMIT ,
119+ showInReview : true ,
120+ } ,
121+ ] ;
122+
79123 // Set up initial state in Onyx
80124 await Onyx . set ( `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ targetTransaction . transactionID } ` , targetTransaction ) ;
81125 await Onyx . set ( `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ sourceTransaction . transactionID } ` , sourceTransaction ) ;
@@ -91,6 +135,7 @@ describe('mergeTransactionRequest', () => {
91135 mergeTransaction,
92136 targetTransaction,
93137 sourceTransaction,
138+ allTransactionViolations : createAllTransactionViolations ( targetTransaction . transactionID , sourceTransaction . transactionID , targetViolations , sourceViolations ) ,
94139 policy : undefined ,
95140 policyTags : undefined ,
96141 policyCategories : undefined ,
@@ -213,6 +258,7 @@ describe('mergeTransactionRequest', () => {
213258 mergeTransaction,
214259 targetTransaction,
215260 sourceTransaction,
261+ allTransactionViolations : createAllTransactionViolations ( targetTransaction . transactionID , sourceTransaction . transactionID , mockViolations , mockViolations ) ,
216262 policy : undefined ,
217263 policyTags : undefined ,
218264 policyCategories : undefined ,
@@ -310,6 +356,7 @@ describe('mergeTransactionRequest', () => {
310356 mergeTransaction,
311357 targetTransaction,
312358 sourceTransaction,
359+ allTransactionViolations : createAllTransactionViolations ( targetTransaction . transactionID , sourceTransaction . transactionID , mockViolations , mockViolations ) ,
313360 policy : undefined ,
314361 policyTags : undefined ,
315362 policyCategories : undefined ,
@@ -374,6 +421,32 @@ describe('mergeTransactionRequest', () => {
374421 } ;
375422 const mergeTransactionID = 'merge789' ;
376423
424+ // Sample violations for testing
425+ const targetViolations : TransactionViolation [ ] = [
426+ {
427+ type : CONST . VIOLATION_TYPES . VIOLATION ,
428+ name : CONST . VIOLATIONS . DUPLICATED_TRANSACTION ,
429+ showInReview : true ,
430+ } ,
431+ {
432+ type : CONST . VIOLATION_TYPES . VIOLATION ,
433+ name : CONST . VIOLATIONS . MISSING_COMMENT ,
434+ showInReview : true ,
435+ } ,
436+ ] ;
437+ const sourceViolations : TransactionViolation [ ] = [
438+ {
439+ type : CONST . VIOLATION_TYPES . VIOLATION ,
440+ name : CONST . VIOLATIONS . DUPLICATED_TRANSACTION ,
441+ showInReview : true ,
442+ } ,
443+ {
444+ type : CONST . VIOLATION_TYPES . VIOLATION ,
445+ name : CONST . VIOLATIONS . RECEIPT_REQUIRED ,
446+ showInReview : true ,
447+ } ,
448+ ] ;
449+
377450 // Set up initial state
378451 await Onyx . set ( `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ targetTransaction . transactionID } ` , targetTransaction ) ;
379452 await Onyx . set ( `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ sourceTransaction . transactionID } ` , sourceTransaction ) ;
@@ -389,6 +462,7 @@ describe('mergeTransactionRequest', () => {
389462 mergeTransaction,
390463 targetTransaction,
391464 sourceTransaction,
465+ allTransactionViolations : createAllTransactionViolations ( targetTransaction . transactionID , sourceTransaction . transactionID , targetViolations , sourceViolations ) ,
392466 policy : undefined ,
393467 policyTags : undefined ,
394468 policyCategories : undefined ,
0 commit comments