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