Skip to content

Commit 2e1cddf

Browse files
authored
Merge pull request Expensify#64784 from bernhardoj/fix/63291-unarchive-report-when-moving-ws
Unarchive expense report when moving to a different workspace
2 parents 4720968 + e8b97cc commit 2e1cddf

2 files changed

Lines changed: 87 additions & 0 deletions

File tree

src/libs/actions/Report.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5671,6 +5671,22 @@ function buildOptimisticChangePolicyData(report: Report, policyID: string, repor
56715671
},
56725672
});
56735673

5674+
// 5. Make sure the expense report is not archived
5675+
optimisticData.push({
5676+
onyxMethod: Onyx.METHOD.MERGE,
5677+
key: `${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID}`,
5678+
value: {
5679+
private_isArchived: null,
5680+
},
5681+
});
5682+
failureData.push({
5683+
onyxMethod: Onyx.METHOD.MERGE,
5684+
key: `${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID}`,
5685+
value: {
5686+
private_isArchived: DateUtils.getDBTime(),
5687+
},
5688+
});
5689+
56745690
return {optimisticData, successData, failureData, optimisticReportPreviewAction, optimisticMovedReportAction};
56755691
}
56765692

tests/actions/ReportTest.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,6 +1760,77 @@ describe('actions/Report', () => {
17601760
});
17611761
});
17621762

1763+
describe('changeReportPolicy', () => {
1764+
it('should unarchive the expense report', async () => {
1765+
// Given an archived expense report
1766+
const expenseReport: OnyxTypes.Report = {
1767+
...createRandomReport(1),
1768+
type: CONST.REPORT.TYPE.EXPENSE,
1769+
policyID: '1',
1770+
};
1771+
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${expenseReport.reportID}`, {
1772+
private_isArchived: DateUtils.getDBTime(),
1773+
});
1774+
1775+
// When moving to another workspace
1776+
Report.changeReportPolicy(expenseReport, '2');
1777+
await waitForBatchedUpdates();
1778+
1779+
// Then the expense report should not be archived anymore
1780+
const isArchived = await new Promise<boolean>((resolve) => {
1781+
const connection = Onyx.connect({
1782+
key: `${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${expenseReport.reportID}`,
1783+
callback: (val) => {
1784+
resolve(!!val?.private_isArchived);
1785+
Onyx.disconnect(connection);
1786+
},
1787+
});
1788+
});
1789+
expect(isArchived).toBe(false);
1790+
});
1791+
});
1792+
1793+
describe('changeReportPolicyAndInviteSubmitter', () => {
1794+
it('should unarchive the expense report', async () => {
1795+
// Given an archived expense report
1796+
const ownerAccountID = 1;
1797+
const ownerEmail = 'owner@gmail.com';
1798+
const adminEmail = 'admin@gmail.com';
1799+
const expenseReport: OnyxTypes.Report = {
1800+
...createRandomReport(1),
1801+
type: CONST.REPORT.TYPE.EXPENSE,
1802+
policyID: '1',
1803+
ownerAccountID,
1804+
};
1805+
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${expenseReport.reportID}`, {
1806+
private_isArchived: DateUtils.getDBTime(),
1807+
});
1808+
await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, {
1809+
[ownerAccountID]: {
1810+
login: ownerEmail,
1811+
},
1812+
});
1813+
1814+
// When moving to another workspace
1815+
Report.changeReportPolicyAndInviteSubmitter(expenseReport, '2', {
1816+
[adminEmail]: {role: CONST.POLICY.ROLE.ADMIN},
1817+
});
1818+
await waitForBatchedUpdates();
1819+
1820+
// Then the expense report should not be archived anymore
1821+
const isArchived = await new Promise<boolean>((resolve) => {
1822+
const connection = Onyx.connect({
1823+
key: `${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${expenseReport.reportID}`,
1824+
callback: (val) => {
1825+
resolve(!!val?.private_isArchived);
1826+
Onyx.disconnect(connection);
1827+
},
1828+
});
1829+
});
1830+
expect(isArchived).toBe(false);
1831+
});
1832+
});
1833+
17631834
describe('buildOptimisticChangePolicyData', () => {
17641835
it('should build the optimistic data next step for the change policy data', () => {
17651836
const report: OnyxTypes.Report = {

0 commit comments

Comments
 (0)