Skip to content

Commit f5a3f30

Browse files
committed
add unit test for canLeaveChat
1 parent 6ebd7f7 commit f5a3f30

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

tests/unit/ReportUtilsTest.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4495,6 +4495,80 @@ describe('ReportUtils', () => {
44954495

44964496
expect(canLeaveChat(report, reportPolicy)).toBe(true);
44974497
});
4498+
4499+
describe('when the report is a money report', () => {
4500+
it('should return false for the owner of the report', async () => {
4501+
const report: Report = {
4502+
...createRandomReport(1),
4503+
chatType: undefined,
4504+
type: CONST.REPORT.TYPE.IOU,
4505+
ownerAccountID: currentUserAccountID,
4506+
};
4507+
4508+
await Onyx.set(ONYXKEYS.SESSION, {email: currentUserEmail, accountID: currentUserAccountID});
4509+
4510+
const reportPolicy: Policy = {
4511+
...createRandomPolicy(1),
4512+
role: CONST.POLICY.ROLE.USER,
4513+
};
4514+
4515+
expect(canLeaveChat(report, reportPolicy)).toBe(false);
4516+
});
4517+
4518+
it('should return false for the manager of the report', async () => {
4519+
const report: Report = {
4520+
...createRandomReport(1),
4521+
chatType: undefined,
4522+
type: CONST.REPORT.TYPE.IOU,
4523+
managerID: currentUserAccountID,
4524+
};
4525+
4526+
await Onyx.set(ONYXKEYS.SESSION, {email: currentUserEmail, accountID: currentUserAccountID});
4527+
4528+
const reportPolicy: Policy = {
4529+
...createRandomPolicy(1),
4530+
role: CONST.POLICY.ROLE.USER,
4531+
};
4532+
4533+
expect(canLeaveChat(report, reportPolicy)).toBe(false);
4534+
});
4535+
4536+
it('should return false for the admin of the policy', async () => {
4537+
const report: Report = {
4538+
...createRandomReport(1),
4539+
chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT,
4540+
type: CONST.REPORT.TYPE.EXPENSE,
4541+
};
4542+
4543+
await Onyx.set(ONYXKEYS.SESSION, {email: currentUserEmail, accountID: currentUserAccountID});
4544+
4545+
const reportPolicy: Policy = {
4546+
...createRandomPolicy(1),
4547+
role: CONST.POLICY.ROLE.ADMIN,
4548+
};
4549+
4550+
expect(canLeaveChat(report, reportPolicy)).toBe(false);
4551+
});
4552+
4553+
it('should return true for the invited user', async () => {
4554+
const report: Report = {
4555+
...createRandomReport(1),
4556+
chatType: undefined,
4557+
type: CONST.REPORT.TYPE.IOU,
4558+
ownerAccountID: 1,
4559+
managerID: 2,
4560+
};
4561+
4562+
await Onyx.set(ONYXKEYS.SESSION, {email: currentUserEmail, accountID: currentUserAccountID});
4563+
4564+
const reportPolicy: Policy = {
4565+
...createRandomPolicy(1),
4566+
role: CONST.POLICY.ROLE.USER,
4567+
};
4568+
4569+
expect(canLeaveChat(report, reportPolicy)).toBe(true);
4570+
});
4571+
});
44984572
});
44994573

45004574
describe('canJoinChat', () => {

0 commit comments

Comments
 (0)