@@ -9299,6 +9299,81 @@ describe('ReportUtils', () => {
92999299 // Should only return the task where childManagerAccountID matches the current user
93009300 expect(result?.reportAction?.reportActionID).toBe('current-user-task');
93019301 });
9302+
9303+ it('should return the earliest matching report action for invoice rooms with missing bank account', async () => {
9304+ const invoiceRoomID = '50000';
9305+ const olderChildReportID = '50001';
9306+ const newerChildReportID = '50002';
9307+ const policyID = '50003';
9308+
9309+ const invoiceRoom: Report = {
9310+ ...createInvoiceRoom(Number(invoiceRoomID)),
9311+ reportID: invoiceRoomID,
9312+ policyID,
9313+ };
9314+
9315+ // Child invoice reports: owned by current user, no bank account on policy, and settled
9316+ // Note: hasMissingInvoiceBankAccount requires isSettled=true, but the outer condition
9317+ // requires !isSettled, making this path currently unreachable. This test documents the
9318+ // current behavior and will catch regressions if the conditions are corrected.
9319+ const olderChildReport: Report = {
9320+ ...createRandomReport(Number(olderChildReportID)),
9321+ reportID: olderChildReportID,
9322+ type: CONST.REPORT.TYPE.INVOICE,
9323+ policyID,
9324+ ownerAccountID: currentUserAccountID,
9325+ statusNum: CONST.REPORT.STATUS_NUM.REIMBURSED,
9326+ };
9327+
9328+ const newerChildReport: Report = {
9329+ ...createRandomReport(Number(newerChildReportID)),
9330+ reportID: newerChildReportID,
9331+ type: CONST.REPORT.TYPE.INVOICE,
9332+ policyID,
9333+ ownerAccountID: currentUserAccountID,
9334+ statusNum: CONST.REPORT.STATUS_NUM.REIMBURSED,
9335+ };
9336+
9337+ const fakePolicy: Policy = {
9338+ ...createRandomPolicy(Number(policyID)),
9339+ id: policyID,
9340+ };
9341+
9342+ await Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, fakePolicy);
9343+ await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${invoiceRoomID}`, invoiceRoom);
9344+ await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${olderChildReportID}`, olderChildReport);
9345+ await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${newerChildReportID}`, newerChildReport);
9346+
9347+ const olderReportPreview: ReportAction = {
9348+ ...createRandomReportAction(Number(olderChildReportID)),
9349+ reportActionID: 'older-invoice-preview',
9350+ actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW,
9351+ created: '2024-01-01 10:00:00.000',
9352+ childReportID: olderChildReportID,
9353+ };
9354+
9355+ const newerReportPreview: ReportAction = {
9356+ ...createRandomReportAction(Number(newerChildReportID)),
9357+ reportActionID: 'newer-invoice-preview',
9358+ actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW,
9359+ created: '2024-01-02 10:00:00.000',
9360+ childReportID: newerChildReportID,
9361+ };
9362+
9363+ await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${invoiceRoomID}`, {
9364+ [newerReportPreview.reportActionID]: newerReportPreview,
9365+ [olderReportPreview.reportActionID]: olderReportPreview,
9366+ });
9367+ await waitForBatchedUpdates();
9368+
9369+ const {result: isReportArchived} = renderHook(() => useReportIsArchived(invoiceRoomID));
9370+ const result = getReasonAndReportActionThatRequiresAttention(invoiceRoom, currentUserEmail, currentUserAccountID, undefined, isReportArchived.current);
9371+
9372+ // Currently returns null because hasMissingInvoiceBankAccount requires isSettled=true
9373+ // but the outer condition filters out settled reports with isSettled check.
9374+ // When this contradiction is resolved, the result should return the older report action.
9375+ expect(result).toBe(null);
9376+ });
93029377 });
93039378
93049379 describe('canEditReportDescription', () => {
0 commit comments