Skip to content

Commit bfa5bce

Browse files
authored
Merge pull request Expensify#64303 from bernhardoj/fix/64027-extra-expense-after-delete-report
Fix extra expense is moved to self DM when deleting expense report
2 parents 080bd33 + 28adc68 commit bfa5bce

2 files changed

Lines changed: 66 additions & 0 deletions

File tree

src/libs/actions/Report.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4762,6 +4762,11 @@ function deleteAppReport(reportID: string | undefined) {
47624762
return;
47634763
}
47644764

4765+
const originalMessage = ReportActionsUtils.getOriginalMessage(reportAction);
4766+
if (originalMessage?.type !== CONST.IOU.REPORT_ACTION_TYPE.CREATE && originalMessage?.type !== CONST.IOU.REPORT_ACTION_TYPE.TRACK) {
4767+
return;
4768+
}
4769+
47654770
const transactionID = ReportActionsUtils.getOriginalMessage(reportAction)?.IOUTransactionID;
47664771
const childReportID = reportAction.childReportID;
47674772
const newReportActionID = rand64();

tests/actions/ReportTest.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,6 +1693,67 @@ describe('actions/Report', () => {
16931693
callback: (val) => (updateReport = val),
16941694
});
16951695
expect(updateReport?.description).toBe('<h1>test</h1>');
1696+
mockFetch.mockReset();
1697+
});
1698+
});
1699+
1700+
describe('deleteAppReport', () => {
1701+
it('should only moves CREATE or TRACK type of IOU action to self DM', async () => {
1702+
// Given an expense report with CREATE, TRACK, and PAY of IOU actions
1703+
const reportID = '1';
1704+
const firstIOUAction: OnyxTypes.ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.IOU> = {
1705+
reportActionID: '1',
1706+
actionName: CONST.REPORT.ACTIONS.TYPE.IOU,
1707+
created: DateUtils.getDBTime(),
1708+
originalMessage: {
1709+
amount: 100,
1710+
currency: CONST.CURRENCY.USD,
1711+
type: CONST.IOU.REPORT_ACTION_TYPE.CREATE,
1712+
},
1713+
};
1714+
const secondIOUAction: OnyxTypes.ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.IOU> = {
1715+
reportActionID: '2',
1716+
actionName: CONST.REPORT.ACTIONS.TYPE.IOU,
1717+
created: DateUtils.getDBTime(),
1718+
originalMessage: {
1719+
amount: 100,
1720+
currency: CONST.CURRENCY.USD,
1721+
type: CONST.IOU.REPORT_ACTION_TYPE.TRACK,
1722+
},
1723+
};
1724+
const payAction: OnyxTypes.ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.IOU> = {
1725+
reportActionID: '3',
1726+
actionName: CONST.REPORT.ACTIONS.TYPE.IOU,
1727+
created: DateUtils.getDBTime(),
1728+
originalMessage: {
1729+
amount: 100,
1730+
currency: CONST.CURRENCY.USD,
1731+
type: CONST.IOU.REPORT_ACTION_TYPE.PAY,
1732+
},
1733+
};
1734+
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, {
1735+
[firstIOUAction.reportActionID]: firstIOUAction,
1736+
[secondIOUAction.reportActionID]: secondIOUAction,
1737+
[payAction.reportActionID]: payAction,
1738+
});
1739+
1740+
// When deleting the expense report
1741+
Report.deleteAppReport(reportID);
1742+
await waitForBatchedUpdates();
1743+
1744+
// Then only the IOU action with type of CREATE and TRACK is moved to the self DM
1745+
const selfDMReportID = ReportUtils.findSelfDMReportID();
1746+
const selfDMReportActions = await new Promise<OnyxEntry<OnyxTypes.ReportActions>>((resolve) => {
1747+
const connection = Onyx.connect({
1748+
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${selfDMReportID}`,
1749+
callback: (val) => {
1750+
Onyx.disconnect(connection);
1751+
resolve(val);
1752+
},
1753+
});
1754+
});
1755+
// The length is 3 to include the CREATED action
1756+
expect(Object.keys(selfDMReportActions ?? {}).length).toBe(3);
16961757
});
16971758
});
16981759
});

0 commit comments

Comments
 (0)