@@ -3506,6 +3506,96 @@ describe('actions/IOU/ReportWorkflow', () => {
35063506 expect ( result . actionBadge ) . toBeUndefined ( ) ;
35073507 } ) ;
35083508
3509+ it ( 'should return the oldest matching report action when multiple actions have badges' , async ( ) => {
3510+ const chatReportID = '500' ;
3511+ const olderIouReportID = '501' ;
3512+ const newerIouReportID = '502' ;
3513+ const policyID = '503' ;
3514+
3515+ const fakePolicy : Policy = {
3516+ ...createRandomPolicy ( Number ( policyID ) ) ,
3517+ id : policyID ,
3518+ type : CONST . POLICY . TYPE . TEAM ,
3519+ approvalMode : CONST . POLICY . APPROVAL_MODE . BASIC ,
3520+ } ;
3521+
3522+ const fakeChatReport : Report = {
3523+ ...createRandomReport ( Number ( chatReportID ) , CONST . REPORT . CHAT_TYPE . POLICY_EXPENSE_CHAT ) ,
3524+ reportID : chatReportID ,
3525+ policyID,
3526+ } ;
3527+
3528+ // Two submitted expense reports — both will produce APPROVE badges
3529+ const olderIouReport : Report = {
3530+ ...createRandomReport ( Number ( olderIouReportID ) , CONST . REPORT . CHAT_TYPE . POLICY_EXPENSE_CHAT ) ,
3531+ reportID : olderIouReportID ,
3532+ type : CONST . REPORT . TYPE . EXPENSE ,
3533+ policyID,
3534+ stateNum : CONST . REPORT . STATE_NUM . SUBMITTED ,
3535+ statusNum : CONST . REPORT . STATUS_NUM . SUBMITTED ,
3536+ managerID : RORY_ACCOUNT_ID ,
3537+ } ;
3538+
3539+ const newerIouReport : Report = {
3540+ ...createRandomReport ( Number ( newerIouReportID ) , CONST . REPORT . CHAT_TYPE . POLICY_EXPENSE_CHAT ) ,
3541+ reportID : newerIouReportID ,
3542+ type : CONST . REPORT . TYPE . EXPENSE ,
3543+ policyID,
3544+ stateNum : CONST . REPORT . STATE_NUM . SUBMITTED ,
3545+ statusNum : CONST . REPORT . STATUS_NUM . SUBMITTED ,
3546+ managerID : RORY_ACCOUNT_ID ,
3547+ } ;
3548+
3549+ const olderTransaction : Transaction = {
3550+ ...createRandomTransaction ( 0 ) ,
3551+ reportID : olderIouReportID ,
3552+ amount : 100 ,
3553+ status : CONST . TRANSACTION . STATUS . POSTED ,
3554+ bank : '' ,
3555+ } ;
3556+
3557+ const newerTransaction : Transaction = {
3558+ ...createRandomTransaction ( 1 ) ,
3559+ reportID : newerIouReportID ,
3560+ amount : 200 ,
3561+ status : CONST . TRANSACTION . STATUS . POSTED ,
3562+ bank : '' ,
3563+ } ;
3564+
3565+ await Onyx . set ( `${ ONYXKEYS . COLLECTION . POLICY } ${ policyID } ` , fakePolicy ) ;
3566+ await Onyx . set ( `${ ONYXKEYS . COLLECTION . REPORT } ${ chatReportID } ` , fakeChatReport ) ;
3567+ await Onyx . set ( `${ ONYXKEYS . COLLECTION . REPORT } ${ olderIouReportID } ` , olderIouReport ) ;
3568+ await Onyx . set ( `${ ONYXKEYS . COLLECTION . REPORT } ${ newerIouReportID } ` , newerIouReport ) ;
3569+ await Onyx . set ( `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ olderTransaction . transactionID } ` , olderTransaction ) ;
3570+ await Onyx . set ( `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ newerTransaction . transactionID } ` , newerTransaction ) ;
3571+
3572+ const olderReportPreview = {
3573+ reportActionID : 'older-preview' ,
3574+ actionName : CONST . REPORT . ACTIONS . TYPE . REPORT_PREVIEW ,
3575+ created : '2024-08-08 18:00:00.000' ,
3576+ childReportID : olderIouReportID ,
3577+ message : [ { type : 'TEXT' , text : 'Older report preview' } ] ,
3578+ } ;
3579+
3580+ const newerReportPreview = {
3581+ reportActionID : 'newer-preview' ,
3582+ actionName : CONST . REPORT . ACTIONS . TYPE . REPORT_PREVIEW ,
3583+ created : '2024-08-08 20:00:00.000' ,
3584+ childReportID : newerIouReportID ,
3585+ message : [ { type : 'TEXT' , text : 'Newer report preview' } ] ,
3586+ } ;
3587+
3588+ await Onyx . set ( `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ chatReportID } ` , {
3589+ [ newerReportPreview . reportActionID ] : newerReportPreview ,
3590+ [ olderReportPreview . reportActionID ] : olderReportPreview ,
3591+ } ) ;
3592+ await waitForBatchedUpdates ( ) ;
3593+
3594+ const result = getIOUReportActionWithBadge ( fakeChatReport , fakePolicy , { } , undefined , RORY_EMAIL , RORY_ACCOUNT_ID ) ;
3595+ expect ( result . reportAction ) . toMatchObject ( olderReportPreview ) ;
3596+ expect ( result . actionBadge ) . toBe ( CONST . REPORT . ACTION_BADGE . APPROVE ) ;
3597+ } ) ;
3598+
35093599 it ( 'should return undefined actionBadge when report is settled' , async ( ) => {
35103600 const chatReportID = '400' ;
35113601 const iouReportID = '401' ;
0 commit comments