@@ -9426,6 +9426,153 @@ describe('ReportUtils', () => {
94269426 expect(result?.reportAction?.reportActionID).toBe('current-user-task');
94279427 });
94289428
9429+ it('should return the IOU badge when the IOU action is older than the task action', async () => {
9430+ const iouReportID = 'iou-report-for-priority';
9431+
9432+ const taskAction: ReportAction = {
9433+ reportActionID: 'task-action-newer',
9434+ actionName: CONST.REPORT.ACTIONS.TYPE.CARD_MISSING_ADDRESS,
9435+ childType: CONST.REPORT.TYPE.TASK,
9436+ childReportID: 'task-report-priority',
9437+ childManagerAccountID: currentUserAccountID,
9438+ created: '2024-01-02 00:00:00',
9439+ originalMessage: {
9440+ assigneeAccountID: currentUserAccountID,
9441+ cardID: 99001,
9442+ },
9443+ };
9444+
9445+ const iouAction: ReportAction = {
9446+ reportActionID: 'iou-action-older',
9447+ actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW,
9448+ childType: CONST.REPORT.TYPE.IOU,
9449+ childReportID: iouReportID,
9450+ childManagerAccountID: currentUserAccountID,
9451+ created: '2024-01-01 00:00:00',
9452+ message: [{html: 'iou preview', text: 'iou preview', type: 'COMMENT'}],
9453+ };
9454+
9455+ const workspaceChat = {
9456+ ...createPolicyExpenseChat(42001),
9457+ hasOutstandingChildTask: true,
9458+ hasOutstandingChildRequest: true,
9459+ iouReportID,
9460+ };
9461+
9462+ await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${workspaceChat.reportID}`, workspaceChat);
9463+ await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${workspaceChat.reportID}`, {
9464+ [taskAction.reportActionID]: taskAction,
9465+ [iouAction.reportActionID]: iouAction,
9466+ });
9467+ await waitForBatchedUpdates();
9468+
9469+ const {result: isReportArchived} = renderHook(() => useReportIsArchived(workspaceChat.reportID));
9470+ const result = getReasonAndReportActionThatRequiresAttention(workspaceChat, currentUserEmail, currentUserAccountID, undefined, isReportArchived.current);
9471+
9472+ // The IOU action is older, so its badge should take priority over the task badge
9473+ expect(result?.reason).toBe(CONST.REQUIRES_ATTENTION_REASONS.HAS_CHILD_REPORT_AWAITING_ACTION);
9474+ expect(result?.reportAction?.reportActionID).toBe('iou-action-older');
9475+ expect(result?.actionBadge).toBe(CONST.REPORT.ACTION_BADGE.PAY);
9476+ });
9477+
9478+ it('should return the Task badge when the task action is older than the IOU action', async () => {
9479+ const iouReportID = 'iou-report-for-priority-2';
9480+
9481+ const taskAction: ReportAction = {
9482+ reportActionID: 'task-action-older',
9483+ actionName: CONST.REPORT.ACTIONS.TYPE.CARD_MISSING_ADDRESS,
9484+ childType: CONST.REPORT.TYPE.TASK,
9485+ childReportID: 'task-report-priority-2',
9486+ childManagerAccountID: currentUserAccountID,
9487+ created: '2024-01-01 00:00:00',
9488+ originalMessage: {
9489+ assigneeAccountID: currentUserAccountID,
9490+ cardID: 99002,
9491+ },
9492+ };
9493+
9494+ const iouAction: ReportAction = {
9495+ reportActionID: 'iou-action-newer',
9496+ actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW,
9497+ childType: CONST.REPORT.TYPE.IOU,
9498+ childReportID: iouReportID,
9499+ childManagerAccountID: currentUserAccountID,
9500+ created: '2024-01-02 00:00:00',
9501+ message: [{html: 'iou preview', text: 'iou preview', type: 'COMMENT'}],
9502+ };
9503+
9504+ const workspaceChat = {
9505+ ...createPolicyExpenseChat(42002),
9506+ hasOutstandingChildTask: true,
9507+ hasOutstandingChildRequest: true,
9508+ iouReportID,
9509+ };
9510+
9511+ await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${workspaceChat.reportID}`, workspaceChat);
9512+ await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${workspaceChat.reportID}`, {
9513+ [taskAction.reportActionID]: taskAction,
9514+ [iouAction.reportActionID]: iouAction,
9515+ });
9516+ await waitForBatchedUpdates();
9517+
9518+ const {result: isReportArchived} = renderHook(() => useReportIsArchived(workspaceChat.reportID));
9519+ const result = getReasonAndReportActionThatRequiresAttention(workspaceChat, currentUserEmail, currentUserAccountID, undefined, isReportArchived.current);
9520+
9521+ // The task action is older, so the task badge should take priority
9522+ expect(result?.reason).toBe(CONST.REQUIRES_ATTENTION_REASONS.IS_WAITING_FOR_ASSIGNEE_TO_COMPLETE_ACTION);
9523+ expect(result?.reportAction?.reportActionID).toBe('task-action-older');
9524+ expect(result?.actionBadge).toBe(CONST.REPORT.ACTION_BADGE.TASK);
9525+ });
9526+
9527+ it('should return the IOU badge when task action has no childManagerAccountID (backend bug before opening report)', async () => {
9528+ const iouReportID = 'iou-report-for-missing-manager';
9529+
9530+ // Task action without childManagerAccountID — simulates the backend bug
9531+ // where childManagerAccountID is missing before the report is opened
9532+ const taskAction: ReportAction = {
9533+ reportActionID: 'task-action-no-manager',
9534+ actionName: CONST.REPORT.ACTIONS.TYPE.CARD_MISSING_ADDRESS,
9535+ childType: CONST.REPORT.TYPE.TASK,
9536+ childReportID: 'task-report-no-manager',
9537+ created: '2024-01-01 00:00:00',
9538+ originalMessage: {
9539+ assigneeAccountID: currentUserAccountID,
9540+ cardID: 99003,
9541+ },
9542+ };
9543+
9544+ const iouAction: ReportAction = {
9545+ reportActionID: 'iou-action-fallback',
9546+ actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW,
9547+ childType: CONST.REPORT.TYPE.IOU,
9548+ childReportID: iouReportID,
9549+ childManagerAccountID: currentUserAccountID,
9550+ created: '2024-01-02 00:00:00',
9551+ message: [{html: 'iou preview', text: 'iou preview', type: 'COMMENT'}],
9552+ };
9553+
9554+ const workspaceChat = {
9555+ ...createPolicyExpenseChat(42003),
9556+ hasOutstandingChildTask: true,
9557+ hasOutstandingChildRequest: true,
9558+ iouReportID,
9559+ };
9560+
9561+ await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${workspaceChat.reportID}`, workspaceChat);
9562+ await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${workspaceChat.reportID}`, {
9563+ [taskAction.reportActionID]: taskAction,
9564+ [iouAction.reportActionID]: iouAction,
9565+ });
9566+ await waitForBatchedUpdates();
9567+
9568+ const {result: isReportArchived} = renderHook(() => useReportIsArchived(workspaceChat.reportID));
9569+ const result = getReasonAndReportActionThatRequiresAttention(workspaceChat, currentUserEmail, currentUserAccountID, undefined, isReportArchived.current);
9570+
9571+ // When oldestTaskAction is undefined (no childManagerAccountID), IOU badge should be returned
9572+ expect(result?.reason).toBe(CONST.REQUIRES_ATTENTION_REASONS.HAS_CHILD_REPORT_AWAITING_ACTION);
9573+ expect(result?.reportAction?.reportActionID).toBe('iou-action-fallback');
9574+ });
9575+
94299576 it('should return the earliest matching report action for invoice rooms with missing bank account', async () => {
94309577 const invoiceRoomID = '50000';
94319578 const olderChildReportID = '50001';
0 commit comments