diff --git a/src/libs/migrations/PersonalDetailsByAccountID.js b/src/libs/migrations/PersonalDetailsByAccountID.js index 38c992a6a375..c08ec6fb2c43 100644 --- a/src/libs/migrations/PersonalDetailsByAccountID.js +++ b/src/libs/migrations/PersonalDetailsByAccountID.js @@ -257,6 +257,18 @@ export default function () { delete newReport.participants; } + if (lodashHas(newReport, ['ownerEmail'])) { + reportWasModified = true; + Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing ownerEmail from report ${newReport.reportID}`); + delete newReport.ownerEmail; + } + + if (lodashHas(newReport, ['managerEmail'])) { + reportWasModified = true; + Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing managerEmail from report ${newReport.reportID}`); + delete newReport.managerEmail; + } + if (reportWasModified) { onyxData[onyxKey] = newReport; } diff --git a/tests/unit/MigrationTest.js b/tests/unit/MigrationTest.js index f212dd75447d..ebffc71e4e0e 100644 --- a/tests/unit/MigrationTest.js +++ b/tests/unit/MigrationTest.js @@ -452,6 +452,56 @@ describe('Migrations', () => { }, }); })); + + it('Should remove any instances of ownerEmail found in a report', () => + Onyx.multiSet({ + [`${ONYXKEYS.COLLECTION.REPORT}1`]: { + reportID: 1, + ownerEmail: 'fake@test.com', + ownerAccountID: 5, + }, + }) + .then(PersonalDetailsByAccountID) + .then(() => { + expect(LogSpy).toHaveBeenCalledWith('[Migrate Onyx] PersonalDetailsByAccountID migration: removing ownerEmail from report 1'); + const connectionID = Onyx.connect({ + key: ONYXKEYS.COLLECTION.REPORT, + waitForCollectionCallback: true, + callback: (allReports) => { + Onyx.disconnect(connectionID); + const expectedReport = { + reportID: 1, + ownerAccountID: 5, + }; + expect(allReports[`${ONYXKEYS.COLLECTION.REPORT}1`]).toMatchObject(expectedReport); + }, + }); + })); + + it('Should remove any instances of managerEmail found in a report', () => + Onyx.multiSet({ + [`${ONYXKEYS.COLLECTION.REPORT}1`]: { + reportID: 1, + managerEmail: 'fake@test.com', + managerID: 5, + }, + }) + .then(PersonalDetailsByAccountID) + .then(() => { + expect(LogSpy).toHaveBeenCalledWith('[Migrate Onyx] PersonalDetailsByAccountID migration: removing managerEmail from report 1'); + const connectionID = Onyx.connect({ + key: ONYXKEYS.COLLECTION.REPORT, + waitForCollectionCallback: true, + callback: (allReports) => { + Onyx.disconnect(connectionID); + const expectedReport = { + reportID: 1, + managerID: 5, + }; + expect(allReports[`${ONYXKEYS.COLLECTION.REPORT}1`]).toMatchObject(expectedReport); + }, + }); + })); }); describe('CheckForPreviousReportActionID', () => {