From 59e0697189c843c8bbdf9c33b345b4697a79bde5 Mon Sep 17 00:00:00 2001 From: Puneet Lath Date: Tue, 21 Nov 2023 16:15:48 -0600 Subject: [PATCH 1/2] Remove managerEmail and ownerEmail from Onyx --- src/libs/migrations/PersonalDetailsByAccountID.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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; } From dbb4cba45d2fc405a9d6aec39e3326c44666230a Mon Sep 17 00:00:00 2001 From: Puneet Lath Date: Tue, 21 Nov 2023 16:21:17 -0600 Subject: [PATCH 2/2] update migration tests for new data being removed --- tests/unit/MigrationTest.js | 50 +++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) 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', () => {