Skip to content

Commit 5459278

Browse files
MelvinBotsituchan
andcommitted
Add test for negative reimbursable expense PAY badge
Co-authored-by: Situ Chandra Shil <situchan@users.noreply.github.com>
1 parent a7a880f commit 5459278

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

tests/actions/IOUTest/ReportWorkflowTest.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3779,6 +3779,64 @@ describe('actions/IOU/ReportWorkflow', () => {
37793779
expect(result).toBe(CONST.REPORT.ACTION_BADGE.PAY);
37803780
});
37813781

3782+
it('should return PAY badge for negative reimbursable expense via pay-elsewhere path', async () => {
3783+
const iouReportID = '1600';
3784+
const chatReportID = '1601';
3785+
const policyID = '1602';
3786+
3787+
const fakePolicy: Policy = {
3788+
...createRandomPolicy(Number(policyID)),
3789+
id: policyID,
3790+
type: CONST.POLICY.TYPE.TEAM,
3791+
approvalMode: CONST.POLICY.APPROVAL_MODE.BASIC,
3792+
role: CONST.POLICY.ROLE.ADMIN,
3793+
reimbursementChoice: CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_MANUAL,
3794+
};
3795+
3796+
const fakeChatReport: Report = {
3797+
...createRandomReport(Number(chatReportID), CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT),
3798+
reportID: chatReportID,
3799+
policyID,
3800+
};
3801+
3802+
// Negative reimbursable expense (credit): total is positive on expense reports,
3803+
// which flips to negative reimbursableSpend in getMoneyRequestSpendBreakdown.
3804+
// canBePaidNow returns false (negative reimbursableSpend), but canBePaidElsewhere
3805+
// returns true via canShowMarkedAsPaidForNegativeAmount.
3806+
// Since the transaction IS reimbursable, hasOnlyNonReimbursableTransactions returns
3807+
// false, so PAY badge should be shown.
3808+
const fakeIouReport: Report = {
3809+
...createRandomReport(Number(iouReportID), CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT),
3810+
reportID: iouReportID,
3811+
type: CONST.REPORT.TYPE.EXPENSE,
3812+
policyID,
3813+
stateNum: CONST.REPORT.STATE_NUM.APPROVED,
3814+
statusNum: CONST.REPORT.STATUS_NUM.APPROVED,
3815+
managerID: 999999,
3816+
total: 5000,
3817+
nonReimbursableTotal: 0,
3818+
isWaitingOnBankAccount: false,
3819+
};
3820+
3821+
const fakeTransaction: Transaction = {
3822+
...createRandomTransaction(0),
3823+
reportID: iouReportID,
3824+
amount: 5000,
3825+
status: CONST.TRANSACTION.STATUS.POSTED,
3826+
bank: '',
3827+
reimbursable: true,
3828+
};
3829+
3830+
await Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, fakePolicy);
3831+
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`, fakeChatReport);
3832+
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${iouReportID}`, fakeIouReport);
3833+
await Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION}${fakeTransaction.transactionID}`, fakeTransaction);
3834+
await waitForBatchedUpdates();
3835+
3836+
const result = getBadgeFromIOUReport(fakeIouReport, fakeChatReport, fakePolicy, {}, undefined, RORY_EMAIL, RORY_ACCOUNT_ID);
3837+
expect(result).toBe(CONST.REPORT.ACTION_BADGE.PAY);
3838+
});
3839+
37823840
it('should return undefined badge for settled report', async () => {
37833841
const iouReportID = '1300';
37843842
const chatReportID = '1301';

0 commit comments

Comments
 (0)