@@ -14,6 +14,7 @@ import {
1414 canUnapproveIOU ,
1515 createDistanceRequest ,
1616 deleteMoneyRequest ,
17+ getIOUReportActionToApproveOrPay ,
1718 initMoneyRequest ,
1819 initSplitExpense ,
1920 payMoneyRequest ,
@@ -6401,4 +6402,86 @@ describe('actions/IOU', () => {
64016402 } ) ;
64026403 } ) ;
64036404 } ) ;
6405+
6406+ describe ( 'getIOUReportActionToApproveOrPay' , ( ) => {
6407+ it ( 'should exclude deleted actions' , async ( ) => {
6408+ const reportID = '1' ;
6409+ const policyID = '2' ;
6410+ const fakePolicy : Policy = {
6411+ ...createRandomPolicy ( Number ( policyID ) ) ,
6412+ approvalMode : CONST . POLICY . APPROVAL_MODE . BASIC ,
6413+ } ;
6414+
6415+ const fakeReport : Report = {
6416+ ...createRandomReport ( Number ( reportID ) ) ,
6417+ type : CONST . REPORT . TYPE . EXPENSE ,
6418+ policyID,
6419+ stateNum : CONST . REPORT . STATE_NUM . SUBMITTED ,
6420+ statusNum : CONST . REPORT . STATUS_NUM . SUBMITTED ,
6421+ managerID : RORY_ACCOUNT_ID ,
6422+ chatType : 'policyExpenseChat' ,
6423+ } ;
6424+ const fakeTransaction1 : Transaction = {
6425+ ...createRandomTransaction ( 0 ) ,
6426+ reportID,
6427+ bank : CONST . EXPENSIFY_CARD . BANK ,
6428+ status : CONST . TRANSACTION . STATUS . PENDING ,
6429+ } ;
6430+ const fakeTransaction2 : Transaction = {
6431+ ...createRandomTransaction ( 1 ) ,
6432+ reportID,
6433+ amount : 0 ,
6434+ receipt : {
6435+ source : 'test' ,
6436+ state : CONST . IOU . RECEIPT_STATE . SCAN_FAILED ,
6437+ } ,
6438+ merchant : CONST . TRANSACTION . PARTIAL_TRANSACTION_MERCHANT ,
6439+ modifiedMerchant : undefined ,
6440+ } ;
6441+ const fakeTransaction3 : Transaction = {
6442+ ...createRandomTransaction ( 2 ) ,
6443+ reportID,
6444+ amount : 100 ,
6445+ } ;
6446+
6447+ await Onyx . set ( `${ ONYXKEYS . COLLECTION . REPORT } ${ fakeReport . reportID } ` , fakeReport ) ;
6448+ await Onyx . set ( `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ fakeTransaction1 . transactionID } ` , fakeTransaction1 ) ;
6449+ await Onyx . set ( `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ fakeTransaction2 . transactionID } ` , fakeTransaction2 ) ;
6450+ await Onyx . set ( `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ fakeTransaction3 . transactionID } ` , fakeTransaction3 ) ;
6451+ await waitForBatchedUpdates ( ) ;
6452+
6453+ expect ( canApproveIOU ( fakeReport , fakePolicy ) ) . toBeTruthy ( ) ;
6454+
6455+ await Onyx . set ( `${ ONYXKEYS . COLLECTION . POLICY } ${ policyID } ` , fakePolicy ) ;
6456+
6457+ const deletedReportAction = {
6458+ reportActionID : '0' ,
6459+ actionName : CONST . REPORT . ACTIONS . TYPE . REPORT_PREVIEW ,
6460+ created : '2024-08-08 18:70:44.171' ,
6461+ childReportID : '1' ,
6462+ } ;
6463+
6464+ const MOCK_REPORT_ACTIONS : ReportActions = {
6465+ // eslint-disable-next-line @typescript-eslint/naming-convention
6466+ '0' : deletedReportAction ,
6467+ // eslint-disable-next-line @typescript-eslint/naming-convention
6468+ '1' : {
6469+ reportActionID : '1' ,
6470+ actionName : CONST . REPORT . ACTIONS . TYPE . REPORT_PREVIEW ,
6471+ created : '2024-08-08 19:70:44.171' ,
6472+ childReportID : '1' ,
6473+ message : [
6474+ {
6475+ type : 'TEXT' ,
6476+ text : 'Hello world!' ,
6477+ } ,
6478+ ] ,
6479+ } ,
6480+ } ;
6481+
6482+ await Onyx . set ( `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ fakeReport . reportID } ` , MOCK_REPORT_ACTIONS ) ;
6483+
6484+ expect ( getIOUReportActionToApproveOrPay ( fakeReport , '3' ) ) . toMatchObject ( MOCK_REPORT_ACTIONS [ '1' ] ) ;
6485+ } ) ;
6486+ } ) ;
64046487} ) ;
0 commit comments