@@ -23,6 +23,9 @@ const PERSONAL_DETAILS = {
2323} ;
2424
2525const REPORT_ID = 1 ;
26+ const CHAT_REPORT_ID = 2 ;
27+ const POLICY_ID = 3 ;
28+ const INVOICE_SENDER_ACCOUNT_ID = 4 ;
2629
2730// This keeps the error "@rnmapbox/maps native code not available." from causing the tests to fail
2831jest . mock ( '@components/ConfirmedRoute.tsx' ) ;
@@ -124,23 +127,33 @@ describe('getPrimaryAction', () => {
124127 expect ( getReportPrimaryAction ( { report, chatReport, reportTransactions : [ transaction ] , violations : { } , policy : policy as Policy } ) ) . toBe ( '' ) ;
125128 } ) ;
126129
127- it ( 'should return PAY for submitted invoice report' , async ( ) => {
130+ it ( 'should return PAY for submitted invoice report if paid as personal ' , async ( ) => {
128131 const report = {
129132 reportID : REPORT_ID ,
130133 type : CONST . REPORT . TYPE . INVOICE ,
131- ownerAccountID : CURRENT_USER_ACCOUNT_ID ,
134+ ownerAccountID : INVOICE_SENDER_ACCOUNT_ID ,
135+ parentReportID : CHAT_REPORT_ID ,
132136 statusNum : CONST . REPORT . STATUS_NUM . SUBMITTED ,
133137 stateNum : CONST . REPORT . STATE_NUM . SUBMITTED ,
134138 } as unknown as Report ;
139+ const parentReport = {
140+ reportID : CHAT_REPORT_ID ,
141+ invoiceReceiver : {
142+ type : CONST . REPORT . INVOICE_RECEIVER_TYPE . INDIVIDUAL ,
143+ accountID : CURRENT_USER_ACCOUNT_ID ,
144+ } ,
145+ } as unknown as Report ;
135146 await Onyx . merge ( `${ ONYXKEYS . COLLECTION . REPORT } ${ REPORT_ID } ` , report ) ;
136- const policy = {
147+ await Onyx . merge ( `${ ONYXKEYS . COLLECTION . REPORT } ${ CHAT_REPORT_ID } ` , parentReport ) ;
148+ const policy = { } as Policy ;
149+ const invoiceReceiverPolicy = {
137150 role : CONST . POLICY . ROLE . ADMIN ,
138- } ;
151+ } as Policy ;
139152 const transaction = {
140153 reportID : `${ REPORT_ID } ` ,
141154 } as unknown as Transaction ;
142155
143- expect ( getReportPrimaryAction ( { report, chatReport, reportTransactions : [ transaction ] , violations : { } , policy : policy as Policy } ) ) . toBe ( CONST . REPORT . PRIMARY_ACTIONS . PAY ) ;
156+ expect ( getReportPrimaryAction ( { report, chatReport, reportTransactions : [ transaction ] , violations : { } , policy, invoiceReceiverPolicy } ) ) . toBe ( CONST . REPORT . PRIMARY_ACTIONS . PAY ) ;
144157 } ) ;
145158
146159 it ( 'should return PAY for expense report with payments enabled' , async ( ) => {
@@ -557,4 +570,40 @@ describe('getTransactionThreadPrimaryAction', () => {
557570 } ) ,
558571 ) . toBe ( '' ) ;
559572 } ) ;
573+
574+ it ( 'should return PAY for submitted invoice report if paid as business and the payer is the policy admin' , async ( ) => {
575+ const report = {
576+ reportID : REPORT_ID ,
577+ type : CONST . REPORT . TYPE . INVOICE ,
578+ ownerAccountID : INVOICE_SENDER_ACCOUNT_ID ,
579+ parentReportID : CHAT_REPORT_ID ,
580+ statusNum : CONST . REPORT . STATUS_NUM . SUBMITTED ,
581+ stateNum : CONST . REPORT . STATE_NUM . SUBMITTED ,
582+ } as unknown as Report ;
583+ const parentReport = {
584+ reportID : CHAT_REPORT_ID ,
585+ invoiceReceiver : {
586+ type : CONST . REPORT . INVOICE_RECEIVER_TYPE . BUSINESS ,
587+ policyID : POLICY_ID ,
588+ } ,
589+ } as unknown as Report ;
590+ await Onyx . merge ( `${ ONYXKEYS . COLLECTION . REPORT } ${ REPORT_ID } ` , report ) ;
591+ await Onyx . merge ( `${ ONYXKEYS . COLLECTION . REPORT } ${ CHAT_REPORT_ID } ` , parentReport ) ;
592+ const invoiceReceiverPolicy = {
593+ role : CONST . POLICY . ROLE . ADMIN ,
594+ } ;
595+ const transaction = {
596+ reportID : `${ REPORT_ID } ` ,
597+ } as unknown as Transaction ;
598+ expect (
599+ getReportPrimaryAction ( {
600+ report,
601+ chatReport,
602+ reportTransactions : [ transaction ] ,
603+ violations : { } ,
604+ policy : { } as Policy ,
605+ invoiceReceiverPolicy : invoiceReceiverPolicy as Policy ,
606+ } ) ,
607+ ) . toBe ( CONST . REPORT . PRIMARY_ACTIONS . PAY ) ;
608+ } ) ;
560609} ) ;
0 commit comments