@@ -4,6 +4,7 @@ import type {OnyxCollection, OnyxEntry, OnyxInputValue} from 'react-native-onyx'
4
4
import Onyx from 'react-native-onyx' ;
5
5
import {
6
6
cancelPayment ,
7
+ canIOUBePaid ,
7
8
deleteMoneyRequest ,
8
9
payMoneyRequest ,
9
10
putOnHold ,
@@ -19,7 +20,7 @@ import {
19
20
updateMoneyRequestAmountAndCurrency ,
20
21
updateMoneyRequestCategory ,
21
22
} from '@libs/actions/IOU' ;
22
- import { createWorkspace , generatePolicyID , setWorkspaceApprovalMode } from '@libs/actions/Policy/Policy' ;
23
+ import { createWorkspace , deleteWorkspace , generatePolicyID , setWorkspaceApprovalMode } from '@libs/actions/Policy/Policy' ;
23
24
import { addComment , deleteReport , notifyNewAction , openReport } from '@libs/actions/Report' ;
24
25
import { clearAllRelatedReportActionErrors } from '@libs/actions/ReportActions' ;
25
26
import { subscribeToUserEvents } from '@libs/actions/User' ;
@@ -3484,6 +3485,7 @@ describe('actions/IOU', () => {
3484
3485
const merchant = 'NASDAQ' ;
3485
3486
let expenseReport : OnyxEntry < Report > ;
3486
3487
let chatReport : OnyxEntry < Report > ;
3488
+ let policy : OnyxEntry < Policy > ;
3487
3489
return waitForBatchedUpdates ( )
3488
3490
. then ( ( ) => {
3489
3491
createWorkspace ( CARLOS_EMAIL , true , "Carlos's Workspace" ) ;
@@ -3498,7 +3500,6 @@ describe('actions/IOU', () => {
3498
3500
callback : ( allReports ) => {
3499
3501
Onyx . disconnect ( connection ) ;
3500
3502
chatReport = Object . values ( allReports ?? { } ) . find ( ( report ) => report ?. chatType === CONST . REPORT . CHAT_TYPE . POLICY_EXPENSE_CHAT ) ;
3501
-
3502
3503
resolve ( ) ;
3503
3504
} ,
3504
3505
} ) ;
@@ -3525,6 +3526,21 @@ describe('actions/IOU', () => {
3525
3526
}
3526
3527
return waitForBatchedUpdates ( ) ;
3527
3528
} )
3529
+ . then (
3530
+ ( ) =>
3531
+ new Promise < void > ( ( resolve ) => {
3532
+ const connection = Onyx . connect ( {
3533
+ key : ONYXKEYS . COLLECTION . POLICY ,
3534
+ waitForCollectionCallback : true ,
3535
+ callback : ( allPolicies ) => {
3536
+ Onyx . disconnect ( connection ) ;
3537
+ policy = Object . values ( allPolicies ?? { } ) . find ( ( p ) : p is OnyxEntry < Policy > => p ?. name === "Carlos's Workspace" ) ;
3538
+ expect ( policy ) . toBeTruthy ( ) ;
3539
+ resolve ( ) ;
3540
+ } ,
3541
+ } ) ;
3542
+ } ) ,
3543
+ )
3528
3544
. then (
3529
3545
( ) =>
3530
3546
new Promise < void > ( ( resolve ) => {
@@ -3534,6 +3550,10 @@ describe('actions/IOU', () => {
3534
3550
callback : ( allReports ) => {
3535
3551
Onyx . disconnect ( connection ) ;
3536
3552
expenseReport = Object . values ( allReports ?? { } ) . find ( ( report ) => report ?. type === CONST . REPORT . TYPE . EXPENSE ) ;
3553
+
3554
+ expect ( canIOUBePaid ( expenseReport , chatReport , policy , [ ] , true ) ) . toBe ( true ) ;
3555
+ expect ( canIOUBePaid ( expenseReport , chatReport , policy , [ ] , false ) ) . toBe ( false ) ;
3556
+
3537
3557
Onyx . merge ( `report_${ expenseReport ?. reportID } ` , {
3538
3558
statusNum : 0 ,
3539
3559
stateNum : 0 ,
@@ -3553,6 +3573,9 @@ describe('actions/IOU', () => {
3553
3573
Onyx . disconnect ( connection ) ;
3554
3574
expenseReport = Object . values ( allReports ?? { } ) . find ( ( report ) => report ?. type === CONST . REPORT . TYPE . EXPENSE ) ;
3555
3575
3576
+ expect ( canIOUBePaid ( expenseReport , chatReport , policy , [ ] , true ) ) . toBe ( false ) ;
3577
+ expect ( canIOUBePaid ( expenseReport , chatReport , policy , [ ] , false ) ) . toBe ( false ) ;
3578
+
3556
3579
// Verify report is a draft
3557
3580
expect ( expenseReport ?. stateNum ) . toBe ( 0 ) ;
3558
3581
expect ( expenseReport ?. statusNum ) . toBe ( 0 ) ;
@@ -3577,9 +3600,37 @@ describe('actions/IOU', () => {
3577
3600
Onyx . disconnect ( connection ) ;
3578
3601
expenseReport = Object . values ( allReports ?? { } ) . find ( ( report ) => report ?. type === CONST . REPORT . TYPE . EXPENSE ) ;
3579
3602
3603
+ expect ( canIOUBePaid ( expenseReport , chatReport , policy , [ ] , false ) ) . toBe ( false ) ;
3604
+ expect ( canIOUBePaid ( expenseReport , chatReport , policy , [ ] , true ) ) . toBe ( true ) ;
3605
+
3580
3606
// Report is closed since the default policy settings is Submit and Close
3581
3607
expect ( expenseReport ?. stateNum ) . toBe ( 2 ) ;
3582
3608
expect ( expenseReport ?. statusNum ) . toBe ( 2 ) ;
3609
+ resolve ( ) ;
3610
+ } ,
3611
+ } ) ;
3612
+ } ) ,
3613
+ )
3614
+ . then ( ( ) => {
3615
+ if ( policy ) {
3616
+ deleteWorkspace ( policy . id , policy . name ) ;
3617
+ }
3618
+ return waitForBatchedUpdates ( ) ;
3619
+ } )
3620
+ . then (
3621
+ ( ) =>
3622
+ new Promise < void > ( ( resolve ) => {
3623
+ const connection = Onyx . connect ( {
3624
+ key : ONYXKEYS . COLLECTION . POLICY ,
3625
+ waitForCollectionCallback : true ,
3626
+ callback : ( allPolicies ) => {
3627
+ Onyx . disconnect ( connection ) ;
3628
+ policy = Object . values ( allPolicies ?? { } ) . find ( ( p ) : p is OnyxEntry < Policy > => p ?. name === "Carlos's Workspace" ) ;
3629
+
3630
+ expect ( policy ) . toBeTruthy ( ) ;
3631
+ expect ( canIOUBePaid ( expenseReport , chatReport , policy , [ ] , false ) ) . toBe ( false ) ;
3632
+ expect ( canIOUBePaid ( expenseReport , chatReport , policy , [ ] , true ) ) . toBe ( true ) ;
3633
+
3583
3634
resolve ( ) ;
3584
3635
} ,
3585
3636
} ) ;
@@ -3592,6 +3643,7 @@ describe('actions/IOU', () => {
3592
3643
const merchant = 'NASDAQ' ;
3593
3644
let expenseReport : OnyxEntry < Report > ;
3594
3645
let chatReport : OnyxEntry < Report > ;
3646
+ let policy : OnyxEntry < Policy > ;
3595
3647
return waitForBatchedUpdates ( )
3596
3648
. then ( ( ) => {
3597
3649
createWorkspace ( CARLOS_EMAIL , true , "Carlos's Workspace" ) ;
@@ -3606,7 +3658,6 @@ describe('actions/IOU', () => {
3606
3658
callback : ( allReports ) => {
3607
3659
Onyx . disconnect ( connection ) ;
3608
3660
chatReport = Object . values ( allReports ?? { } ) . find ( ( report ) => report ?. chatType === CONST . REPORT . CHAT_TYPE . POLICY_EXPENSE_CHAT ) ;
3609
-
3610
3661
resolve ( ) ;
3611
3662
} ,
3612
3663
} ) ;
@@ -3633,6 +3684,21 @@ describe('actions/IOU', () => {
3633
3684
}
3634
3685
return waitForBatchedUpdates ( ) ;
3635
3686
} )
3687
+ . then (
3688
+ ( ) =>
3689
+ new Promise < void > ( ( resolve ) => {
3690
+ const connection = Onyx . connect ( {
3691
+ key : ONYXKEYS . COLLECTION . POLICY ,
3692
+ waitForCollectionCallback : true ,
3693
+ callback : ( allPolicies ) => {
3694
+ Onyx . disconnect ( connection ) ;
3695
+ policy = Object . values ( allPolicies ?? { } ) . find ( ( p ) : p is OnyxEntry < Policy > => p ?. name === "Carlos's Workspace" ) ;
3696
+ expect ( policy ) . toBeTruthy ( ) ;
3697
+ resolve ( ) ;
3698
+ } ,
3699
+ } ) ;
3700
+ } ) ,
3701
+ )
3636
3702
. then (
3637
3703
( ) =>
3638
3704
new Promise < void > ( ( resolve ) => {
@@ -3642,6 +3708,10 @@ describe('actions/IOU', () => {
3642
3708
callback : ( allReports ) => {
3643
3709
Onyx . disconnect ( connection ) ;
3644
3710
expenseReport = Object . values ( allReports ?? { } ) . find ( ( report ) => report ?. type === CONST . REPORT . TYPE . EXPENSE ) ;
3711
+
3712
+ expect ( canIOUBePaid ( expenseReport , chatReport , policy , [ ] , false ) ) . toBe ( false ) ;
3713
+ expect ( canIOUBePaid ( expenseReport , chatReport , policy , [ ] , true ) ) . toBe ( true ) ;
3714
+
3645
3715
Onyx . merge ( `report_${ expenseReport ?. reportID } ` , {
3646
3716
statusNum : 0 ,
3647
3717
stateNum : 0 ,
@@ -3686,6 +3756,9 @@ describe('actions/IOU', () => {
3686
3756
Onyx . disconnect ( connection ) ;
3687
3757
expenseReport = Object . values ( allReports ?? { } ) . find ( ( report ) => report ?. type === CONST . REPORT . TYPE . EXPENSE ) ;
3688
3758
3759
+ expect ( canIOUBePaid ( expenseReport , chatReport , policy , [ ] , false ) ) . toBe ( false ) ;
3760
+ expect ( canIOUBePaid ( expenseReport , chatReport , policy , [ ] , true ) ) . toBe ( false ) ;
3761
+
3689
3762
// Report was submitted with some fail
3690
3763
expect ( expenseReport ?. stateNum ) . toBe ( 0 ) ;
3691
3764
expect ( expenseReport ?. statusNum ) . toBe ( 0 ) ;
0 commit comments