Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
199 changes: 199 additions & 0 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ import {
parseReportRouteParams,
populateOptimisticReportFormula,
prepareOnboardingOnyxData,
reasonForReportToBeInOptionList,
requiresAttentionFromCurrentUser,
requiresManualSubmission,
shouldBlockSubmitDueToStrictPolicyRules,
Expand Down Expand Up @@ -8812,4 +8813,202 @@ 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 () => {
await Onyx.clear();

const adminAccountID = 42;
const expenseReportID = '10000';
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 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.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 = '10000';
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 = '10000';
const expenseReportID = '20000';
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,
created: '2025-01-01T00:00:00.000Z',
merchant: 'Expensify Card',
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 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,
};

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}`, policy1),
]);
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();
});
});