Skip to content

Commit

Permalink
Merge pull request #31664 from Expensify/puneet-manager-owner-migration
Browse files Browse the repository at this point in the history
[No QA] Remove managerEmail and ownerEmail from Onyx
  • Loading branch information
puneetlath authored Nov 29, 2023
2 parents 01a0183 + dbb4cba commit 4fa869c
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/libs/migrations/PersonalDetailsByAccountID.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
50 changes: 50 additions & 0 deletions tests/unit/MigrationTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '[email protected]',
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: '[email protected]',
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', () => {
Expand Down

0 comments on commit 4fa869c

Please sign in to comment.