Skip to content

Commit f0bcac1

Browse files
Handle missing childManagerAccountID: fall back to IOU badge when oldestTaskAction is undefined
When childManagerAccountID is not populated (backend bug before opening report), oldestTaskAction is undefined. Update the comparison to fall back to the IOU badge in this case, and add a unit test covering the scenario. Co-authored-by: Aimane Chnaif <aimane-chnaif@users.noreply.github.com>
1 parent 5a3f4e9 commit f0bcac1

2 files changed

Lines changed: 50 additions & 1 deletion

File tree

src/libs/ReportUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4279,7 +4279,7 @@ function getReasonAndReportActionThatRequiresAttention(
42794279
.at(0);
42804280

42814281
// If there's a valid IOU action that is older than the task, use the IOU badge instead
4282-
if (hasValidIOUAction && iouReportActionToApproveOrPay?.created && oldestTaskAction?.created && iouReportActionToApproveOrPay.created < oldestTaskAction.created) {
4282+
if (hasValidIOUAction && iouReportActionToApproveOrPay?.created && (!oldestTaskAction || iouReportActionToApproveOrPay.created < oldestTaskAction.created)) {
42834283
return {
42844284
reason: CONST.REQUIRES_ATTENTION_REASONS.HAS_CHILD_REPORT_AWAITING_ACTION,
42854285
reportAction: iouReportActionToApproveOrPay,

tests/unit/ReportUtilsTest.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9399,6 +9399,55 @@ describe('ReportUtils', () => {
93999399
expect(result?.actionBadge).toBe(CONST.REPORT.ACTION_BADGE.TASK);
94009400
});
94019401

9402+
it('should return the IOU badge when task action has no childManagerAccountID (backend bug before opening report)', async () => {
9403+
const iouReportID = 'iou-report-for-missing-manager';
9404+
9405+
// Task action without childManagerAccountID — simulates the backend bug
9406+
// where childManagerAccountID is missing before the report is opened
9407+
const taskAction: ReportAction = {
9408+
reportActionID: 'task-action-no-manager',
9409+
actionName: CONST.REPORT.ACTIONS.TYPE.CARD_MISSING_ADDRESS,
9410+
childType: CONST.REPORT.TYPE.TASK,
9411+
childReportID: 'task-report-no-manager',
9412+
created: '2024-01-01 00:00:00',
9413+
originalMessage: {
9414+
assigneeAccountID: currentUserAccountID,
9415+
cardID: 99003,
9416+
},
9417+
};
9418+
9419+
const iouAction: ReportAction = {
9420+
reportActionID: 'iou-action-fallback',
9421+
actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW,
9422+
childType: CONST.REPORT.TYPE.IOU,
9423+
childReportID: iouReportID,
9424+
childManagerAccountID: currentUserAccountID,
9425+
created: '2024-01-02 00:00:00',
9426+
message: [{html: 'iou preview', text: 'iou preview', type: 'COMMENT'}],
9427+
};
9428+
9429+
const workspaceChat = {
9430+
...createPolicyExpenseChat(42003),
9431+
hasOutstandingChildTask: true,
9432+
hasOutstandingChildRequest: true,
9433+
iouReportID,
9434+
};
9435+
9436+
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${workspaceChat.reportID}`, workspaceChat);
9437+
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${workspaceChat.reportID}`, {
9438+
[taskAction.reportActionID]: taskAction,
9439+
[iouAction.reportActionID]: iouAction,
9440+
});
9441+
await waitForBatchedUpdates();
9442+
9443+
const {result: isReportArchived} = renderHook(() => useReportIsArchived(workspaceChat.reportID));
9444+
const result = getReasonAndReportActionThatRequiresAttention(workspaceChat, currentUserEmail, currentUserAccountID, undefined, isReportArchived.current);
9445+
9446+
// When oldestTaskAction is undefined (no childManagerAccountID), IOU badge should be returned
9447+
expect(result?.reason).toBe(CONST.REQUIRES_ATTENTION_REASONS.HAS_CHILD_REPORT_AWAITING_ACTION);
9448+
expect(result?.reportAction?.reportActionID).toBe('iou-action-fallback');
9449+
});
9450+
94029451
it('should return the earliest matching report action for invoice rooms with missing bank account', async () => {
94039452
const invoiceRoomID = '50000';
94049453
const olderChildReportID = '50001';

0 commit comments

Comments
 (0)