Skip to content

Commit 4e2041a

Browse files
committed
update unit test
1 parent d8db28d commit 4e2041a

1 file changed

Lines changed: 20 additions & 7 deletions

File tree

tests/unit/ReportPrimaryActionUtilsTest.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const PERSONAL_DETAILS = {
2525
const REPORT_ID = 1;
2626
const CHAT_REPORT_ID = 2;
2727
const POLICY_ID = 3;
28+
const INVOICE_SENDER_ACCOUNT_ID = 4;
2829

2930
// This keeps the error "@rnmapbox/maps native code not available." from causing the tests to fail
3031
jest.mock('@components/ConfirmedRoute.tsx');
@@ -126,23 +127,33 @@ describe('getPrimaryAction', () => {
126127
expect(getReportPrimaryAction({report, chatReport, reportTransactions: [transaction], violations: {}, policy: policy as Policy})).toBe('');
127128
});
128129

129-
it('should return PAY for submitted invoice report', async () => {
130+
it('should return PAY for submitted invoice report if paid as personal', async () => {
130131
const report = {
131132
reportID: REPORT_ID,
132133
type: CONST.REPORT.TYPE.INVOICE,
133-
ownerAccountID: CURRENT_USER_ACCOUNT_ID,
134+
ownerAccountID: INVOICE_SENDER_ACCOUNT_ID,
135+
parentReportID: CHAT_REPORT_ID,
134136
statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED,
135137
stateNum: CONST.REPORT.STATE_NUM.SUBMITTED,
136138
} as unknown as Report;
139+
const parentReport = {
140+
reportID: CHAT_REPORT_ID,
141+
invoiceReceiver: {
142+
type: CONST.REPORT.INVOICE_RECEIVER_TYPE.INDIVIDUAL,
143+
accountID: CURRENT_USER_ACCOUNT_ID,
144+
},
145+
} as unknown as Report;
137146
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report);
138-
const policy = {
147+
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${CHAT_REPORT_ID}`, parentReport);
148+
const policy = {} as Policy;
149+
const invoiceReceiverPolicy = {
139150
role: CONST.POLICY.ROLE.ADMIN,
140-
};
151+
} as Policy;
141152
const transaction = {
142153
reportID: `${REPORT_ID}`,
143154
} as unknown as Transaction;
144155

145-
expect(getReportPrimaryAction({report, chatReport, reportTransactions: [transaction], violations: {}, policy: policy as Policy})).toBe(CONST.REPORT.PRIMARY_ACTIONS.PAY);
156+
expect(getReportPrimaryAction({report, chatReport, reportTransactions: [transaction], violations: {}, policy, invoiceReceiverPolicy})).toBe(CONST.REPORT.PRIMARY_ACTIONS.PAY);
146157
});
147158

148159
it('should return PAY for expense report with payments enabled', async () => {
@@ -560,12 +571,14 @@ describe('getTransactionThreadPrimaryAction', () => {
560571
).toBe('');
561572
});
562573

563-
it('should return PAY if paid as business and the payer is the policy admin', async () => {
574+
it('should return PAY for submitted invoice report if paid as business and the payer is the policy admin', async () => {
564575
const report = {
565576
reportID: REPORT_ID,
566577
type: CONST.REPORT.TYPE.INVOICE,
567-
ownerAccountID: CURRENT_USER_ACCOUNT_ID,
578+
ownerAccountID: INVOICE_SENDER_ACCOUNT_ID,
568579
parentReportID: CHAT_REPORT_ID,
580+
statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED,
581+
stateNum: CONST.REPORT.STATE_NUM.SUBMITTED,
569582
} as unknown as Report;
570583
const parentReport = {
571584
reportID: CHAT_REPORT_ID,

0 commit comments

Comments
 (0)