Skip to content

Commit 17e795f

Browse files
committed
add unit test
1 parent 61134bc commit 17e795f

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

tests/actions/PolicyTest.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,6 +1519,43 @@ describe('actions/Policy', () => {
15191519
});
15201520
});
15211521

1522+
describe('leaveWorkspace', () => {
1523+
it('should leave workspace and archive reports', async () => {
1524+
// Given a policy and a report in Onyx
1525+
const policy = createRandomPolicy(1);
1526+
const report = {
1527+
...createRandomReport(1, undefined),
1528+
policyID: policy.id,
1529+
};
1530+
1531+
// Set initial state in Onyx
1532+
await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policy.id}`, policy);
1533+
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report);
1534+
1535+
// When leaveWorkspace is called
1536+
Policy.leaveWorkspace(policy);
1537+
1538+
await waitForBatchedUpdates();
1539+
1540+
// Then the policy should be removed
1541+
const policyAfter = await getOnyxValue(`${ONYXKEYS.COLLECTION.POLICY}${policy.id}`);
1542+
expect(policyAfter).toBeFalsy();
1543+
1544+
// And the report should be closed and archived
1545+
const reportAfter = await getOnyxValue(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`);
1546+
expect(reportAfter).toMatchObject({
1547+
statusNum: CONST.REPORT.STATUS_NUM.CLOSED,
1548+
stateNum: CONST.REPORT.STATE_NUM.APPROVED,
1549+
});
1550+
1551+
const reportNameValuePairsAfter = await getOnyxValue(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`);
1552+
expect(reportNameValuePairsAfter?.private_isArchived).toBeTruthy();
1553+
1554+
const reportMetadataAfter = await getOnyxValue(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${report.reportID}`);
1555+
expect(reportMetadataAfter?.pendingChatMembers).toBeFalsy();
1556+
});
1557+
});
1558+
15221559
describe('generateDefaultWorkspaceName', () => {
15231560
beforeAll(() => {
15241561
Onyx.set(ONYXKEYS.COLLECTION.POLICY, {});

0 commit comments

Comments
 (0)