Skip to content

Commit 4580fdf

Browse files
committed
add unit test
1 parent 7e00717 commit 4580fdf

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

tests/actions/ReportTest.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,4 +1756,75 @@ describe('actions/Report', () => {
17561756
expect(Object.keys(selfDMReportActions ?? {}).length).toBe(3);
17571757
});
17581758
});
1759+
1760+
describe('changeReportPolicy', () => {
1761+
it('should unarchive the expense report', async () => {
1762+
// Given an archived expense report
1763+
const expenseReport: OnyxTypes.Report = {
1764+
...createRandomReport(1),
1765+
type: CONST.REPORT.TYPE.EXPENSE,
1766+
policyID: '1',
1767+
};
1768+
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${expenseReport.reportID}`, {
1769+
private_isArchived: DateUtils.getDBTime(),
1770+
});
1771+
1772+
// When moving to another workspace
1773+
Report.changeReportPolicy(expenseReport, '2');
1774+
await waitForBatchedUpdates();
1775+
1776+
// Then the expense report should not be archived anymore
1777+
const isArchived = await new Promise<boolean>((resolve) => {
1778+
const connection = Onyx.connect({
1779+
key: `${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${expenseReport.reportID}`,
1780+
callback: (val) => {
1781+
resolve(!!val?.private_isArchived);
1782+
Onyx.disconnect(connection);
1783+
},
1784+
});
1785+
});
1786+
expect(isArchived).toBe(false);
1787+
});
1788+
});
1789+
1790+
describe('changeReportPolicyAndInviteSubmitter', () => {
1791+
it('should unarchive the expense report', async () => {
1792+
// Given an archived expense report
1793+
const ownerAccountID = 1;
1794+
const ownerEmail = 'owner@gmail.com';
1795+
const adminEmail = 'admin@gmail.com';
1796+
const expenseReport: OnyxTypes.Report = {
1797+
...createRandomReport(1),
1798+
type: CONST.REPORT.TYPE.EXPENSE,
1799+
policyID: '1',
1800+
ownerAccountID,
1801+
};
1802+
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${expenseReport.reportID}`, {
1803+
private_isArchived: DateUtils.getDBTime(),
1804+
});
1805+
await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, {
1806+
[ownerAccountID]: {
1807+
login: ownerEmail,
1808+
},
1809+
});
1810+
1811+
// When moving to another workspace
1812+
Report.changeReportPolicyAndInviteSubmitter(expenseReport, '2', {
1813+
[adminEmail]: {role: CONST.POLICY.ROLE.ADMIN},
1814+
});
1815+
await waitForBatchedUpdates();
1816+
1817+
// Then the expense report should not be archived anymore
1818+
const isArchived = await new Promise<boolean>((resolve) => {
1819+
const connection = Onyx.connect({
1820+
key: `${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${expenseReport.reportID}`,
1821+
callback: (val) => {
1822+
resolve(!!val?.private_isArchived);
1823+
Onyx.disconnect(connection);
1824+
},
1825+
});
1826+
});
1827+
expect(isArchived).toBe(false);
1828+
});
1829+
});
17591830
});

0 commit comments

Comments
 (0)