From ae362c2540ad8f49c63de64d00a5b7355e43a60c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Fa=C5=82at?= Date: Mon, 18 Sep 2023 11:37:06 +0200 Subject: [PATCH 1/8] Migrated CheckForPreviousReportActionID.js with Log.js dependency. --- src/libs/{Log.js => Log.ts} | 28 +++++++------ ...D.js => CheckForPreviousReportActionID.ts} | 42 +++++++++++-------- 2 files changed, 40 insertions(+), 30 deletions(-) rename src/libs/{Log.js => Log.ts} (81%) rename src/libs/migrations/{CheckForPreviousReportActionID.js => CheckForPreviousReportActionID.ts} (62%) diff --git a/src/libs/Log.js b/src/libs/Log.ts similarity index 81% rename from src/libs/Log.js rename to src/libs/Log.ts index e51fb74aedd5..e9874e0b739d 100644 --- a/src/libs/Log.js +++ b/src/libs/Log.ts @@ -7,15 +7,15 @@ import pkg from '../../package.json'; import requireParameters from './requireParameters'; import * as Network from './Network'; -let timeout = null; +let timeout: NodeJS.Timeout | null = null; /** - * @param {Object} parameters - * @param {String} parameters.expensifyCashAppVersion - * @param {Object[]} parameters.logPacket - * @returns {Promise} + * @param parameters + * @param parameters.expensifyCashAppVersion + * @param parameters.logPacket + * @returns Promise */ -function LogCommand(parameters) { +function LogCommand(parameters: Record) { const commandName = 'Log'; requireParameters(['logPacket', 'expensifyCashAppVersion'], parameters, commandName); @@ -27,13 +27,13 @@ function LogCommand(parameters) { /** * Network interface for logger. * - * @param {Logger} logger - * @param {Object} params - * @param {Object} params.parameters - * @param {String} params.message - * @return {Promise} + * @param logger + * @param params + * @param params.parameters + * @param params.message + * @return */ -function serverLoggingCallback(logger, params) { +function serverLoggingCallback(logger: Logger, params: Record) { const requestParams = params; requestParams.shouldProcessImmediately = false; requestParams.shouldRetry = false; @@ -41,7 +41,9 @@ function serverLoggingCallback(logger, params) { if (requestParams.parameters) { requestParams.parameters = JSON.stringify(params.parameters); } - clearTimeout(timeout); + if(timeout) { + clearTimeout(timeout); + } timeout = setTimeout(() => logger.info('Flushing logs older than 10 minutes', true, {}, true), 10 * 60 * 1000); return LogCommand(requestParams); } diff --git a/src/libs/migrations/CheckForPreviousReportActionID.js b/src/libs/migrations/CheckForPreviousReportActionID.ts similarity index 62% rename from src/libs/migrations/CheckForPreviousReportActionID.js rename to src/libs/migrations/CheckForPreviousReportActionID.ts index a61d9bfb08ec..ea1c2e2ad5b9 100644 --- a/src/libs/migrations/CheckForPreviousReportActionID.js +++ b/src/libs/migrations/CheckForPreviousReportActionID.ts @@ -1,17 +1,19 @@ -import _ from 'underscore'; -import Onyx from 'react-native-onyx'; +import Onyx, {OnyxCollection} from 'react-native-onyx'; +import _ from "lodash"; +import lodashHas from "lodash/has"; import Log from '../Log'; import ONYXKEYS from '../../ONYXKEYS'; +import {ReportAction} from "../../types/onyx"; /** - * @returns {Promise} + * @returns */ -function getReportActionsFromOnyx() { +function getReportActionsFromOnyx(): Promise> { return new Promise((resolve) => { const connectionID = Onyx.connect({ key: ONYXKEYS.COLLECTION.REPORT_ACTIONS, waitForCollectionCallback: true, - callback: (allReportActions) => { + callback: (allReportActions: OnyxCollection) => { Onyx.disconnect(connectionID); return resolve(allReportActions); }, @@ -23,9 +25,9 @@ function getReportActionsFromOnyx() { * This migration checks for the 'previousReportActionID' key in the first valid reportAction of a report in Onyx. * If the key is not found then all reportActions for all reports are removed from Onyx. * - * @returns {Promise} + * @returns */ -export default function () { +export default function (): Promise { return getReportActionsFromOnyx().then((allReportActions) => { if (_.isEmpty(allReportActions)) { Log.info(`[Migrate Onyx] Skipped migration CheckForPreviousReportActionID because there were no reportActions`); @@ -33,18 +35,23 @@ export default function () { } let firstValidValue; - _.some(_.values(allReportActions), (reportActions) => - _.some(_.values(reportActions), (reportActionData) => { - if (_.has(reportActionData, 'reportActionID')) { + + const records = allReportActions as Record; + + Object.values(records).some((reportAction: ReportAction) => { + Object.values(reportAction).some((reportActionData: unknown) => { + if (lodashHas(reportActionData, 'reportActionID')) { firstValidValue = reportActionData; return true; } return false; - }), - ); + }); - if (_.isUndefined(firstValidValue)) { + return true; + }); + + if (firstValidValue === undefined) { Log.info(`[Migrate Onyx] Skipped migration CheckForPreviousReportActionID because there were no valid reportActions`); return; } @@ -57,11 +64,12 @@ export default function () { // If previousReportActionID not found: Log.info(`[Migrate Onyx] CheckForPreviousReportActionID Migration: removing all reportActions because previousReportActionID not found in the first valid reportAction`); - const onyxData = {}; - _.each(allReportActions, (reportAction, onyxKey) => { - onyxData[onyxKey] = {}; + const onyxData: Record = {}; + + Object.entries(records).forEach(([onyxKey]) => { + onyxData[onyxKey] = {} as ReportAction; }); - return Onyx.multiSet(onyxData); + return Onyx.multiSet(onyxData as never); }); } From 626de5aec8be864b1723a80545548ff55a4051cd Mon Sep 17 00:00:00 2001 From: Kacper Falat Date: Thu, 5 Oct 2023 09:37:29 +0200 Subject: [PATCH 2/8] Fixes for migrations. --- .../CheckForPreviousReportActionID.ts | 41 +++++++------------ 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/src/libs/migrations/CheckForPreviousReportActionID.ts b/src/libs/migrations/CheckForPreviousReportActionID.ts index ea1c2e2ad5b9..59ce2e9689ba 100644 --- a/src/libs/migrations/CheckForPreviousReportActionID.ts +++ b/src/libs/migrations/CheckForPreviousReportActionID.ts @@ -1,13 +1,8 @@ -import Onyx, {OnyxCollection} from 'react-native-onyx'; -import _ from "lodash"; -import lodashHas from "lodash/has"; +import Onyx, {OnyxCollection, OnyxEntry} from 'react-native-onyx'; import Log from '../Log'; import ONYXKEYS from '../../ONYXKEYS'; import {ReportAction} from "../../types/onyx"; -/** - * @returns - */ function getReportActionsFromOnyx(): Promise> { return new Promise((resolve) => { const connectionID = Onyx.connect({ @@ -24,31 +19,23 @@ function getReportActionsFromOnyx(): Promise> { /** * This migration checks for the 'previousReportActionID' key in the first valid reportAction of a report in Onyx. * If the key is not found then all reportActions for all reports are removed from Onyx. - * - * @returns */ export default function (): Promise { return getReportActionsFromOnyx().then((allReportActions) => { - if (_.isEmpty(allReportActions)) { + if (!Array.isArray(allReportActions) || allReportActions.length === 0) { Log.info(`[Migrate Onyx] Skipped migration CheckForPreviousReportActionID because there were no reportActions`); return; } - let firstValidValue; - - const records = allReportActions as Record; - - Object.values(records).some((reportAction: ReportAction) => { - Object.values(reportAction).some((reportActionData: unknown) => { - if (lodashHas(reportActionData, 'reportActionID')) { - firstValidValue = reportActionData; - return true; - } + let firstValidValue: undefined | ReportAction; - return false; - }); + Object.values(allReportActions as ReportAction[]).some((reportAction) => { + if (reportAction.reportActionID !== undefined) { + firstValidValue = reportAction; + return true; + } - return true; + return false; }); if (firstValidValue === undefined) { @@ -56,7 +43,7 @@ export default function (): Promise { return; } - if (_.has(firstValidValue, 'previousReportActionID')) { + if (Object.hasOwn(firstValidValue, 'previousReportActionID')) { Log.info(`[Migrate Onyx] CheckForPreviousReportActionID Migration: previousReportActionID found. Migration complete`); return; } @@ -64,12 +51,12 @@ export default function (): Promise { // If previousReportActionID not found: Log.info(`[Migrate Onyx] CheckForPreviousReportActionID Migration: removing all reportActions because previousReportActionID not found in the first valid reportAction`); - const onyxData: Record = {}; + const onyxData: Record>> = {}; - Object.entries(records).forEach(([onyxKey]) => { - onyxData[onyxKey] = {} as ReportAction; + Object.entries(allReportActions).forEach(([onyxKey]) => { + onyxData[onyxKey] = {}; }); - return Onyx.multiSet(onyxData as never); + return Onyx.multiSet(onyxData); }); } From 59fd5bfcc96acaef0bcb791439012ef99f4b2267 Mon Sep 17 00:00:00 2001 From: Kacper Falat Date: Mon, 16 Oct 2023 13:11:21 +0200 Subject: [PATCH 3/8] Fixed typing issues. --- src/ONYXKEYS.ts | 2 +- .../CheckForPreviousReportActionID.ts | 40 +++++++------- src/types/onyx/ReportAction.ts | 4 ++ src/types/onyx/index.ts | 3 +- tests/unit/MigrationTest.js | 52 +++++++++---------- 5 files changed, 54 insertions(+), 47 deletions(-) diff --git a/src/ONYXKEYS.ts b/src/ONYXKEYS.ts index d9ea3488f85f..6861473694b0 100755 --- a/src/ONYXKEYS.ts +++ b/src/ONYXKEYS.ts @@ -386,7 +386,7 @@ type OnyxValues = { [ONYXKEYS.COLLECTION.WORKSPACE_INVITE_MEMBERS_DRAFT]: Record; [ONYXKEYS.COLLECTION.REPORT]: OnyxTypes.Report; [ONYXKEYS.COLLECTION.REPORT_METADATA]: OnyxTypes.ReportMetadata; - [ONYXKEYS.COLLECTION.REPORT_ACTIONS]: OnyxTypes.ReportAction; + [ONYXKEYS.COLLECTION.REPORT_ACTIONS]: OnyxTypes.ReportActions; [ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS]: string; [ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS]: OnyxTypes.ReportActionReactions; [ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT]: string; diff --git a/src/libs/migrations/CheckForPreviousReportActionID.ts b/src/libs/migrations/CheckForPreviousReportActionID.ts index 59ce2e9689ba..2224674a35fe 100644 --- a/src/libs/migrations/CheckForPreviousReportActionID.ts +++ b/src/libs/migrations/CheckForPreviousReportActionID.ts @@ -1,14 +1,14 @@ -import Onyx, {OnyxCollection, OnyxEntry} from 'react-native-onyx'; -import Log from '../Log'; +import Onyx, {OnyxCollection} from 'react-native-onyx'; import ONYXKEYS from '../../ONYXKEYS'; -import {ReportAction} from "../../types/onyx"; +import * as OnyxTypes from '../../types/onyx'; +import Log from '../Log'; -function getReportActionsFromOnyx(): Promise> { +function getReportActionsFromOnyx(): Promise> { return new Promise((resolve) => { const connectionID = Onyx.connect({ key: ONYXKEYS.COLLECTION.REPORT_ACTIONS, waitForCollectionCallback: true, - callback: (allReportActions: OnyxCollection) => { + callback: (allReportActions: OnyxCollection) => { Onyx.disconnect(connectionID); return resolve(allReportActions); }, @@ -22,28 +22,30 @@ function getReportActionsFromOnyx(): Promise> { */ export default function (): Promise { return getReportActionsFromOnyx().then((allReportActions) => { - if (!Array.isArray(allReportActions) || allReportActions.length === 0) { + if (Object.keys(allReportActions ?? {}).length === 0) { Log.info(`[Migrate Onyx] Skipped migration CheckForPreviousReportActionID because there were no reportActions`); return; } - let firstValidValue: undefined | ReportAction; + let firstValidValue: OnyxTypes.ReportAction | undefined; - Object.values(allReportActions as ReportAction[]).some((reportAction) => { - if (reportAction.reportActionID !== undefined) { - firstValidValue = reportAction; - return true; - } + Object.values(allReportActions ?? {}).some((reportActions) => + Object.values(reportActions ?? {}).some((reportActionData) => { + if (reportActionData?.reportActionID) { + firstValidValue = reportActionData; + return true; + } - return false; - }); + return false; + }), + ); - if (firstValidValue === undefined) { + if (!firstValidValue) { Log.info(`[Migrate Onyx] Skipped migration CheckForPreviousReportActionID because there were no valid reportActions`); return; } - if (Object.hasOwn(firstValidValue, 'previousReportActionID')) { + if (firstValidValue.previousReportActionID) { Log.info(`[Migrate Onyx] CheckForPreviousReportActionID Migration: previousReportActionID found. Migration complete`); return; } @@ -51,12 +53,12 @@ export default function (): Promise { // If previousReportActionID not found: Log.info(`[Migrate Onyx] CheckForPreviousReportActionID Migration: removing all reportActions because previousReportActionID not found in the first valid reportAction`); - const onyxData: Record>> = {}; + const onyxData: OnyxCollection = {}; - Object.entries(allReportActions).forEach(([onyxKey]) => { + Object.keys(allReportActions ?? {}).forEach((onyxKey) => { onyxData[onyxKey] = {}; }); - return Onyx.multiSet(onyxData); + return Onyx.multiSet(onyxData as Record<`${typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS}`, Record>); }); } diff --git a/src/types/onyx/ReportAction.ts b/src/types/onyx/ReportAction.ts index 5cbb02f08722..819a9ecd7850 100644 --- a/src/types/onyx/ReportAction.ts +++ b/src/types/onyx/ReportAction.ts @@ -85,8 +85,12 @@ type ReportActionBase = { childVisibleActionCount?: number; pendingAction?: OnyxCommon.PendingAction; + errors?: OnyxCommon.Errors; }; type ReportAction = ReportActionBase & OriginalMessage; +type ReportActions = Record; + export default ReportAction; +export type {ReportActions}; diff --git a/src/types/onyx/index.ts b/src/types/onyx/index.ts index e50925e7adf2..cb064869427e 100644 --- a/src/types/onyx/index.ts +++ b/src/types/onyx/index.ts @@ -37,7 +37,7 @@ import Policy from './Policy'; import PolicyCategory from './PolicyCategory'; import Report from './Report'; import ReportMetadata from './ReportMetadata'; -import ReportAction from './ReportAction'; +import ReportAction, {ReportActions} from './ReportAction'; import ReportActionReactions from './ReportActionReactions'; import SecurityGroup from './SecurityGroup'; import Transaction from './Transaction'; @@ -87,6 +87,7 @@ export type { Report, ReportMetadata, ReportAction, + ReportActions, ReportActionReactions, SecurityGroup, Transaction, diff --git a/tests/unit/MigrationTest.js b/tests/unit/MigrationTest.js index d0e7f19d3d3f..bc1b03084b99 100644 --- a/tests/unit/MigrationTest.js +++ b/tests/unit/MigrationTest.js @@ -463,10 +463,10 @@ describe('Migrations', () => { Onyx.multiSet({ [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]: { 1: { - reportActionID: 1, + reportActionID: '1', }, 2: { - reportActionID: 2, + reportActionID: '2', }, }, }) @@ -490,12 +490,12 @@ describe('Migrations', () => { Onyx.multiSet({ [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]: { 1: { - reportActionID: 1, - previousReportActionID: 0, + reportActionID: '1', + previousReportActionID: '0', }, 2: { - reportActionID: 2, - previousReportActionID: 1, + reportActionID: '2', + previousReportActionID: '1', }, }, }) @@ -509,12 +509,12 @@ describe('Migrations', () => { Onyx.disconnect(connectionID); const expectedReportAction = { 1: { - reportActionID: 1, - previousReportActionID: 0, + reportActionID: '1', + previousReportActionID: '0', }, 2: { - reportActionID: 2, - previousReportActionID: 1, + reportActionID: '2', + previousReportActionID: '1', }, }; expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]).toMatchObject(expectedReportAction); @@ -529,10 +529,10 @@ describe('Migrations', () => { [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}3`]: null, [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}4`]: { 1: { - reportActionID: 1, + reportActionID: '1', }, 2: { - reportActionID: 2, + reportActionID: '2', }, }, }) @@ -548,8 +548,8 @@ describe('Migrations', () => { Onyx.disconnect(connectionID); const expectedReportAction = {}; expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]).toMatchObject(expectedReportAction); - expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}2`]).toBeUndefined(); - expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}3`]).toBeUndefined(); + expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}2`]).toMatchObject(expectedReportAction); + expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}3`]).toMatchObject(expectedReportAction); expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}4`]).toMatchObject(expectedReportAction); }, }); @@ -562,12 +562,12 @@ describe('Migrations', () => { [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}3`]: null, [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}4`]: { 1: { - reportActionID: 1, - previousReportActionID: 10, + reportActionID: '1', + previousReportActionID: '10', }, 2: { - reportActionID: 2, - previousReportActionID: 23, + reportActionID: '2', + previousReportActionID: '23', }, }, }) @@ -582,17 +582,17 @@ describe('Migrations', () => { const expectedReportAction1 = {}; const expectedReportAction4 = { 1: { - reportActionID: 1, - previousReportActionID: 10, + reportActionID: '1', + previousReportActionID: '10', }, 2: { - reportActionID: 2, - previousReportActionID: 23, + reportActionID: '2', + previousReportActionID: '23', }, }; expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]).toMatchObject(expectedReportAction1); - expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}2`]).toBeUndefined(); - expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}3`]).toBeUndefined(); + expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}2`]).toBeNull(); + expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}3`]).toBeNull(); expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}4`]).toMatchObject(expectedReportAction4); }, }); @@ -614,10 +614,10 @@ describe('Migrations', () => { callback: (allReportActions) => { Onyx.disconnect(connectionID); const expectedReportAction = {}; - expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]).toBeUndefined(); + expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]).toBeNull(); expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}2`]).toMatchObject(expectedReportAction); expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}3`]).toMatchObject(expectedReportAction); - expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}4`]).toBeUndefined(); + expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}4`]).toBeNull(); }, }); })); From 2877065e334fcb75e1baf2bf9f7334cebb8671e1 Mon Sep 17 00:00:00 2001 From: Kacper Falat Date: Fri, 20 Oct 2023 11:20:15 +0200 Subject: [PATCH 4/8] After review changes. --- src/libs/migrations/CheckForPreviousReportActionID.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/migrations/CheckForPreviousReportActionID.ts b/src/libs/migrations/CheckForPreviousReportActionID.ts index 2224674a35fe..40fd95216558 100644 --- a/src/libs/migrations/CheckForPreviousReportActionID.ts +++ b/src/libs/migrations/CheckForPreviousReportActionID.ts @@ -8,7 +8,7 @@ function getReportActionsFromOnyx(): Promise) => { + callback: (allReportActions) => { Onyx.disconnect(connectionID); return resolve(allReportActions); }, @@ -31,7 +31,7 @@ export default function (): Promise { Object.values(allReportActions ?? {}).some((reportActions) => Object.values(reportActions ?? {}).some((reportActionData) => { - if (reportActionData?.reportActionID) { + if ('reportActionID' in reportActionData) { firstValidValue = reportActionData; return true; } From b0b64cb9b79e9b55a6ddaab7f5c0b37313fb913d Mon Sep 17 00:00:00 2001 From: Kacper Falat Date: Fri, 20 Oct 2023 11:25:53 +0200 Subject: [PATCH 5/8] Reverted own test changes. --- tests/unit/MigrationTest.js | 52 ++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/tests/unit/MigrationTest.js b/tests/unit/MigrationTest.js index bc1b03084b99..d0e7f19d3d3f 100644 --- a/tests/unit/MigrationTest.js +++ b/tests/unit/MigrationTest.js @@ -463,10 +463,10 @@ describe('Migrations', () => { Onyx.multiSet({ [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]: { 1: { - reportActionID: '1', + reportActionID: 1, }, 2: { - reportActionID: '2', + reportActionID: 2, }, }, }) @@ -490,12 +490,12 @@ describe('Migrations', () => { Onyx.multiSet({ [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]: { 1: { - reportActionID: '1', - previousReportActionID: '0', + reportActionID: 1, + previousReportActionID: 0, }, 2: { - reportActionID: '2', - previousReportActionID: '1', + reportActionID: 2, + previousReportActionID: 1, }, }, }) @@ -509,12 +509,12 @@ describe('Migrations', () => { Onyx.disconnect(connectionID); const expectedReportAction = { 1: { - reportActionID: '1', - previousReportActionID: '0', + reportActionID: 1, + previousReportActionID: 0, }, 2: { - reportActionID: '2', - previousReportActionID: '1', + reportActionID: 2, + previousReportActionID: 1, }, }; expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]).toMatchObject(expectedReportAction); @@ -529,10 +529,10 @@ describe('Migrations', () => { [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}3`]: null, [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}4`]: { 1: { - reportActionID: '1', + reportActionID: 1, }, 2: { - reportActionID: '2', + reportActionID: 2, }, }, }) @@ -548,8 +548,8 @@ describe('Migrations', () => { Onyx.disconnect(connectionID); const expectedReportAction = {}; expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]).toMatchObject(expectedReportAction); - expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}2`]).toMatchObject(expectedReportAction); - expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}3`]).toMatchObject(expectedReportAction); + expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}2`]).toBeUndefined(); + expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}3`]).toBeUndefined(); expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}4`]).toMatchObject(expectedReportAction); }, }); @@ -562,12 +562,12 @@ describe('Migrations', () => { [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}3`]: null, [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}4`]: { 1: { - reportActionID: '1', - previousReportActionID: '10', + reportActionID: 1, + previousReportActionID: 10, }, 2: { - reportActionID: '2', - previousReportActionID: '23', + reportActionID: 2, + previousReportActionID: 23, }, }, }) @@ -582,17 +582,17 @@ describe('Migrations', () => { const expectedReportAction1 = {}; const expectedReportAction4 = { 1: { - reportActionID: '1', - previousReportActionID: '10', + reportActionID: 1, + previousReportActionID: 10, }, 2: { - reportActionID: '2', - previousReportActionID: '23', + reportActionID: 2, + previousReportActionID: 23, }, }; expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]).toMatchObject(expectedReportAction1); - expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}2`]).toBeNull(); - expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}3`]).toBeNull(); + expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}2`]).toBeUndefined(); + expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}3`]).toBeUndefined(); expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}4`]).toMatchObject(expectedReportAction4); }, }); @@ -614,10 +614,10 @@ describe('Migrations', () => { callback: (allReportActions) => { Onyx.disconnect(connectionID); const expectedReportAction = {}; - expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]).toBeNull(); + expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]).toBeUndefined(); expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}2`]).toMatchObject(expectedReportAction); expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}3`]).toMatchObject(expectedReportAction); - expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}4`]).toBeNull(); + expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}4`]).toBeUndefined(); }, }); })); From 00db0cb7b112c76873e5e42af83393026499aaf4 Mon Sep 17 00:00:00 2001 From: Kacper Falat Date: Fri, 20 Oct 2023 12:10:37 +0200 Subject: [PATCH 6/8] Fixed tests. --- .../CheckForPreviousReportActionID.ts | 2 +- tests/unit/MigrationTest.js | 40 +++++++++---------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/libs/migrations/CheckForPreviousReportActionID.ts b/src/libs/migrations/CheckForPreviousReportActionID.ts index 40fd95216558..5f0e8e8d1c96 100644 --- a/src/libs/migrations/CheckForPreviousReportActionID.ts +++ b/src/libs/migrations/CheckForPreviousReportActionID.ts @@ -31,7 +31,7 @@ export default function (): Promise { Object.values(allReportActions ?? {}).some((reportActions) => Object.values(reportActions ?? {}).some((reportActionData) => { - if ('reportActionID' in reportActionData) { + if (reportActionData.reportActionID?.length) { firstValidValue = reportActionData; return true; } diff --git a/tests/unit/MigrationTest.js b/tests/unit/MigrationTest.js index d0e7f19d3d3f..66aa8646296e 100644 --- a/tests/unit/MigrationTest.js +++ b/tests/unit/MigrationTest.js @@ -463,10 +463,10 @@ describe('Migrations', () => { Onyx.multiSet({ [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]: { 1: { - reportActionID: 1, + reportActionID: '1', }, 2: { - reportActionID: 2, + reportActionID: '2', }, }, }) @@ -490,12 +490,12 @@ describe('Migrations', () => { Onyx.multiSet({ [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]: { 1: { - reportActionID: 1, - previousReportActionID: 0, + reportActionID: '1', + previousReportActionID: '0', }, 2: { - reportActionID: 2, - previousReportActionID: 1, + reportActionID: '2', + previousReportActionID: '1', }, }, }) @@ -509,12 +509,12 @@ describe('Migrations', () => { Onyx.disconnect(connectionID); const expectedReportAction = { 1: { - reportActionID: 1, - previousReportActionID: 0, + reportActionID: '1', + previousReportActionID: '0', }, 2: { - reportActionID: 2, - previousReportActionID: 1, + reportActionID: '2', + previousReportActionID: '1', }, }; expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]).toMatchObject(expectedReportAction); @@ -529,10 +529,10 @@ describe('Migrations', () => { [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}3`]: null, [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}4`]: { 1: { - reportActionID: 1, + reportActionID: '1', }, 2: { - reportActionID: 2, + reportActionID: '2', }, }, }) @@ -562,12 +562,12 @@ describe('Migrations', () => { [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}3`]: null, [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}4`]: { 1: { - reportActionID: 1, - previousReportActionID: 10, + reportActionID: '1', + previousReportActionID: '10', }, 2: { - reportActionID: 2, - previousReportActionID: 23, + reportActionID: '2', + previousReportActionID: '23', }, }, }) @@ -582,12 +582,12 @@ describe('Migrations', () => { const expectedReportAction1 = {}; const expectedReportAction4 = { 1: { - reportActionID: 1, - previousReportActionID: 10, + reportActionID: '1', + previousReportActionID: '10', }, 2: { - reportActionID: 2, - previousReportActionID: 23, + reportActionID: '2', + previousReportActionID: '23', }, }; expect(allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]).toMatchObject(expectedReportAction1); From fce1f22c04437b8b8c609948124a46c4e9ecdbbd Mon Sep 17 00:00:00 2001 From: Kacper Falat Date: Fri, 20 Oct 2023 14:10:28 +0200 Subject: [PATCH 7/8] Applied change in condition check. --- src/libs/migrations/CheckForPreviousReportActionID.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/migrations/CheckForPreviousReportActionID.ts b/src/libs/migrations/CheckForPreviousReportActionID.ts index 5f0e8e8d1c96..40fd95216558 100644 --- a/src/libs/migrations/CheckForPreviousReportActionID.ts +++ b/src/libs/migrations/CheckForPreviousReportActionID.ts @@ -31,7 +31,7 @@ export default function (): Promise { Object.values(allReportActions ?? {}).some((reportActions) => Object.values(reportActions ?? {}).some((reportActionData) => { - if (reportActionData.reportActionID?.length) { + if ('reportActionID' in reportActionData) { firstValidValue = reportActionData; return true; } From 172f1c7a00425e018d11f097f4182d9fa6b14bbe Mon Sep 17 00:00:00 2001 From: Kacper Falat Date: Mon, 6 Nov 2023 14:16:31 +0100 Subject: [PATCH 8/8] Conflicts resolved. --- src/libs/migrations/CheckForPreviousReportActionID.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/migrations/CheckForPreviousReportActionID.ts b/src/libs/migrations/CheckForPreviousReportActionID.ts index 474c0f560558..1f31a3586b0a 100644 --- a/src/libs/migrations/CheckForPreviousReportActionID.ts +++ b/src/libs/migrations/CheckForPreviousReportActionID.ts @@ -1,7 +1,7 @@ import Onyx, {OnyxCollection} from 'react-native-onyx'; import Log from '@libs/Log'; import ONYXKEYS from '@src/ONYXKEYS'; -import * as OnyxTypes from "@src/types/onyx"; +import * as OnyxTypes from '@src/types/onyx'; function getReportActionsFromOnyx(): Promise> { return new Promise((resolve) => {