From cb793c02b1c164742df621be6b80ea86c764f2d1 Mon Sep 17 00:00:00 2001 From: ShridharGoel <35566748+ShridharGoel@users.noreply.github.com> Date: Tue, 4 Nov 2025 20:21:24 +0530 Subject: [PATCH 1/4] Add test for green brick road when waiting for bank account --- tests/unit/ReportUtilsTest.ts | 56 +++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 360c7ae26265..f289dcb5fe83 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -84,6 +84,7 @@ import { parseReportRouteParams, populateOptimisticReportFormula, prepareOnboardingOnyxData, + reasonForReportToBeInOptionList, requiresAttentionFromCurrentUser, requiresManualSubmission, shouldBlockSubmitDueToStrictPolicyRules, @@ -8766,4 +8767,59 @@ describe('ReportUtils', () => { expect(getPolicyIDsWithEmptyReportsForAccount(reports, accountID, transactions)).toEqual({}); }); }); + + it('should surface a GBR when reimbursement is queued and waiting on the payee bank account', async () => { + const adminAccountID = 42; + const expenseReportID = 'BRICK_ROAD_WAITING_ON_BANK'; + const chatReport: Report = { + ...LHNTestUtils.getFakeReport([currentUserAccountID, adminAccountID]), + hasOutstandingChildRequest: true, + iouReportID: expenseReportID, + }; + const expenseReport: Report = { + ...LHNTestUtils.getFakeReport([currentUserAccountID, adminAccountID]), + reportID: expenseReportID, + chatReportID: chatReport.reportID, + type: CONST.REPORT.TYPE.EXPENSE, + ownerAccountID: currentUserAccountID, + managerID: adminAccountID, + currency: CONST.CURRENCY.USD, + total: 10000, + stateNum: CONST.REPORT.STATE_NUM.APPROVED, + statusNum: CONST.REPORT.STATUS_NUM.APPROVED, + isWaitingOnBankAccount: true, + }; + const reimbursementQueuedAction: ReportAction = { + ...LHNTestUtils.getFakeReportAction(), + actionName: CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENT_QUEUED, + childReportID: expenseReportID, + originalMessage: { + paymentType: CONST.IOU.PAYMENT_TYPE.VBBA, + }, + }; + + await Onyx.merge(ONYXKEYS.SESSION, {accountID: currentUserAccountID, email: currentUserEmail}); + await Onyx.multiSet({ + [`${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`]: chatReport, + [`${ONYXKEYS.COLLECTION.REPORT}${expenseReportID}`]: expenseReport, + [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`]: { + [reimbursementQueuedAction.reportActionID]: reimbursementQueuedAction, + }, + }); + await waitForBatchedUpdates(); + + const reason = reasonForReportToBeInOptionList({ + report: chatReport, + chatReport, + currentReportId: '', + isInFocusMode: false, + betas: [CONST.BETAS.DEFAULT_ROOMS], + doesReportHaveViolations: false, + excludeEmptyChats: false, + draftComment: '', + isReportArchived: undefined, + }); + + expect(reason).toBe(CONST.REPORT_IN_LHN_REASONS.HAS_GBR); + }); }); From cb6aca91e12127c957aa2b6bbd863f3bc65a7639 Mon Sep 17 00:00:00 2001 From: ShridharGoel <35566748+ShridharGoel@users.noreply.github.com> Date: Tue, 4 Nov 2025 22:11:49 +0530 Subject: [PATCH 2/4] Typecheck fix --- tests/unit/ReportUtilsTest.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index f289dcb5fe83..3d452cc740ef 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -8799,13 +8799,13 @@ describe('ReportUtils', () => { }; await Onyx.merge(ONYXKEYS.SESSION, {accountID: currentUserAccountID, email: currentUserEmail}); - await Onyx.multiSet({ - [`${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`]: chatReport, - [`${ONYXKEYS.COLLECTION.REPORT}${expenseReportID}`]: expenseReport, - [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`]: { + await Promise.all([ + Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`, chatReport), + Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${expenseReportID}`, expenseReport), + Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, { [reimbursementQueuedAction.reportActionID]: reimbursementQueuedAction, - }, - }); + }), + ]); await waitForBatchedUpdates(); const reason = reasonForReportToBeInOptionList({ From b991568d744c6ea4ce6aec2e2c8c9d6c2ac272bd Mon Sep 17 00:00:00 2001 From: ShridharGoel <35566748+ShridharGoel@users.noreply.github.com> Date: Thu, 6 Nov 2025 04:26:29 +0530 Subject: [PATCH 3/4] Add tests --- tests/unit/ReportUtilsTest.ts | 138 ++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 3d452cc740ef..4cbdc4c413a9 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -8769,6 +8769,8 @@ describe('ReportUtils', () => { }); it('should surface a GBR when reimbursement is queued and waiting on the payee bank account', async () => { + await Onyx.clear(); + const adminAccountID = 42; const expenseReportID = 'BRICK_ROAD_WAITING_ON_BANK'; const chatReport: Report = { @@ -8821,5 +8823,141 @@ describe('ReportUtils', () => { }); expect(reason).toBe(CONST.REPORT_IN_LHN_REASONS.HAS_GBR); + await Onyx.clear(); + }); + + it('should not surface a GBR when reimbursement is queued but not waiting on the payee bank account', async () => { + await Onyx.clear(); + + const adminAccountID = 42; + const expenseReportID = 'BRICK_ROAD_NOT_WAITING_ON_BANK'; + const chatReport: Report = { + ...LHNTestUtils.getFakeReport([currentUserAccountID, adminAccountID]), + hasOutstandingChildRequest: false, + iouReportID: expenseReportID, + }; + const expenseReport: Report = { + ...LHNTestUtils.getFakeReport([currentUserAccountID, adminAccountID]), + reportID: expenseReportID, + chatReportID: chatReport.reportID, + type: CONST.REPORT.TYPE.EXPENSE, + ownerAccountID: currentUserAccountID, + managerID: adminAccountID, + currency: CONST.CURRENCY.USD, + total: 10000, + stateNum: CONST.REPORT.STATE_NUM.APPROVED, + statusNum: CONST.REPORT.STATUS_NUM.APPROVED, + isWaitingOnBankAccount: false, + }; + const reimbursementQueuedAction: ReportAction = { + ...LHNTestUtils.getFakeReportAction(), + actionName: CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENT_QUEUED, + childReportID: expenseReportID, + originalMessage: { + paymentType: CONST.IOU.PAYMENT_TYPE.VBBA, + }, + }; + + await Onyx.merge(ONYXKEYS.SESSION, {accountID: currentUserAccountID, email: currentUserEmail}); + await Promise.all([ + Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`, chatReport), + Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${expenseReportID}`, expenseReport), + Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, { + [reimbursementQueuedAction.reportActionID]: reimbursementQueuedAction, + }), + ]); + await waitForBatchedUpdates(); + + const reason = reasonForReportToBeInOptionList({ + report: chatReport, + chatReport, + currentReportId: '', + isInFocusMode: false, + betas: [CONST.BETAS.DEFAULT_ROOMS], + doesReportHaveViolations: false, + excludeEmptyChats: false, + draftComment: '', + isReportArchived: undefined, + }); + + expect(reason).toBe(CONST.REPORT_IN_LHN_REASONS.DEFAULT); + await Onyx.clear(); + }); + + it('should not surface a GBR when bank account is added, but reimbursement is disabled on the policy', async () => { + await Onyx.clear(); + + const adminAccountID = 42; + const policyID = 'REIMBURSEMENT_DISABLED_POLICY'; + const expenseReportID = 'BRICK_ROAD_POLICY_REIM_DISABLED'; + const chatReport: Report = { + ...LHNTestUtils.getFakeReport([currentUserAccountID, adminAccountID]), + iouReportID: expenseReportID, + policyID, + }; + const expenseReport: Report = { + ...LHNTestUtils.getFakeReport([currentUserAccountID, adminAccountID]), + reportID: expenseReportID, + chatReportID: chatReport.reportID, + type: CONST.REPORT.TYPE.EXPENSE, + ownerAccountID: currentUserAccountID, + managerID: adminAccountID, + currency: CONST.CURRENCY.USD, + total: 10000, + stateNum: CONST.REPORT.STATE_NUM.APPROVED, + statusNum: CONST.REPORT.STATUS_NUM.APPROVED, + isWaitingOnBankAccount: false, + policyID, + }; + const pendingTransaction: Transaction = { + transactionID: `${expenseReportID}-transaction`, + reportID: expenseReportID, + amount: 10000, + currency: CONST.CURRENCY.USD, + bank: CONST.EXPENSIFY_CARD.BANK, + status: CONST.TRANSACTION.STATUS.PENDING, + }; + const reimbursementQueuedAction: ReportAction = { + ...LHNTestUtils.getFakeReportAction(), + actionName: CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENT_QUEUED, + childReportID: expenseReportID, + originalMessage: { + paymentType: CONST.IOU.PAYMENT_TYPE.VBBA, + }, + }; + const policy: Policy = { + id: policyID, + name: 'Policy', + role: CONST.POLICY.ROLE.ADMIN, + type: CONST.POLICY.TYPE.TEAM, + reimbursementChoice: CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_NO, + }; + + await Onyx.merge(ONYXKEYS.SESSION, {accountID: currentUserAccountID, email: currentUserEmail}); + await Promise.all([ + Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`, chatReport), + Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${expenseReportID}`, expenseReport), + Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, { + [reimbursementQueuedAction.reportActionID]: reimbursementQueuedAction, + }), + Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${pendingTransaction.transactionID}`, pendingTransaction), + Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, policy), + ]); + await waitForBatchedUpdates(); + + const reason = reasonForReportToBeInOptionList({ + report: chatReport, + chatReport, + currentReportId: '', + isInFocusMode: false, + betas: [CONST.BETAS.DEFAULT_ROOMS], + doesReportHaveViolations: false, + excludeEmptyChats: false, + draftComment: '', + isReportArchived: undefined, + }); + + expect(reason).toBe(CONST.REPORT_IN_LHN_REASONS.DEFAULT); + await Onyx.clear(); }); }); From 32d35ac316167c506e668ee4d232d51aaf7c835c Mon Sep 17 00:00:00 2001 From: ShridharGoel <35566748+ShridharGoel@users.noreply.github.com> Date: Fri, 7 Nov 2025 23:32:17 +0530 Subject: [PATCH 4/4] Lint and type fixes --- tests/unit/ReportUtilsTest.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index eaf2f166f070..1aec34fcf00d 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -8818,7 +8818,7 @@ describe('ReportUtils', () => { await Onyx.clear(); const adminAccountID = 42; - const expenseReportID = 'BRICK_ROAD_WAITING_ON_BANK'; + const expenseReportID = '10000'; const chatReport: Report = { ...LHNTestUtils.getFakeReport([currentUserAccountID, adminAccountID]), hasOutstandingChildRequest: true, @@ -8876,7 +8876,7 @@ describe('ReportUtils', () => { await Onyx.clear(); const adminAccountID = 42; - const expenseReportID = 'BRICK_ROAD_NOT_WAITING_ON_BANK'; + const expenseReportID = '10000'; const chatReport: Report = { ...LHNTestUtils.getFakeReport([currentUserAccountID, adminAccountID]), hasOutstandingChildRequest: false, @@ -8934,8 +8934,8 @@ describe('ReportUtils', () => { await Onyx.clear(); const adminAccountID = 42; - const policyID = 'REIMBURSEMENT_DISABLED_POLICY'; - const expenseReportID = 'BRICK_ROAD_POLICY_REIM_DISABLED'; + const policyID = '10000'; + const expenseReportID = '20000'; const chatReport: Report = { ...LHNTestUtils.getFakeReport([currentUserAccountID, adminAccountID]), iouReportID: expenseReportID, @@ -8960,6 +8960,8 @@ describe('ReportUtils', () => { reportID: expenseReportID, amount: 10000, currency: CONST.CURRENCY.USD, + created: '2025-01-01T00:00:00.000Z', + merchant: 'Expensify Card', bank: CONST.EXPENSIFY_CARD.BANK, status: CONST.TRANSACTION.STATUS.PENDING, }; @@ -8971,11 +8973,14 @@ describe('ReportUtils', () => { paymentType: CONST.IOU.PAYMENT_TYPE.VBBA, }, }; - const policy: Policy = { + const policy1: Policy = { id: policyID, name: 'Policy', role: CONST.POLICY.ROLE.ADMIN, type: CONST.POLICY.TYPE.TEAM, + owner: currentUserEmail, + outputCurrency: CONST.CURRENCY.USD, + isPolicyExpenseChatEnabled: true, reimbursementChoice: CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_NO, }; @@ -8987,7 +8992,7 @@ describe('ReportUtils', () => { [reimbursementQueuedAction.reportActionID]: reimbursementQueuedAction, }), Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${pendingTransaction.transactionID}`, pendingTransaction), - Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, policy), + Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, policy1), ]); await waitForBatchedUpdates();