From 5a6807fea9ee53b6439c8dc221bc2e63eb7ef8ab Mon Sep 17 00:00:00 2001 From: Puneet Lath Date: Tue, 27 Jun 2023 11:47:57 -0400 Subject: [PATCH 1/4] Connect to policy member list deprecated key --- .../migrations/PersonalDetailsByAccountID.js | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/libs/migrations/PersonalDetailsByAccountID.js b/src/libs/migrations/PersonalDetailsByAccountID.js index 8716f063357e..0ceebb8bfe0c 100644 --- a/src/libs/migrations/PersonalDetailsByAccountID.js +++ b/src/libs/migrations/PersonalDetailsByAccountID.js @@ -7,6 +7,11 @@ import Log from '../Log'; const DEPRECATED_ONYX_KEYS = { // Deprecated personal details object which was keyed by login instead of accountID. PERSONAL_DETAILS: 'personalDetails', + + // Deprecated policy member list object which was keyed by login instead of accountID. + COLLECTION: { + POLICY_MEMBER_LIST: 'policyMemberList_', + }, }; /** @@ -43,6 +48,22 @@ function getDeprecatedPersonalDetailsFromOnyx() { }); } +/** + * @returns {Promise} + */ +function getDeprecatedPolicyMemberListFromOnyx() { + return new Promise((resolve) => { + const connectionID = Onyx.connect({ + key: DEPRECATED_ONYX_KEYS.COLLECTION.POLICY_MEMBER_LIST, + waitForCollectionCallback: true, + callback: (allPolicyMembers) => { + Onyx.disconnect(connectionID); + return resolve(allPolicyMembers); + }, + }); + }); +} + /** * Migrate Onyx data for the email to accountID migration. * @@ -59,9 +80,17 @@ function getDeprecatedPersonalDetailsFromOnyx() { * @returns {Promise} */ export default function () { - return Promise.all([getReportActionsFromOnyx(), getDeprecatedPersonalDetailsFromOnyx()]).then(([oldReportActions, oldPersonalDetails]) => { + return Promise.all([getReportActionsFromOnyx(), getDeprecatedPersonalDetailsFromOnyx(), getDeprecatedPolicyMemberListFromOnyx()]).then(([oldReportActions, oldPersonalDetails, oldPolicyMembers]) => { const onyxData = {}; + console.log('puneetlath', oldReportActions); + console.log('puneetlath', oldPersonalDetails); + console.log('puneetlath', oldPolicyMembers); + _.each(oldPolicyMembers, (_policyMembersForPolicy, policyKey) => { + console.log('puneetlath', policyKey); + onyxData[policyKey] = null; + }); + if (!oldReportActions) { Log.info('[Migrate Onyx] Skipped migration PersonalDetailsByAccountID because there were no reportActions'); return; From a7481839bb3f36800dabfc680cd9a9b6b15b5fd6 Mon Sep 17 00:00:00 2001 From: Puneet Lath Date: Tue, 27 Jun 2023 16:59:18 -0400 Subject: [PATCH 2/4] Fix onyx key for deprecated policy member list --- src/ONYXKEYS.js | 3 + .../migrations/PersonalDetailsByAccountID.js | 242 +++++++++--------- tests/unit/MigrationTest.js | 2 +- 3 files changed, 123 insertions(+), 124 deletions(-) diff --git a/src/ONYXKEYS.js b/src/ONYXKEYS.js index b04687967dfc..823ad7028a94 100755 --- a/src/ONYXKEYS.js +++ b/src/ONYXKEYS.js @@ -122,6 +122,9 @@ export default { REPORT_USER_IS_TYPING: 'reportUserIsTyping_', SECURITY_GROUP: 'securityGroup_', TRANSACTION: 'transactions_', + + // This is deprecated, but needed for a migration, so we still need to include it here so that it will be initialized in Onyx.init + DEPRECATED_POLICY_MEMBER_LIST: 'policyMemberList_', }, // Indicates which locale should be used diff --git a/src/libs/migrations/PersonalDetailsByAccountID.js b/src/libs/migrations/PersonalDetailsByAccountID.js index 0ceebb8bfe0c..e20437f2d2d3 100644 --- a/src/libs/migrations/PersonalDetailsByAccountID.js +++ b/src/libs/migrations/PersonalDetailsByAccountID.js @@ -7,11 +7,6 @@ import Log from '../Log'; const DEPRECATED_ONYX_KEYS = { // Deprecated personal details object which was keyed by login instead of accountID. PERSONAL_DETAILS: 'personalDetails', - - // Deprecated policy member list object which was keyed by login instead of accountID. - COLLECTION: { - POLICY_MEMBER_LIST: 'policyMemberList_', - }, }; /** @@ -54,7 +49,7 @@ function getDeprecatedPersonalDetailsFromOnyx() { function getDeprecatedPolicyMemberListFromOnyx() { return new Promise((resolve) => { const connectionID = Onyx.connect({ - key: DEPRECATED_ONYX_KEYS.COLLECTION.POLICY_MEMBER_LIST, + key: ONYXKEYS.COLLECTION.DEPRECATED_POLICY_MEMBER_LIST, waitForCollectionCallback: true, callback: (allPolicyMembers) => { Onyx.disconnect(connectionID); @@ -86,156 +81,157 @@ export default function () { console.log('puneetlath', oldReportActions); console.log('puneetlath', oldPersonalDetails); console.log('puneetlath', oldPolicyMembers); + // The policyMemberList_ collection has been replaced by policyMembers_ + // So if we find any instances of policyMemberList_ we will clear them out _.each(oldPolicyMembers, (_policyMembersForPolicy, policyKey) => { - console.log('puneetlath', policyKey); + Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing policyMemberList ${policyKey}`); onyxData[policyKey] = null; }); - if (!oldReportActions) { - Log.info('[Migrate Onyx] Skipped migration PersonalDetailsByAccountID because there were no reportActions'); - return; - } - // 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 // 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) => { - if (_.isEmpty(reportActionsForReport)) { - Log.info(`[Migrate Onyx] Skipped migration PersonalDetailsByAccountID for ${onyxKey} because there were no reportActions`); - return; - } - - const newReportActionsForReport = {}; - let reportActionsWereModified = false; - _.each(reportActionsForReport, (reportAction, reportActionID) => { - if (_.isEmpty(reportAction)) { - reportActionsWereModified = true; - Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because the reportAction was empty`); + if (!oldReportActions) { + Log.info('[Migrate Onyx] Skipped PersonalDetailsByAccountID reportActions migration because there were no reportActions'); + } else { + _.each(oldReportActions, (reportActionsForReport, onyxKey) => { + if (_.isEmpty(reportActionsForReport)) { + Log.info(`[Migrate Onyx] Skipped migration PersonalDetailsByAccountID for ${onyxKey} because there were no reportActions`); return; } - const newReportAction = reportAction; - - if (lodashHas(reportAction, ['originalMessage', 'oldLogin']) && !lodashHas(reportAction, ['originalMessage', 'oldAccountID'])) { - reportActionsWereModified = true; - const oldAccountID = _.get(oldPersonalDetails, [reportAction.originalMessage.oldLogin, 'accountID']); - if (oldAccountID) { - newReportAction.originalMessage.oldAccountID = oldAccountID; - } else { - Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because originalMessage.oldAccountID not found`); + const newReportActionsForReport = {}; + let reportActionsWereModified = false; + _.each(reportActionsForReport, (reportAction, reportActionID) => { + if (_.isEmpty(reportAction)) { + reportActionsWereModified = true; + Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because the reportAction was empty`); return; } - } - if (lodashHas(reportAction, ['originalMessage', 'newLogin']) && !lodashHas(reportAction, ['originalMessage', 'newAccountID'])) { - reportActionsWereModified = true; - const newAccountID = _.get(oldPersonalDetails, [reportAction.originalMessage.newLogin, 'accountID']); - if (newAccountID) { - newReportAction.originalMessage.newAccountID = newAccountID; - } else { - Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because originalMessage.newAccountID not found`); - return; - } - } + const newReportAction = reportAction; - if (lodashHas(reportAction, ['accountEmail']) && !lodashHas(reportAction, ['accountID'])) { - reportActionsWereModified = true; - const accountID = _.get(oldPersonalDetails, [reportAction.accountEmail, 'accountID']); - if (accountID) { - newReportAction.accountID = accountID; - } else { - Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because accountID not found`); - return; + if (lodashHas(reportAction, ['originalMessage', 'oldLogin']) && !lodashHas(reportAction, ['originalMessage', 'oldAccountID'])) { + reportActionsWereModified = true; + const oldAccountID = _.get(oldPersonalDetails, [reportAction.originalMessage.oldLogin, 'accountID']); + if (oldAccountID) { + newReportAction.originalMessage.oldAccountID = oldAccountID; + } else { + Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because originalMessage.oldAccountID not found`); + return; + } } - } - if (lodashHas(reportAction, ['actorEmail']) && !lodashHas(reportAction, ['actorAccountID'])) { - reportActionsWereModified = true; - const actorAccountID = _.get(oldPersonalDetails, [reportAction.actorEmail, 'accountID']); - if (actorAccountID) { - newReportAction.actorAccountID = actorAccountID; - } else { - Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because actorAccountID not found`); - return; + if (lodashHas(reportAction, ['originalMessage', 'newLogin']) && !lodashHas(reportAction, ['originalMessage', 'newAccountID'])) { + reportActionsWereModified = true; + const newAccountID = _.get(oldPersonalDetails, [reportAction.originalMessage.newLogin, 'accountID']); + if (newAccountID) { + newReportAction.originalMessage.newAccountID = newAccountID; + } else { + Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because originalMessage.newAccountID not found`); + return; + } } - } - if (lodashHas(reportAction, ['childManagerEmail']) && !lodashHas(reportAction, ['childManagerAccountID'])) { - reportActionsWereModified = true; - const childManagerAccountID = _.get(oldPersonalDetails, [reportAction.childManagerEmail, 'accountID']); - if (childManagerAccountID) { - newReportAction.childManagerAccountID = childManagerAccountID; - } else { - Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because childManagerAccountID not found`); - return; + if (lodashHas(reportAction, ['accountEmail']) && !lodashHas(reportAction, ['accountID'])) { + reportActionsWereModified = true; + const accountID = _.get(oldPersonalDetails, [reportAction.accountEmail, 'accountID']); + if (accountID) { + newReportAction.accountID = accountID; + } else { + Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because accountID not found`); + return; + } } - } - if (lodashHas(reportAction, ['whisperedTo']) && !lodashHas(reportAction, ['whisperedToAccountIDs'])) { - reportActionsWereModified = true; - const whisperedToAccountIDs = []; - _.each(reportAction.whisperedTo, (whisperedToLogin) => { - const whisperedToAccountID = _.get(oldPersonalDetails, [whisperedToLogin, 'accountID']); - if (whisperedToAccountID) { - whisperedToAccountIDs.push(whisperedToAccountID); + if (lodashHas(reportAction, ['actorEmail']) && !lodashHas(reportAction, ['actorAccountID'])) { + reportActionsWereModified = true; + const actorAccountID = _.get(oldPersonalDetails, [reportAction.actorEmail, 'accountID']); + if (actorAccountID) { + newReportAction.actorAccountID = actorAccountID; + } else { + Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because actorAccountID not found`); + return; } - }); - - if (whisperedToAccountIDs.length === reportAction.whisperedTo.length) { - newReportAction.whisperedToAccountIDs = whisperedToAccountIDs; - } else { - Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because whisperedToAccountIDs not found`); - return; } - } - if (lodashHas(reportAction, ['childOldestFourEmails']) && !lodashHas(reportAction, ['childOldestFourAccountIDs'])) { - 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 (lodashHas(reportAction, ['childManagerEmail']) && !lodashHas(reportAction, ['childManagerAccountID'])) { + reportActionsWereModified = true; + const childManagerAccountID = _.get(oldPersonalDetails, [reportAction.childManagerEmail, 'accountID']); + if (childManagerAccountID) { + newReportAction.childManagerAccountID = childManagerAccountID; + } else { + Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because childManagerAccountID not found`); + return; } - }); + } - if (childOldestFourAccountIDs.length === childOldestFourEmails.length) { - newReportAction.childOldestFourAccountIDs = childOldestFourAccountIDs.join(','); - } else { - Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because childOldestFourAccountIDs not found`); - return; + if (lodashHas(reportAction, ['whisperedTo']) && !lodashHas(reportAction, ['whisperedToAccountIDs'])) { + 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; + } else { + Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because whisperedToAccountIDs not found`); + return; + } } - } - if (lodashHas(reportAction, ['originalMessage', 'participants']) && !lodashHas(reportAction, ['originalMessage', 'participantAccountIDs'])) { - reportActionsWereModified = true; - const participantAccountIDs = []; - _.each(reportAction.originalMessage.participants, (participant) => { - const participantAccountID = _.get(oldPersonalDetails, [participant, 'accountID']); - if (participantAccountID) { - participantAccountIDs.push(participantAccountID); + if (lodashHas(reportAction, ['childOldestFourEmails']) && !lodashHas(reportAction, ['childOldestFourAccountIDs'])) { + 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(','); + } else { + Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because childOldestFourAccountIDs not found`); + return; } - }); + } - if (participantAccountIDs.length === reportAction.originalMessage.participants.length) { - newReportAction.originalMessage.participantAccountIDs = participantAccountIDs; - } else { - Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because originalMessage.participantAccountIDs not found`); - return; + if (lodashHas(reportAction, ['originalMessage', 'participants']) && !lodashHas(reportAction, ['originalMessage', 'participantAccountIDs'])) { + 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; + } else { + Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because originalMessage.participantAccountIDs not found`); + return; + } } - } - newReportActionsForReport[reportActionID] = newReportAction; - }); + newReportActionsForReport[reportActionID] = newReportAction; + }); - // Only include the reportActions from this report if at least one reportAction in this report - // was modified in any way. - if (reportActionsWereModified) { - onyxData[onyxKey] = newReportActionsForReport; - } - }); + // Only include the reportActions from this report if at least one reportAction in this report + // was modified in any way. + if (reportActionsWereModified) { + onyxData[onyxKey] = newReportActionsForReport; + } + }); + } return Onyx.multiSet(onyxData); }); diff --git a/tests/unit/MigrationTest.js b/tests/unit/MigrationTest.js index e9f605699e43..7a5f264e0b30 100644 --- a/tests/unit/MigrationTest.js +++ b/tests/unit/MigrationTest.js @@ -263,7 +263,7 @@ describe('Migrations', () => { // Warning: this test has to come before the others in this suite because Onyx.clear leaves traces and keys with null values aren't cleared out between tests it("Should skip the migration if there's no reportAction data in Onyx", () => - PersonalDetailsByAccountID().then(() => expect(LogSpy).toHaveBeenCalledWith('[Migrate Onyx] Skipped migration PersonalDetailsByAccountID because there were no reportActions'))); + PersonalDetailsByAccountID().then(() => expect(LogSpy).toHaveBeenCalledWith('[Migrate Onyx] Skipped PersonalDetailsByAccountID reportActions migration because there were no reportActions'))); it('Should skip any zombie reportAction collections that have no reportAction data in Onyx', () => Onyx.multiSet({ From f955e4e010192810c78b44703751f907165e342d Mon Sep 17 00:00:00 2001 From: Puneet Lath Date: Tue, 27 Jun 2023 17:10:31 -0400 Subject: [PATCH 3/4] Add tests for policyMemberList removal --- .../migrations/PersonalDetailsByAccountID.js | 267 +++++++++--------- tests/unit/MigrationTest.js | 42 ++- 2 files changed, 175 insertions(+), 134 deletions(-) diff --git a/src/libs/migrations/PersonalDetailsByAccountID.js b/src/libs/migrations/PersonalDetailsByAccountID.js index e20437f2d2d3..68ab79a39a26 100644 --- a/src/libs/migrations/PersonalDetailsByAccountID.js +++ b/src/libs/migrations/PersonalDetailsByAccountID.js @@ -75,164 +75,165 @@ function getDeprecatedPolicyMemberListFromOnyx() { * @returns {Promise} */ export default function () { - return Promise.all([getReportActionsFromOnyx(), getDeprecatedPersonalDetailsFromOnyx(), getDeprecatedPolicyMemberListFromOnyx()]).then(([oldReportActions, oldPersonalDetails, oldPolicyMembers]) => { - const onyxData = {}; - - console.log('puneetlath', oldReportActions); - console.log('puneetlath', oldPersonalDetails); - console.log('puneetlath', oldPolicyMembers); - // The policyMemberList_ collection has been replaced by policyMembers_ - // So if we find any instances of policyMemberList_ we will clear them out - _.each(oldPolicyMembers, (_policyMembersForPolicy, policyKey) => { - Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing policyMemberList ${policyKey}`); - onyxData[policyKey] = null; - }); + return Promise.all([getReportActionsFromOnyx(), getDeprecatedPersonalDetailsFromOnyx(), getDeprecatedPolicyMemberListFromOnyx()]).then( + ([oldReportActions, oldPersonalDetails, oldPolicyMemberList]) => { + const onyxData = {}; + + // 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) => { + Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing policyMemberList ${policyKey}`); + 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 - // 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. - if (!oldReportActions) { - Log.info('[Migrate Onyx] Skipped PersonalDetailsByAccountID reportActions migration because there were no reportActions'); - } else { - _.each(oldReportActions, (reportActionsForReport, onyxKey) => { - if (_.isEmpty(reportActionsForReport)) { - Log.info(`[Migrate Onyx] Skipped migration PersonalDetailsByAccountID for ${onyxKey} because there were no reportActions`); - return; - } - - const newReportActionsForReport = {}; - let reportActionsWereModified = false; - _.each(reportActionsForReport, (reportAction, reportActionID) => { - if (_.isEmpty(reportAction)) { - reportActionsWereModified = true; - Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because the reportAction was empty`); + // 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 + // 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. + if (!oldReportActions) { + Log.info('[Migrate Onyx] Skipped PersonalDetailsByAccountID reportActions migration because there were no reportActions'); + } else { + _.each(oldReportActions, (reportActionsForReport, onyxKey) => { + if (_.isEmpty(reportActionsForReport)) { + Log.info(`[Migrate Onyx] Skipped migration PersonalDetailsByAccountID for ${onyxKey} because there were no reportActions`); return; } - const newReportAction = reportAction; - - if (lodashHas(reportAction, ['originalMessage', 'oldLogin']) && !lodashHas(reportAction, ['originalMessage', 'oldAccountID'])) { - reportActionsWereModified = true; - const oldAccountID = _.get(oldPersonalDetails, [reportAction.originalMessage.oldLogin, 'accountID']); - if (oldAccountID) { - newReportAction.originalMessage.oldAccountID = oldAccountID; - } else { - Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because originalMessage.oldAccountID not found`); + const newReportActionsForReport = {}; + let reportActionsWereModified = false; + _.each(reportActionsForReport, (reportAction, reportActionID) => { + if (_.isEmpty(reportAction)) { + reportActionsWereModified = true; + Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because the reportAction was empty`); return; } - } - if (lodashHas(reportAction, ['originalMessage', 'newLogin']) && !lodashHas(reportAction, ['originalMessage', 'newAccountID'])) { - reportActionsWereModified = true; - const newAccountID = _.get(oldPersonalDetails, [reportAction.originalMessage.newLogin, 'accountID']); - if (newAccountID) { - newReportAction.originalMessage.newAccountID = newAccountID; - } else { - Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because originalMessage.newAccountID not found`); - return; - } - } + const newReportAction = reportAction; - if (lodashHas(reportAction, ['accountEmail']) && !lodashHas(reportAction, ['accountID'])) { - reportActionsWereModified = true; - const accountID = _.get(oldPersonalDetails, [reportAction.accountEmail, 'accountID']); - if (accountID) { - newReportAction.accountID = accountID; - } else { - Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because accountID not found`); - return; + if (lodashHas(reportAction, ['originalMessage', 'oldLogin']) && !lodashHas(reportAction, ['originalMessage', 'oldAccountID'])) { + reportActionsWereModified = true; + const oldAccountID = _.get(oldPersonalDetails, [reportAction.originalMessage.oldLogin, 'accountID']); + if (oldAccountID) { + newReportAction.originalMessage.oldAccountID = oldAccountID; + } else { + Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because originalMessage.oldAccountID not found`); + return; + } } - } - if (lodashHas(reportAction, ['actorEmail']) && !lodashHas(reportAction, ['actorAccountID'])) { - reportActionsWereModified = true; - const actorAccountID = _.get(oldPersonalDetails, [reportAction.actorEmail, 'accountID']); - if (actorAccountID) { - newReportAction.actorAccountID = actorAccountID; - } else { - Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because actorAccountID not found`); - return; + if (lodashHas(reportAction, ['originalMessage', 'newLogin']) && !lodashHas(reportAction, ['originalMessage', 'newAccountID'])) { + reportActionsWereModified = true; + const newAccountID = _.get(oldPersonalDetails, [reportAction.originalMessage.newLogin, 'accountID']); + if (newAccountID) { + newReportAction.originalMessage.newAccountID = newAccountID; + } else { + Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because originalMessage.newAccountID not found`); + return; + } } - } - if (lodashHas(reportAction, ['childManagerEmail']) && !lodashHas(reportAction, ['childManagerAccountID'])) { - reportActionsWereModified = true; - const childManagerAccountID = _.get(oldPersonalDetails, [reportAction.childManagerEmail, 'accountID']); - if (childManagerAccountID) { - newReportAction.childManagerAccountID = childManagerAccountID; - } else { - Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because childManagerAccountID not found`); - return; + if (lodashHas(reportAction, ['accountEmail']) && !lodashHas(reportAction, ['accountID'])) { + reportActionsWereModified = true; + const accountID = _.get(oldPersonalDetails, [reportAction.accountEmail, 'accountID']); + if (accountID) { + newReportAction.accountID = accountID; + } else { + Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because accountID not found`); + return; + } } - } - if (lodashHas(reportAction, ['whisperedTo']) && !lodashHas(reportAction, ['whisperedToAccountIDs'])) { - reportActionsWereModified = true; - const whisperedToAccountIDs = []; - _.each(reportAction.whisperedTo, (whisperedToLogin) => { - const whisperedToAccountID = _.get(oldPersonalDetails, [whisperedToLogin, 'accountID']); - if (whisperedToAccountID) { - whisperedToAccountIDs.push(whisperedToAccountID); + if (lodashHas(reportAction, ['actorEmail']) && !lodashHas(reportAction, ['actorAccountID'])) { + reportActionsWereModified = true; + const actorAccountID = _.get(oldPersonalDetails, [reportAction.actorEmail, 'accountID']); + if (actorAccountID) { + newReportAction.actorAccountID = actorAccountID; + } else { + Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because actorAccountID not found`); + return; } - }); - - if (whisperedToAccountIDs.length === reportAction.whisperedTo.length) { - newReportAction.whisperedToAccountIDs = whisperedToAccountIDs; - } else { - Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because whisperedToAccountIDs not found`); - return; } - } - if (lodashHas(reportAction, ['childOldestFourEmails']) && !lodashHas(reportAction, ['childOldestFourAccountIDs'])) { - 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 (lodashHas(reportAction, ['childManagerEmail']) && !lodashHas(reportAction, ['childManagerAccountID'])) { + reportActionsWereModified = true; + const childManagerAccountID = _.get(oldPersonalDetails, [reportAction.childManagerEmail, 'accountID']); + if (childManagerAccountID) { + newReportAction.childManagerAccountID = childManagerAccountID; + } else { + Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because childManagerAccountID not found`); + return; } - }); + } - if (childOldestFourAccountIDs.length === childOldestFourEmails.length) { - newReportAction.childOldestFourAccountIDs = childOldestFourAccountIDs.join(','); - } else { - Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because childOldestFourAccountIDs not found`); - return; + if (lodashHas(reportAction, ['whisperedTo']) && !lodashHas(reportAction, ['whisperedToAccountIDs'])) { + 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; + } else { + Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because whisperedToAccountIDs not found`); + return; + } } - } - if (lodashHas(reportAction, ['originalMessage', 'participants']) && !lodashHas(reportAction, ['originalMessage', 'participantAccountIDs'])) { - reportActionsWereModified = true; - const participantAccountIDs = []; - _.each(reportAction.originalMessage.participants, (participant) => { - const participantAccountID = _.get(oldPersonalDetails, [participant, 'accountID']); - if (participantAccountID) { - participantAccountIDs.push(participantAccountID); + if (lodashHas(reportAction, ['childOldestFourEmails']) && !lodashHas(reportAction, ['childOldestFourAccountIDs'])) { + 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(','); + } else { + Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because childOldestFourAccountIDs not found`); + return; } - }); + } - if (participantAccountIDs.length === reportAction.originalMessage.participants.length) { - newReportAction.originalMessage.participantAccountIDs = participantAccountIDs; - } else { - Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because originalMessage.participantAccountIDs not found`); - return; + if (lodashHas(reportAction, ['originalMessage', 'participants']) && !lodashHas(reportAction, ['originalMessage', 'participantAccountIDs'])) { + 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; + } else { + Log.info( + `[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because originalMessage.participantAccountIDs not found`, + ); + return; + } } - } - newReportActionsForReport[reportActionID] = newReportAction; - }); + newReportActionsForReport[reportActionID] = newReportAction; + }); - // Only include the reportActions from this report if at least one reportAction in this report - // was modified in any way. - if (reportActionsWereModified) { - onyxData[onyxKey] = newReportActionsForReport; - } - }); - } + // Only include the reportActions from this report if at least one reportAction in this report + // was modified in any way. + if (reportActionsWereModified) { + onyxData[onyxKey] = newReportActionsForReport; + } + }); + } - return Onyx.multiSet(onyxData); - }); + return Onyx.multiSet(onyxData); + }, + ); } diff --git a/tests/unit/MigrationTest.js b/tests/unit/MigrationTest.js index 7a5f264e0b30..278dd6dfe742 100644 --- a/tests/unit/MigrationTest.js +++ b/tests/unit/MigrationTest.js @@ -263,7 +263,9 @@ describe('Migrations', () => { // Warning: this test has to come before the others in this suite because Onyx.clear leaves traces and keys with null values aren't cleared out between tests it("Should skip the migration if there's no reportAction data in Onyx", () => - PersonalDetailsByAccountID().then(() => expect(LogSpy).toHaveBeenCalledWith('[Migrate Onyx] Skipped PersonalDetailsByAccountID reportActions migration because there were no reportActions'))); + PersonalDetailsByAccountID().then(() => + expect(LogSpy).toHaveBeenCalledWith('[Migrate Onyx] Skipped PersonalDetailsByAccountID reportActions migration because there were no reportActions'), + )); it('Should skip any zombie reportAction collections that have no reportAction data in Onyx', () => Onyx.multiSet({ @@ -811,5 +813,43 @@ describe('Migrations', () => { }, }); })); + + it('Should succeed in removing any policyMemberList objects it finds in Onyx', () => + Onyx.multiSet({ + [`${ONYXKEYS.COLLECTION.DEPRECATED_POLICY_MEMBER_LIST}1`]: { + 'admin@company1.com': { + role: 'admin', + }, + 'employee@company1.com': { + role: 'user', + }, + }, + [`${ONYXKEYS.COLLECTION.DEPRECATED_POLICY_MEMBER_LIST}2`]: { + 'admin@company2.com': { + role: 'admin', + }, + 'employee@company2.com': { + role: 'user', + }, + }, + }) + .then(PersonalDetailsByAccountID) + .then(() => { + expect(LogSpy).toHaveBeenCalledWith( + `[Migrate Onyx] PersonalDetailsByAccountID migration: removing policyMemberList ${ONYXKEYS.COLLECTION.DEPRECATED_POLICY_MEMBER_LIST}1`, + ); + expect(LogSpy).toHaveBeenCalledWith( + `[Migrate Onyx] PersonalDetailsByAccountID migration: removing policyMemberList ${ONYXKEYS.COLLECTION.DEPRECATED_POLICY_MEMBER_LIST}2`, + ); + const connectionID = Onyx.connect({ + key: ONYXKEYS.COLLECTION.DEPRECATED_POLICY_MEMBER_LIST, + waitForCollectionCallback: true, + callback: (allPolicyMemberLists) => { + Onyx.disconnect(connectionID); + expect(allPolicyMemberLists[`${ONYXKEYS.COLLECTION.DEPRECATED_POLICY_MEMBER_LIST}1`]).toBeNull(); + expect(allPolicyMemberLists[`${ONYXKEYS.COLLECTION.DEPRECATED_POLICY_MEMBER_LIST}2`]).toBeNull(); + }, + }); + })); }); }); From 4213c5bfbe7d17a39b5121c73fa7a6946ad1cb5e Mon Sep 17 00:00:00 2001 From: Puneet Lath Date: Wed, 28 Jun 2023 15:32:13 -0400 Subject: [PATCH 4/4] Remove no report actions condition --- .../migrations/PersonalDetailsByAccountID.js | 228 +++++++++--------- tests/unit/MigrationTest.js | 6 - 2 files changed, 110 insertions(+), 124 deletions(-) diff --git a/src/libs/migrations/PersonalDetailsByAccountID.js b/src/libs/migrations/PersonalDetailsByAccountID.js index 68ab79a39a26..2872e0ed1afe 100644 --- a/src/libs/migrations/PersonalDetailsByAccountID.js +++ b/src/libs/migrations/PersonalDetailsByAccountID.js @@ -90,148 +90,140 @@ export default function () { // If we are not able to get the accountID from personalDetails for some reason, 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. - if (!oldReportActions) { - Log.info('[Migrate Onyx] Skipped PersonalDetailsByAccountID reportActions migration because there were no reportActions'); - } else { - _.each(oldReportActions, (reportActionsForReport, onyxKey) => { - if (_.isEmpty(reportActionsForReport)) { - Log.info(`[Migrate Onyx] Skipped migration PersonalDetailsByAccountID for ${onyxKey} because there were no reportActions`); + _.each(oldReportActions, (reportActionsForReport, onyxKey) => { + if (_.isEmpty(reportActionsForReport)) { + Log.info(`[Migrate Onyx] Skipped migration PersonalDetailsByAccountID for ${onyxKey} because there were no reportActions`); + return; + } + const newReportActionsForReport = {}; + let reportActionsWereModified = false; + _.each(reportActionsForReport, (reportAction, reportActionID) => { + if (_.isEmpty(reportAction)) { + reportActionsWereModified = true; + Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because the reportAction was empty`); return; } - - const newReportActionsForReport = {}; - let reportActionsWereModified = false; - _.each(reportActionsForReport, (reportAction, reportActionID) => { - if (_.isEmpty(reportAction)) { - reportActionsWereModified = true; - Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because the reportAction was empty`); + const newReportAction = reportAction; + + if (lodashHas(reportAction, ['originalMessage', 'oldLogin']) && !lodashHas(reportAction, ['originalMessage', 'oldAccountID'])) { + reportActionsWereModified = true; + const oldAccountID = _.get(oldPersonalDetails, [reportAction.originalMessage.oldLogin, 'accountID']); + if (oldAccountID) { + newReportAction.originalMessage.oldAccountID = oldAccountID; + } else { + Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because originalMessage.oldAccountID not found`); return; } + } - const newReportAction = reportAction; - - if (lodashHas(reportAction, ['originalMessage', 'oldLogin']) && !lodashHas(reportAction, ['originalMessage', 'oldAccountID'])) { - reportActionsWereModified = true; - const oldAccountID = _.get(oldPersonalDetails, [reportAction.originalMessage.oldLogin, 'accountID']); - if (oldAccountID) { - newReportAction.originalMessage.oldAccountID = oldAccountID; - } 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'])) { + reportActionsWereModified = true; + const newAccountID = _.get(oldPersonalDetails, [reportAction.originalMessage.newLogin, 'accountID']); + if (newAccountID) { + newReportAction.originalMessage.newAccountID = newAccountID; + } else { + Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because originalMessage.newAccountID not found`); + return; } + } - if (lodashHas(reportAction, ['originalMessage', 'newLogin']) && !lodashHas(reportAction, ['originalMessage', 'newAccountID'])) { - reportActionsWereModified = true; - const newAccountID = _.get(oldPersonalDetails, [reportAction.originalMessage.newLogin, 'accountID']); - if (newAccountID) { - newReportAction.originalMessage.newAccountID = newAccountID; - } else { - Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because originalMessage.newAccountID not found`); - return; - } + if (lodashHas(reportAction, ['accountEmail']) && !lodashHas(reportAction, ['accountID'])) { + reportActionsWereModified = true; + const accountID = _.get(oldPersonalDetails, [reportAction.accountEmail, 'accountID']); + if (accountID) { + newReportAction.accountID = accountID; + } else { + Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because accountID not found`); + return; } + } - if (lodashHas(reportAction, ['accountEmail']) && !lodashHas(reportAction, ['accountID'])) { - reportActionsWereModified = true; - const accountID = _.get(oldPersonalDetails, [reportAction.accountEmail, 'accountID']); - if (accountID) { - newReportAction.accountID = accountID; - } else { - Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because accountID not found`); - return; - } + if (lodashHas(reportAction, ['actorEmail']) && !lodashHas(reportAction, ['actorAccountID'])) { + reportActionsWereModified = true; + const actorAccountID = _.get(oldPersonalDetails, [reportAction.actorEmail, 'accountID']); + if (actorAccountID) { + newReportAction.actorAccountID = actorAccountID; + } else { + Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because actorAccountID not found`); + return; } + } - if (lodashHas(reportAction, ['actorEmail']) && !lodashHas(reportAction, ['actorAccountID'])) { - reportActionsWereModified = true; - const actorAccountID = _.get(oldPersonalDetails, [reportAction.actorEmail, 'accountID']); - if (actorAccountID) { - newReportAction.actorAccountID = actorAccountID; - } else { - Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because actorAccountID not found`); - return; - } + if (lodashHas(reportAction, ['childManagerEmail']) && !lodashHas(reportAction, ['childManagerAccountID'])) { + reportActionsWereModified = true; + const childManagerAccountID = _.get(oldPersonalDetails, [reportAction.childManagerEmail, 'accountID']); + if (childManagerAccountID) { + newReportAction.childManagerAccountID = childManagerAccountID; + } else { + Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because childManagerAccountID not found`); + return; } + } - if (lodashHas(reportAction, ['childManagerEmail']) && !lodashHas(reportAction, ['childManagerAccountID'])) { - reportActionsWereModified = true; - const childManagerAccountID = _.get(oldPersonalDetails, [reportAction.childManagerEmail, 'accountID']); - if (childManagerAccountID) { - newReportAction.childManagerAccountID = childManagerAccountID; - } else { - Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because childManagerAccountID not found`); - return; + if (lodashHas(reportAction, ['whisperedTo']) && !lodashHas(reportAction, ['whisperedToAccountIDs'])) { + reportActionsWereModified = true; + const whisperedToAccountIDs = []; + _.each(reportAction.whisperedTo, (whisperedToLogin) => { + const whisperedToAccountID = _.get(oldPersonalDetails, [whisperedToLogin, 'accountID']); + if (whisperedToAccountID) { + whisperedToAccountIDs.push(whisperedToAccountID); } - } + }); - if (lodashHas(reportAction, ['whisperedTo']) && !lodashHas(reportAction, ['whisperedToAccountIDs'])) { - 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; - } else { - Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because whisperedToAccountIDs not found`); - return; - } + if (whisperedToAccountIDs.length === reportAction.whisperedTo.length) { + newReportAction.whisperedToAccountIDs = whisperedToAccountIDs; + } else { + Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because whisperedToAccountIDs not found`); + return; } + } - if (lodashHas(reportAction, ['childOldestFourEmails']) && !lodashHas(reportAction, ['childOldestFourAccountIDs'])) { - 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(','); - } else { - Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because childOldestFourAccountIDs not found`); - return; + if (lodashHas(reportAction, ['childOldestFourEmails']) && !lodashHas(reportAction, ['childOldestFourAccountIDs'])) { + 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 (lodashHas(reportAction, ['originalMessage', 'participants']) && !lodashHas(reportAction, ['originalMessage', 'participantAccountIDs'])) { - 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; - } else { - Log.info( - `[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because originalMessage.participantAccountIDs not found`, - ); - return; - } + if (childOldestFourAccountIDs.length === childOldestFourEmails.length) { + newReportAction.childOldestFourAccountIDs = childOldestFourAccountIDs.join(','); + } else { + Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because childOldestFourAccountIDs not found`); + return; } + } - newReportActionsForReport[reportActionID] = newReportAction; - }); + if (lodashHas(reportAction, ['originalMessage', 'participants']) && !lodashHas(reportAction, ['originalMessage', 'participantAccountIDs'])) { + reportActionsWereModified = true; + const participantAccountIDs = []; + _.each(reportAction.originalMessage.participants, (participant) => { + const participantAccountID = _.get(oldPersonalDetails, [participant, 'accountID']); + if (participantAccountID) { + participantAccountIDs.push(participantAccountID); + } + }); - // Only include the reportActions from this report if at least one reportAction in this report - // was modified in any way. - if (reportActionsWereModified) { - onyxData[onyxKey] = newReportActionsForReport; + if (participantAccountIDs.length === reportAction.originalMessage.participants.length) { + newReportAction.originalMessage.participantAccountIDs = participantAccountIDs; + } else { + Log.info(`[Migrate Onyx] PersonalDetailsByAccountID migration: removing reportAction ${reportActionID} because originalMessage.participantAccountIDs not found`); + return; + } } + + newReportActionsForReport[reportActionID] = newReportAction; }); - } + + // Only include the reportActions from this report if at least one reportAction in this report + // was modified in any way. + if (reportActionsWereModified) { + onyxData[onyxKey] = newReportActionsForReport; + } + }); return Onyx.multiSet(onyxData); }, diff --git a/tests/unit/MigrationTest.js b/tests/unit/MigrationTest.js index 278dd6dfe742..6162bded793b 100644 --- a/tests/unit/MigrationTest.js +++ b/tests/unit/MigrationTest.js @@ -261,12 +261,6 @@ describe('Migrations', () => { PERSONAL_DETAILS: 'personalDetails', }; - // Warning: this test has to come before the others in this suite because Onyx.clear leaves traces and keys with null values aren't cleared out between tests - it("Should skip the migration if there's no reportAction data in Onyx", () => - PersonalDetailsByAccountID().then(() => - expect(LogSpy).toHaveBeenCalledWith('[Migrate Onyx] Skipped PersonalDetailsByAccountID reportActions migration because there were no reportActions'), - )); - it('Should skip any zombie reportAction collections that have no reportAction data in Onyx', () => Onyx.multiSet({ [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]: null,