From c5d71d075c0aab33a48cb0dac8190cab152effa0 Mon Sep 17 00:00:00 2001 From: Puneet Lath Date: Fri, 7 Jul 2023 11:48:03 -0400 Subject: [PATCH 1/5] Remove email-based info from reportActions --- .../migrations/PersonalDetailsByAccountID.js | 86 +++++++------------ 1 file changed, 32 insertions(+), 54 deletions(-) diff --git a/src/libs/migrations/PersonalDetailsByAccountID.js b/src/libs/migrations/PersonalDetailsByAccountID.js index 34b8ebabc150..7325fc073bab 100644 --- a/src/libs/migrations/PersonalDetailsByAccountID.js +++ b/src/libs/migrations/PersonalDetailsByAccountID.js @@ -105,110 +105,88 @@ export default function () { } const newReportAction = reportAction; - if (lodashHas(reportAction, ['originalMessage', 'oldLogin']) && !lodashHas(reportAction, ['originalMessage', 'oldAccountID'])) { + if (lodashHas(reportAction, ['originalMessage', 'oldLogin'])) { reportActionsWereModified = true; - const oldAccountID = _.get(oldPersonalDetails, [reportAction.originalMessage.oldLogin, 'accountID']); - if (oldAccountID) { - newReportAction.originalMessage.oldAccountID = oldAccountID; + + if (lodashHas(reportAction, ['originalMessage', 'oldAccountID'])) { + delete newReportAction.originalMessage.oldLogin; } else { Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because originalMessage.oldAccountID not found`); return; } } - if (lodashHas(reportAction, ['originalMessage', 'newLogin']) && !lodashHas(reportAction, ['originalMessage', 'newAccountID'])) { + if (lodashHas(reportAction, ['originalMessage', 'newLogin'])) { reportActionsWereModified = true; - const newAccountID = _.get(oldPersonalDetails, [reportAction.originalMessage.newLogin, 'accountID']); - if (newAccountID) { - newReportAction.originalMessage.newAccountID = newAccountID; + + if (lodashHas(reportAction, ['originalMessage', 'newAccountID'])) { + delete newReportAction.originalMessage.newLogin; } else { Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because originalMessage.newAccountID not found`); return; } } - if (lodashHas(reportAction, ['accountEmail']) && !lodashHas(reportAction, ['accountID'])) { + if (lodashHas(reportAction, ['accountEmail'])) { reportActionsWereModified = true; - const accountID = _.get(oldPersonalDetails, [reportAction.accountEmail, 'accountID']); - if (accountID) { - newReportAction.accountID = accountID; + + if (lodashHas(reportAction, ['accountID'])) { + delete newReportAction.accountEmail; } else { Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because accountID not found`); return; } } - if (lodashHas(reportAction, ['actorEmail']) && !lodashHas(reportAction, ['actorAccountID'])) { + if (lodashHas(reportAction, ['actorEmail'])) { reportActionsWereModified = true; - const actorAccountID = _.get(oldPersonalDetails, [reportAction.actorEmail, 'accountID']); - if (actorAccountID) { - newReportAction.actorAccountID = actorAccountID; + + if (lodashHas(reportAction, ['actorAccountID'])) { + delete newReportAction.actorEmail; } else { Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because actorAccountID not found`); return; } } - if (lodashHas(reportAction, ['childManagerEmail']) && !lodashHas(reportAction, ['childManagerAccountID'])) { + if (lodashHas(reportAction, ['childManagerEmail'])) { reportActionsWereModified = true; - const childManagerAccountID = _.get(oldPersonalDetails, [reportAction.childManagerEmail, 'accountID']); - if (childManagerAccountID) { - newReportAction.childManagerAccountID = childManagerAccountID; + + if (lodashHas(reportAction, ['childManagerAccountID'])) { + delete newReportAction.childManagerEmail; } else { Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because childManagerAccountID not found`); return; } } - if (lodashHas(reportAction, ['whisperedTo']) && !lodashHas(reportAction, ['whisperedToAccountIDs'])) { + if (lodashHas(reportAction, ['whisperedTo'])) { reportActionsWereModified = true; - const whisperedToAccountIDs = []; - _.each(reportAction.whisperedTo, (whisperedToLogin) => { - const whisperedToAccountID = _.get(oldPersonalDetails, [whisperedToLogin, 'accountID']); - if (whisperedToAccountID) { - whisperedToAccountIDs.push(whisperedToAccountID); - } - }); - - if (whisperedToAccountIDs.length === reportAction.whisperedTo.length) { - newReportAction.whisperedToAccountIDs = whisperedToAccountIDs; + + if (lodashHas(reportAction, ['whisperedToAccountIDs'])) { + delete newReportAction.whisperedTo; } else { Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because whisperedToAccountIDs not found`); return; } } - if (lodashHas(reportAction, ['childOldestFourEmails']) && !lodashHas(reportAction, ['childOldestFourAccountIDs'])) { + if (lodashHas(reportAction, ['childOldestFourEmails'])) { reportActionsWereModified = true; - const childOldestFourEmails = reportAction.childOldestFourEmails.split(','); - const childOldestFourAccountIDs = []; - _.each(childOldestFourEmails, (login) => { - const accountID = _.get(oldPersonalDetails, [login.trim(), 'accountID']); - if (accountID) { - childOldestFourAccountIDs.push(accountID); - } - }); - - if (childOldestFourAccountIDs.length === childOldestFourEmails.length) { - newReportAction.childOldestFourAccountIDs = childOldestFourAccountIDs.join(','); + + if (lodashHas(reportAction, ['childOldestFourAccountIDs'])) { + delete newReportAction.childOldestFourEmails; } else { Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because childOldestFourAccountIDs not found`); return; } } - if (lodashHas(reportAction, ['originalMessage', 'participants']) && !lodashHas(reportAction, ['originalMessage', 'participantAccountIDs'])) { + if (lodashHas(reportAction, ['originalMessage', 'participants'])) { reportActionsWereModified = true; - const participantAccountIDs = []; - _.each(reportAction.originalMessage.participants, (participant) => { - const participantAccountID = _.get(oldPersonalDetails, [participant, 'accountID']); - if (participantAccountID) { - participantAccountIDs.push(participantAccountID); - } - }); - - if (participantAccountIDs.length === reportAction.originalMessage.participants.length) { - newReportAction.originalMessage.participantAccountIDs = participantAccountIDs; + + if (lodashHas(reportAction, ['originalMessage', 'participantAccountIDs'])) { + delete newReportAction.originalMessage.participants; } else { Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because originalMessage.participantAccountIDs not found`); return; From 827ab668998382e35c53d3a997dc4576fe755700 Mon Sep 17 00:00:00 2001 From: Puneet Lath Date: Fri, 7 Jul 2023 12:02:03 -0400 Subject: [PATCH 2/5] Update tests to account for udpated logic --- tests/unit/MigrationTest.js | 278 ++++++++++++++++++++---------------- 1 file changed, 154 insertions(+), 124 deletions(-) diff --git a/tests/unit/MigrationTest.js b/tests/unit/MigrationTest.js index 6ca3b5b2d516..7f1548a61015 100644 --- a/tests/unit/MigrationTest.js +++ b/tests/unit/MigrationTest.js @@ -305,44 +305,49 @@ describe('Migrations', () => { }); })); - it('Should remove any individual reportActions that have originalMessage.oldLogin but the matching accountID is not found', () => + it('Should remove any individual reportActions that have originalMessage.oldLogin but not originalMessage.oldAccountID', () => Onyx.multiSet({ - [`${DEPRECATED_ONYX_KEYS.PERSONAL_DETAILS}`]: { - 'test1@account.com': { - accountID: 100, - login: 'test1@account.com', - }, - 'test2@account.com': { - accountID: 101, - login: 'test2@account.com', - }, - }, [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]: { 1: { reportActionID: '1', originalMessage: { oldLogin: 'test1@account.com', + oldAccountID: 100, newLogin: 'test2@account.com', + newAccountID: 101, participants: ['test1@account.com', 'test2@account.com'], + participantAccountIDs: [100, 101], }, actorEmail: 'test2@account.com', + actorAccountID: 101, accountEmail: 'test2@account.com', + accountID: 101, childManagerEmail: 'test2@account.com', + childManagerAccountID: 101, whisperedTo: ['test1@account.com', 'test2@account.com'], + whisperedToAccountIDs: [100, 101], childOldestFourEmails: 'test1@account.com, test2@account.com', + childOldestFourAccountIDs: [100, 101], }, 2: { - reportActionID: '2', + reportActionID: '1', originalMessage: { - oldLogin: 'non-existent@account.com', + oldLogin: 'test1@account.com', newLogin: 'test2@account.com', + newAccountID: 101, participants: ['test1@account.com', 'test2@account.com'], + participantAccountIDs: [100, 101], }, actorEmail: 'test2@account.com', + actorAccountID: 101, accountEmail: 'test2@account.com', + accountID: 101, childManagerEmail: 'test2@account.com', + childManagerAccountID: 101, whisperedTo: ['test1@account.com', 'test2@account.com'], + whisperedToAccountIDs: [100, 101], childOldestFourEmails: 'test1@account.com, test2@account.com', + childOldestFourAccountIDs: [100, 101], }, }, }) @@ -360,44 +365,49 @@ describe('Migrations', () => { }); })); - it('Should remove any individual reportActions that have originalMessage.newLogin but the matching accountID is not found', () => + it('Should remove any individual reportActions that have originalMessage.newLogin but not originalMessage.newAccountID', () => Onyx.multiSet({ - [`${DEPRECATED_ONYX_KEYS.PERSONAL_DETAILS}`]: { - 'test1@account.com': { - accountID: 100, - login: 'test1@account.com', - }, - 'test2@account.com': { - accountID: 101, - login: 'test2@account.com', - }, - }, [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]: { 1: { reportActionID: '1', originalMessage: { oldLogin: 'test1@account.com', + oldAccountID: 100, newLogin: 'test2@account.com', + newAccountID: 101, participants: ['test1@account.com', 'test2@account.com'], + participantAccountIDs: [100, 101], }, actorEmail: 'test2@account.com', + actorAccountID: 101, accountEmail: 'test2@account.com', + accountID: 101, childManagerEmail: 'test2@account.com', + childManagerAccountID: 101, whisperedTo: ['test1@account.com', 'test2@account.com'], + whisperedToAccountIDs: [100, 101], childOldestFourEmails: 'test1@account.com, test2@account.com', + childOldestFourAccountIDs: [100, 101], }, 2: { - reportActionID: '2', + reportActionID: '1', originalMessage: { oldLogin: 'test1@account.com', - newLogin: 'non-existent@account.com', + oldAccountID: 100, + newLogin: 'test2@account.com', participants: ['test1@account.com', 'test2@account.com'], + participantAccountIDs: [100, 101], }, actorEmail: 'test2@account.com', + actorAccountID: 101, accountEmail: 'test2@account.com', + accountID: 101, childManagerEmail: 'test2@account.com', + childManagerAccountID: 101, whisperedTo: ['test1@account.com', 'test2@account.com'], + whisperedToAccountIDs: [100, 101], childOldestFourEmails: 'test1@account.com, test2@account.com', + childOldestFourAccountIDs: [100, 101], }, }, }) @@ -415,44 +425,49 @@ describe('Migrations', () => { }); })); - it('Should remove any individual reportActions that have accountEmail but the matching accountID is not found', () => + it('Should remove any individual reportActions that have accountEmail but not accountID', () => Onyx.multiSet({ - [`${DEPRECATED_ONYX_KEYS.PERSONAL_DETAILS}`]: { - 'test1@account.com': { - accountID: 100, - login: 'test1@account.com', - }, - 'test2@account.com': { - accountID: 101, - login: 'test2@account.com', - }, - }, [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]: { 1: { reportActionID: '1', originalMessage: { oldLogin: 'test1@account.com', + oldAccountID: 100, newLogin: 'test2@account.com', + newAccountID: 101, participants: ['test1@account.com', 'test2@account.com'], + participantAccountIDs: [100, 101], }, actorEmail: 'test2@account.com', + actorAccountID: 101, accountEmail: 'test2@account.com', + accountID: 101, childManagerEmail: 'test2@account.com', + childManagerAccountID: 101, whisperedTo: ['test1@account.com', 'test2@account.com'], + whisperedToAccountIDs: [100, 101], childOldestFourEmails: 'test1@account.com, test2@account.com', + childOldestFourAccountIDs: [100, 101], }, 2: { - reportActionID: '2', + reportActionID: '1', originalMessage: { oldLogin: 'test1@account.com', + oldAccountID: 100, newLogin: 'test2@account.com', + newAccountID: 101, participants: ['test1@account.com', 'test2@account.com'], + participantAccountIDs: [100, 101], }, actorEmail: 'test2@account.com', - accountEmail: 'non-existent@account.com', + actorAccountID: 101, + accountEmail: 'test2@account.com', childManagerEmail: 'test2@account.com', + childManagerAccountID: 101, whisperedTo: ['test1@account.com', 'test2@account.com'], + whisperedToAccountIDs: [100, 101], childOldestFourEmails: 'test1@account.com, test2@account.com', + childOldestFourAccountIDs: [100, 101], }, }, }) @@ -470,44 +485,49 @@ describe('Migrations', () => { }); })); - it('Should remove any individual reportActions that have actorEmail but the matching accountID is not found', () => + it('Should remove any individual reportActions that have actorEmail but not actorAccountID', () => Onyx.multiSet({ - [`${DEPRECATED_ONYX_KEYS.PERSONAL_DETAILS}`]: { - 'test1@account.com': { - accountID: 100, - login: 'test1@account.com', - }, - 'test2@account.com': { - accountID: 101, - login: 'test2@account.com', - }, - }, [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]: { 1: { reportActionID: '1', originalMessage: { oldLogin: 'test1@account.com', + oldAccountID: 100, newLogin: 'test2@account.com', + newAccountID: 101, participants: ['test1@account.com', 'test2@account.com'], + participantAccountIDs: [100, 101], }, actorEmail: 'test2@account.com', + actorAccountID: 101, accountEmail: 'test2@account.com', + accountID: 101, childManagerEmail: 'test2@account.com', + childManagerAccountID: 101, whisperedTo: ['test1@account.com', 'test2@account.com'], + whisperedToAccountIDs: [100, 101], childOldestFourEmails: 'test1@account.com, test2@account.com', + childOldestFourAccountIDs: [100, 101], }, 2: { - reportActionID: '2', + reportActionID: '1', originalMessage: { oldLogin: 'test1@account.com', + oldAccountID: 100, newLogin: 'test2@account.com', + newAccountID: 101, participants: ['test1@account.com', 'test2@account.com'], + participantAccountIDs: [100, 101], }, - actorEmail: 'non-existent@account.com', + actorEmail: 'test2@account.com', accountEmail: 'test2@account.com', + accountID: 101, childManagerEmail: 'test2@account.com', + childManagerAccountID: 101, whisperedTo: ['test1@account.com', 'test2@account.com'], + whisperedToAccountIDs: [100, 101], childOldestFourEmails: 'test1@account.com, test2@account.com', + childOldestFourAccountIDs: [100, 101], }, }, }) @@ -525,44 +545,49 @@ describe('Migrations', () => { }); })); - it('Should remove any individual reportActions that have childManagerEmail but the matching accountID is not found', () => + it('Should remove any individual reportActions that have childManagerEmail but not childManagerAccountID', () => Onyx.multiSet({ - [`${DEPRECATED_ONYX_KEYS.PERSONAL_DETAILS}`]: { - 'test1@account.com': { - accountID: 100, - login: 'test1@account.com', - }, - 'test2@account.com': { - accountID: 101, - login: 'test2@account.com', - }, - }, [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]: { 1: { reportActionID: '1', originalMessage: { oldLogin: 'test1@account.com', + oldAccountID: 100, newLogin: 'test2@account.com', + newAccountID: 101, participants: ['test1@account.com', 'test2@account.com'], + participantAccountIDs: [100, 101], }, actorEmail: 'test2@account.com', + actorAccountID: 101, accountEmail: 'test2@account.com', + accountID: 101, childManagerEmail: 'test2@account.com', + childManagerAccountID: 101, whisperedTo: ['test1@account.com', 'test2@account.com'], + whisperedToAccountIDs: [100, 101], childOldestFourEmails: 'test1@account.com, test2@account.com', + childOldestFourAccountIDs: [100, 101], }, 2: { - reportActionID: '2', + reportActionID: '1', originalMessage: { oldLogin: 'test1@account.com', + oldAccountID: 100, newLogin: 'test2@account.com', + newAccountID: 101, participants: ['test1@account.com', 'test2@account.com'], + participantAccountIDs: [100, 101], }, actorEmail: 'test2@account.com', + actorAccountID: 101, accountEmail: 'test2@account.com', - childManagerEmail: 'non-existent@account.com', + accountID: 101, + childManagerEmail: 'test2@account.com', whisperedTo: ['test1@account.com', 'test2@account.com'], + whisperedToAccountIDs: [100, 101], childOldestFourEmails: 'test1@account.com, test2@account.com', + childOldestFourAccountIDs: [100, 101], }, }, }) @@ -580,44 +605,49 @@ describe('Migrations', () => { }); })); - it('Should remove any individual reportActions that have whisperedTo but the matching accountID is not found', () => + it('Should remove any individual reportActions that have whisperedTo but not whisperedToAccountIDs', () => Onyx.multiSet({ - [`${DEPRECATED_ONYX_KEYS.PERSONAL_DETAILS}`]: { - 'test1@account.com': { - accountID: 100, - login: 'test1@account.com', - }, - 'test2@account.com': { - accountID: 101, - login: 'test2@account.com', - }, - }, [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]: { 1: { reportActionID: '1', originalMessage: { oldLogin: 'test1@account.com', + oldAccountID: 100, newLogin: 'test2@account.com', + newAccountID: 101, participants: ['test1@account.com', 'test2@account.com'], + participantAccountIDs: [100, 101], }, actorEmail: 'test2@account.com', + actorAccountID: 101, accountEmail: 'test2@account.com', + accountID: 101, childManagerEmail: 'test2@account.com', + childManagerAccountID: 101, whisperedTo: ['test1@account.com', 'test2@account.com'], + whisperedToAccountIDs: [100, 101], childOldestFourEmails: 'test1@account.com, test2@account.com', + childOldestFourAccountIDs: [100, 101], }, 2: { - reportActionID: '2', + reportActionID: '1', originalMessage: { oldLogin: 'test1@account.com', + oldAccountID: 100, newLogin: 'test2@account.com', + newAccountID: 101, participants: ['test1@account.com', 'test2@account.com'], + participantAccountIDs: [100, 101], }, actorEmail: 'test2@account.com', + actorAccountID: 101, accountEmail: 'test2@account.com', + accountID: 101, childManagerEmail: 'test2@account.com', - whisperedTo: ['test1@account.com', 'non-existent@account.com'], + childManagerAccountID: 101, + whisperedTo: ['test1@account.com', 'test2@account.com'], childOldestFourEmails: 'test1@account.com, test2@account.com', + childOldestFourAccountIDs: [100, 101], }, }, }) @@ -635,44 +665,49 @@ describe('Migrations', () => { }); })); - it('Should remove any individual reportActions that have childOldestFourEmails but the matching accountID is not found', () => + it('Should remove any individual reportActions that have childOldestFourEmails but not childOldestFourAccountIDs', () => Onyx.multiSet({ - [`${DEPRECATED_ONYX_KEYS.PERSONAL_DETAILS}`]: { - 'test1@account.com': { - accountID: 100, - login: 'test1@account.com', - }, - 'test2@account.com': { - accountID: 101, - login: 'test2@account.com', - }, - }, [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]: { 1: { reportActionID: '1', originalMessage: { oldLogin: 'test1@account.com', + oldAccountID: 100, newLogin: 'test2@account.com', + newAccountID: 101, participants: ['test1@account.com', 'test2@account.com'], + participantAccountIDs: [100, 101], }, actorEmail: 'test2@account.com', + actorAccountID: 101, accountEmail: 'test2@account.com', + accountID: 101, childManagerEmail: 'test2@account.com', + childManagerAccountID: 101, whisperedTo: ['test1@account.com', 'test2@account.com'], + whisperedToAccountIDs: [100, 101], childOldestFourEmails: 'test1@account.com, test2@account.com', + childOldestFourAccountIDs: [100, 101], }, 2: { - reportActionID: '2', + reportActionID: '1', originalMessage: { oldLogin: 'test1@account.com', + oldAccountID: 100, newLogin: 'test2@account.com', + newAccountID: 101, participants: ['test1@account.com', 'test2@account.com'], + participantAccountIDs: [100, 101], }, actorEmail: 'test2@account.com', + actorAccountID: 101, accountEmail: 'test2@account.com', + accountID: 101, childManagerEmail: 'test2@account.com', + childManagerAccountID: 101, whisperedTo: ['test1@account.com', 'test2@account.com'], - childOldestFourEmails: 'test1@account.com, non-existent@account.com', + whisperedToAccountIDs: [100, 101], + childOldestFourEmails: 'test1@account.com, test2@account.com', }, }, }) @@ -690,44 +725,49 @@ describe('Migrations', () => { }); })); - it('Should remove any individual reportActions that have originalMessage.participants but the matching accountID is not found', () => + it('Should remove any individual reportActions that have originalMessage.participants but not originalMessage.participantAccountIDs', () => Onyx.multiSet({ - [`${DEPRECATED_ONYX_KEYS.PERSONAL_DETAILS}`]: { - 'test1@account.com': { - accountID: 100, - login: 'test1@account.com', - }, - 'test2@account.com': { - accountID: 101, - login: 'test2@account.com', - }, - }, [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]: { 1: { reportActionID: '1', originalMessage: { oldLogin: 'test1@account.com', + oldAccountID: 100, newLogin: 'test2@account.com', + newAccountID: 101, participants: ['test1@account.com', 'test2@account.com'], + participantAccountIDs: [100, 101], }, actorEmail: 'test2@account.com', + actorAccountID: 101, accountEmail: 'test2@account.com', + accountID: 101, childManagerEmail: 'test2@account.com', + childManagerAccountID: 101, whisperedTo: ['test1@account.com', 'test2@account.com'], + whisperedToAccountIDs: [100, 101], childOldestFourEmails: 'test1@account.com, test2@account.com', + childOldestFourAccountIDs: [100, 101], }, 2: { - reportActionID: '2', + reportActionID: '1', originalMessage: { oldLogin: 'test1@account.com', + oldAccountID: 100, newLogin: 'test2@account.com', - participants: ['test1@account.com', 'non-existent@account.com'], + newAccountID: 101, + participants: ['test1@account.com', 'test2@account.com'], }, actorEmail: 'test2@account.com', + actorAccountID: 101, accountEmail: 'test2@account.com', + accountID: 101, childManagerEmail: 'test2@account.com', + childManagerAccountID: 101, whisperedTo: ['test1@account.com', 'test2@account.com'], + whisperedToAccountIDs: [100, 101], childOldestFourEmails: 'test1@account.com, test2@account.com', + childOldestFourAccountIDs: [100, 101], }, }, }) @@ -747,31 +787,29 @@ describe('Migrations', () => { }); })); - it('Should succeed in adding all relevant accountID data if it can be found in personalDetails', () => + it('Should succeed in removing all email data when equivalent accountID data exists', () => Onyx.multiSet({ - [`${DEPRECATED_ONYX_KEYS.PERSONAL_DETAILS}`]: { - 'test1@account.com': { - accountID: 100, - login: 'test1@account.com', - }, - 'test2@account.com': { - accountID: 101, - login: 'test2@account.com', - }, - }, [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]: { 1: { reportActionID: '1', originalMessage: { oldLogin: 'test1@account.com', + oldAccountID: 100, newLogin: 'test2@account.com', + newAccountID: 101, participants: ['test1@account.com', 'test2@account.com'], + participantAccountIDs: [100, 101], }, actorEmail: 'test2@account.com', + actorAccountID: 101, accountEmail: 'test2@account.com', + accountID: 101, childManagerEmail: 'test2@account.com', + childManagerAccountID: 101, whisperedTo: ['test1@account.com', 'test2@account.com'], + whisperedToAccountIDs: [100, 101], childOldestFourEmails: 'test1@account.com, test2@account.com', + childOldestFourAccountIDs: [100, 101], }, }, }) @@ -785,23 +823,15 @@ describe('Migrations', () => { const expectedReportAction = { reportActionID: '1', originalMessage: { - oldLogin: 'test1@account.com', oldAccountID: 100, - newLogin: 'test2@account.com', newAccountID: 101, - participants: ['test1@account.com', 'test2@account.com'], participantAccountIDs: [100, 101], }, - actorEmail: 'test2@account.com', actorAccountID: 101, - accountEmail: 'test2@account.com', accountID: 101, - childManagerEmail: 'test2@account.com', childManagerAccountID: 101, - whisperedTo: ['test1@account.com', 'test2@account.com'], whisperedToAccountIDs: [100, 101], - childOldestFourEmails: 'test1@account.com, test2@account.com', - childOldestFourAccountIDs: '100,101', + childOldestFourAccountIDs: [100, 101], }; expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`][1]).toMatchObject(expectedReportAction); }, From 84607ca1220dd97107891f0b684a7be8bdf26e80 Mon Sep 17 00:00:00 2001 From: Puneet Lath Date: Fri, 7 Jul 2023 12:08:46 -0400 Subject: [PATCH 3/5] Update tests to be less unnecessarily verbose --- tests/unit/MigrationTest.js | 262 ------------------------------------ 1 file changed, 262 deletions(-) diff --git a/tests/unit/MigrationTest.js b/tests/unit/MigrationTest.js index 7f1548a61015..54ad79db14c7 100644 --- a/tests/unit/MigrationTest.js +++ b/tests/unit/MigrationTest.js @@ -309,45 +309,15 @@ describe('Migrations', () => { Onyx.multiSet({ [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]: { 1: { - reportActionID: '1', originalMessage: { oldLogin: 'test1@account.com', oldAccountID: 100, - newLogin: 'test2@account.com', - newAccountID: 101, - participants: ['test1@account.com', 'test2@account.com'], - participantAccountIDs: [100, 101], }, - actorEmail: 'test2@account.com', - actorAccountID: 101, - accountEmail: 'test2@account.com', - accountID: 101, - childManagerEmail: 'test2@account.com', - childManagerAccountID: 101, - whisperedTo: ['test1@account.com', 'test2@account.com'], - whisperedToAccountIDs: [100, 101], - childOldestFourEmails: 'test1@account.com, test2@account.com', - childOldestFourAccountIDs: [100, 101], }, 2: { - reportActionID: '1', originalMessage: { oldLogin: 'test1@account.com', - newLogin: 'test2@account.com', - newAccountID: 101, - participants: ['test1@account.com', 'test2@account.com'], - participantAccountIDs: [100, 101], }, - actorEmail: 'test2@account.com', - actorAccountID: 101, - accountEmail: 'test2@account.com', - accountID: 101, - childManagerEmail: 'test2@account.com', - childManagerAccountID: 101, - whisperedTo: ['test1@account.com', 'test2@account.com'], - whisperedToAccountIDs: [100, 101], - childOldestFourEmails: 'test1@account.com, test2@account.com', - childOldestFourAccountIDs: [100, 101], }, }, }) @@ -369,45 +339,15 @@ describe('Migrations', () => { Onyx.multiSet({ [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]: { 1: { - reportActionID: '1', originalMessage: { - oldLogin: 'test1@account.com', - oldAccountID: 100, newLogin: 'test2@account.com', newAccountID: 101, - participants: ['test1@account.com', 'test2@account.com'], - participantAccountIDs: [100, 101], }, - actorEmail: 'test2@account.com', - actorAccountID: 101, - accountEmail: 'test2@account.com', - accountID: 101, - childManagerEmail: 'test2@account.com', - childManagerAccountID: 101, - whisperedTo: ['test1@account.com', 'test2@account.com'], - whisperedToAccountIDs: [100, 101], - childOldestFourEmails: 'test1@account.com, test2@account.com', - childOldestFourAccountIDs: [100, 101], }, 2: { - reportActionID: '1', originalMessage: { - oldLogin: 'test1@account.com', - oldAccountID: 100, newLogin: 'test2@account.com', - participants: ['test1@account.com', 'test2@account.com'], - participantAccountIDs: [100, 101], }, - actorEmail: 'test2@account.com', - actorAccountID: 101, - accountEmail: 'test2@account.com', - accountID: 101, - childManagerEmail: 'test2@account.com', - childManagerAccountID: 101, - whisperedTo: ['test1@account.com', 'test2@account.com'], - whisperedToAccountIDs: [100, 101], - childOldestFourEmails: 'test1@account.com, test2@account.com', - childOldestFourAccountIDs: [100, 101], }, }, }) @@ -429,45 +369,11 @@ describe('Migrations', () => { Onyx.multiSet({ [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]: { 1: { - reportActionID: '1', - originalMessage: { - oldLogin: 'test1@account.com', - oldAccountID: 100, - newLogin: 'test2@account.com', - newAccountID: 101, - participants: ['test1@account.com', 'test2@account.com'], - participantAccountIDs: [100, 101], - }, - actorEmail: 'test2@account.com', - actorAccountID: 101, accountEmail: 'test2@account.com', accountID: 101, - childManagerEmail: 'test2@account.com', - childManagerAccountID: 101, - whisperedTo: ['test1@account.com', 'test2@account.com'], - whisperedToAccountIDs: [100, 101], - childOldestFourEmails: 'test1@account.com, test2@account.com', - childOldestFourAccountIDs: [100, 101], }, 2: { - reportActionID: '1', - originalMessage: { - oldLogin: 'test1@account.com', - oldAccountID: 100, - newLogin: 'test2@account.com', - newAccountID: 101, - participants: ['test1@account.com', 'test2@account.com'], - participantAccountIDs: [100, 101], - }, - actorEmail: 'test2@account.com', - actorAccountID: 101, accountEmail: 'test2@account.com', - childManagerEmail: 'test2@account.com', - childManagerAccountID: 101, - whisperedTo: ['test1@account.com', 'test2@account.com'], - whisperedToAccountIDs: [100, 101], - childOldestFourEmails: 'test1@account.com, test2@account.com', - childOldestFourAccountIDs: [100, 101], }, }, }) @@ -489,45 +395,11 @@ describe('Migrations', () => { Onyx.multiSet({ [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]: { 1: { - reportActionID: '1', - originalMessage: { - oldLogin: 'test1@account.com', - oldAccountID: 100, - newLogin: 'test2@account.com', - newAccountID: 101, - participants: ['test1@account.com', 'test2@account.com'], - participantAccountIDs: [100, 101], - }, actorEmail: 'test2@account.com', actorAccountID: 101, - accountEmail: 'test2@account.com', - accountID: 101, - childManagerEmail: 'test2@account.com', - childManagerAccountID: 101, - whisperedTo: ['test1@account.com', 'test2@account.com'], - whisperedToAccountIDs: [100, 101], - childOldestFourEmails: 'test1@account.com, test2@account.com', - childOldestFourAccountIDs: [100, 101], }, 2: { - reportActionID: '1', - originalMessage: { - oldLogin: 'test1@account.com', - oldAccountID: 100, - newLogin: 'test2@account.com', - newAccountID: 101, - participants: ['test1@account.com', 'test2@account.com'], - participantAccountIDs: [100, 101], - }, actorEmail: 'test2@account.com', - accountEmail: 'test2@account.com', - accountID: 101, - childManagerEmail: 'test2@account.com', - childManagerAccountID: 101, - whisperedTo: ['test1@account.com', 'test2@account.com'], - whisperedToAccountIDs: [100, 101], - childOldestFourEmails: 'test1@account.com, test2@account.com', - childOldestFourAccountIDs: [100, 101], }, }, }) @@ -549,45 +421,11 @@ describe('Migrations', () => { Onyx.multiSet({ [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]: { 1: { - reportActionID: '1', - originalMessage: { - oldLogin: 'test1@account.com', - oldAccountID: 100, - newLogin: 'test2@account.com', - newAccountID: 101, - participants: ['test1@account.com', 'test2@account.com'], - participantAccountIDs: [100, 101], - }, - actorEmail: 'test2@account.com', - actorAccountID: 101, - accountEmail: 'test2@account.com', - accountID: 101, childManagerEmail: 'test2@account.com', childManagerAccountID: 101, - whisperedTo: ['test1@account.com', 'test2@account.com'], - whisperedToAccountIDs: [100, 101], - childOldestFourEmails: 'test1@account.com, test2@account.com', - childOldestFourAccountIDs: [100, 101], }, 2: { - reportActionID: '1', - originalMessage: { - oldLogin: 'test1@account.com', - oldAccountID: 100, - newLogin: 'test2@account.com', - newAccountID: 101, - participants: ['test1@account.com', 'test2@account.com'], - participantAccountIDs: [100, 101], - }, - actorEmail: 'test2@account.com', - actorAccountID: 101, - accountEmail: 'test2@account.com', - accountID: 101, childManagerEmail: 'test2@account.com', - whisperedTo: ['test1@account.com', 'test2@account.com'], - whisperedToAccountIDs: [100, 101], - childOldestFourEmails: 'test1@account.com, test2@account.com', - childOldestFourAccountIDs: [100, 101], }, }, }) @@ -609,45 +447,11 @@ describe('Migrations', () => { Onyx.multiSet({ [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]: { 1: { - reportActionID: '1', - originalMessage: { - oldLogin: 'test1@account.com', - oldAccountID: 100, - newLogin: 'test2@account.com', - newAccountID: 101, - participants: ['test1@account.com', 'test2@account.com'], - participantAccountIDs: [100, 101], - }, - actorEmail: 'test2@account.com', - actorAccountID: 101, - accountEmail: 'test2@account.com', - accountID: 101, - childManagerEmail: 'test2@account.com', - childManagerAccountID: 101, whisperedTo: ['test1@account.com', 'test2@account.com'], whisperedToAccountIDs: [100, 101], - childOldestFourEmails: 'test1@account.com, test2@account.com', - childOldestFourAccountIDs: [100, 101], }, 2: { - reportActionID: '1', - originalMessage: { - oldLogin: 'test1@account.com', - oldAccountID: 100, - newLogin: 'test2@account.com', - newAccountID: 101, - participants: ['test1@account.com', 'test2@account.com'], - participantAccountIDs: [100, 101], - }, - actorEmail: 'test2@account.com', - actorAccountID: 101, - accountEmail: 'test2@account.com', - accountID: 101, - childManagerEmail: 'test2@account.com', - childManagerAccountID: 101, whisperedTo: ['test1@account.com', 'test2@account.com'], - childOldestFourEmails: 'test1@account.com, test2@account.com', - childOldestFourAccountIDs: [100, 101], }, }, }) @@ -669,44 +473,10 @@ describe('Migrations', () => { Onyx.multiSet({ [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]: { 1: { - reportActionID: '1', - originalMessage: { - oldLogin: 'test1@account.com', - oldAccountID: 100, - newLogin: 'test2@account.com', - newAccountID: 101, - participants: ['test1@account.com', 'test2@account.com'], - participantAccountIDs: [100, 101], - }, - actorEmail: 'test2@account.com', - actorAccountID: 101, - accountEmail: 'test2@account.com', - accountID: 101, - childManagerEmail: 'test2@account.com', - childManagerAccountID: 101, - whisperedTo: ['test1@account.com', 'test2@account.com'], - whisperedToAccountIDs: [100, 101], childOldestFourEmails: 'test1@account.com, test2@account.com', childOldestFourAccountIDs: [100, 101], }, 2: { - reportActionID: '1', - originalMessage: { - oldLogin: 'test1@account.com', - oldAccountID: 100, - newLogin: 'test2@account.com', - newAccountID: 101, - participants: ['test1@account.com', 'test2@account.com'], - participantAccountIDs: [100, 101], - }, - actorEmail: 'test2@account.com', - actorAccountID: 101, - accountEmail: 'test2@account.com', - accountID: 101, - childManagerEmail: 'test2@account.com', - childManagerAccountID: 101, - whisperedTo: ['test1@account.com', 'test2@account.com'], - whisperedToAccountIDs: [100, 101], childOldestFourEmails: 'test1@account.com, test2@account.com', }, }, @@ -729,45 +499,15 @@ describe('Migrations', () => { Onyx.multiSet({ [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]: { 1: { - reportActionID: '1', originalMessage: { - oldLogin: 'test1@account.com', - oldAccountID: 100, - newLogin: 'test2@account.com', - newAccountID: 101, participants: ['test1@account.com', 'test2@account.com'], participantAccountIDs: [100, 101], }, - actorEmail: 'test2@account.com', - actorAccountID: 101, - accountEmail: 'test2@account.com', - accountID: 101, - childManagerEmail: 'test2@account.com', - childManagerAccountID: 101, - whisperedTo: ['test1@account.com', 'test2@account.com'], - whisperedToAccountIDs: [100, 101], - childOldestFourEmails: 'test1@account.com, test2@account.com', - childOldestFourAccountIDs: [100, 101], }, 2: { - reportActionID: '1', originalMessage: { - oldLogin: 'test1@account.com', - oldAccountID: 100, - newLogin: 'test2@account.com', - newAccountID: 101, participants: ['test1@account.com', 'test2@account.com'], }, - actorEmail: 'test2@account.com', - actorAccountID: 101, - accountEmail: 'test2@account.com', - accountID: 101, - childManagerEmail: 'test2@account.com', - childManagerAccountID: 101, - whisperedTo: ['test1@account.com', 'test2@account.com'], - whisperedToAccountIDs: [100, 101], - childOldestFourEmails: 'test1@account.com, test2@account.com', - childOldestFourAccountIDs: [100, 101], }, }, }) @@ -791,7 +531,6 @@ describe('Migrations', () => { Onyx.multiSet({ [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]: { 1: { - reportActionID: '1', originalMessage: { oldLogin: 'test1@account.com', oldAccountID: 100, @@ -821,7 +560,6 @@ describe('Migrations', () => { callback: (allReportActions) => { Onyx.disconnect(connectionID); const expectedReportAction = { - reportActionID: '1', originalMessage: { oldAccountID: 100, newAccountID: 101, From 1ba5a4563c84ac3716392cc588de8567a0516786 Mon Sep 17 00:00:00 2001 From: Puneet Lath Date: Fri, 7 Jul 2023 12:09:13 -0400 Subject: [PATCH 4/5] Update comments for updated approach --- .../migrations/PersonalDetailsByAccountID.js | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/libs/migrations/PersonalDetailsByAccountID.js b/src/libs/migrations/PersonalDetailsByAccountID.js index 7325fc073bab..a4f97e77a27d 100644 --- a/src/libs/migrations/PersonalDetailsByAccountID.js +++ b/src/libs/migrations/PersonalDetailsByAccountID.js @@ -62,6 +62,8 @@ function getDeprecatedPolicyMemberListFromOnyx() { /** * Migrate Onyx data for the email to accountID migration. * + * - personalDetails -> personalDetailsList + * - policyMemberList_ -> policyMembers_ * - reportAction_ * - originalMessage.oldLogin -> originalMessage.oldAccountID * - originalMessage.newLogin -> originalMessage.newAccountID @@ -79,6 +81,13 @@ export default function () { ([oldReportActions, oldPersonalDetails, oldPolicyMemberList]) => { const onyxData = {}; + // The personalDetails object has been replaced by personalDetailsList + // So if we find an instance of personalDetails we will clear it out + if (oldPersonalDetails) { + Log.info('[Migrate Onyx] PersonalDetailsByAccountID migration: removing personalDetails'); + onyxData[DEPRECATED_ONYX_KEYS.PERSONAL_DETAILS] = null; + } + // The policyMemberList_ collection has been replaced by policyMembers_ // So if we find any instances of policyMemberList_ we will clear them out _.each(oldPolicyMemberList, (_policyMembersForPolicy, policyKey) => { @@ -86,8 +95,8 @@ export default function () { onyxData[policyKey] = null; }); - // We migrate reportActions to have the new accountID-based data if they don't already. - // If we are not able to get the accountID from personalDetails for some reason, we will just clear the reportAction + // We migrate reportActions to remove old email-based data. + // If we do not find the equivalent accountID-based data in the reportAction, we will just clear the reportAction // and let it be fetched from the API next time they open the report and scroll to that action. // We do this because we know the reportAction from the API will include the needed accountID data. _.each(oldReportActions, (reportActionsForReport, onyxKey) => { @@ -203,13 +212,6 @@ export default function () { } }); - // The personalDetails object has been replaced by personalDetailsList - // So if we find an instance of personalDetails we will clear it out - if (oldPersonalDetails) { - Log.info('[Migrate Onyx] PersonalDetailsByAccountID migration: removing personalDetails'); - onyxData[DEPRECATED_ONYX_KEYS.PERSONAL_DETAILS] = null; - } - return Onyx.multiSet(onyxData); }, ); From 6bca6026f4b78b6751a4486c4543e084bb05f8cb Mon Sep 17 00:00:00 2001 From: Puneet Lath Date: Fri, 7 Jul 2023 12:16:12 -0400 Subject: [PATCH 5/5] Correct childOldestFourAccountIDs to be string --- tests/unit/MigrationTest.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/unit/MigrationTest.js b/tests/unit/MigrationTest.js index 54ad79db14c7..af7f39ddf828 100644 --- a/tests/unit/MigrationTest.js +++ b/tests/unit/MigrationTest.js @@ -474,7 +474,7 @@ describe('Migrations', () => { [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]: { 1: { childOldestFourEmails: 'test1@account.com, test2@account.com', - childOldestFourAccountIDs: [100, 101], + childOldestFourAccountIDs: '100,101', }, 2: { childOldestFourEmails: 'test1@account.com, test2@account.com', @@ -548,7 +548,7 @@ describe('Migrations', () => { whisperedTo: ['test1@account.com', 'test2@account.com'], whisperedToAccountIDs: [100, 101], childOldestFourEmails: 'test1@account.com, test2@account.com', - childOldestFourAccountIDs: [100, 101], + childOldestFourAccountIDs: '100,101', }, }, }) @@ -569,7 +569,7 @@ describe('Migrations', () => { accountID: 101, childManagerAccountID: 101, whisperedToAccountIDs: [100, 101], - childOldestFourAccountIDs: [100, 101], + childOldestFourAccountIDs: '100,101', }; expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`][1]).toMatchObject(expectedReportAction); },