Skip to content

Commit

Permalink
Merge pull request #27529 from software-mansion-labs/@Skalakid/ts/Key…
Browse files Browse the repository at this point in the history
…ReportActionsByReportActionID

[No QA][TS migration] Migrate 'KeyReportActionsByReportActionID.js' lib to TypeScript
  • Loading branch information
cristipaval authored Sep 19, 2023
2 parents 7b02afd + 3809ba2 commit 6d67552
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 173 deletions.
2 changes: 0 additions & 2 deletions src/libs/migrateOnyx.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import RenamePriorityModeKey from './migrations/RenamePriorityModeKey';
import MoveToIndexedDB from './migrations/MoveToIndexedDB';
import RenameExpensifyNewsStatus from './migrations/RenameExpensifyNewsStatus';
import AddLastVisibleActionCreated from './migrations/AddLastVisibleActionCreated';
import KeyReportActionsByReportActionID from './migrations/KeyReportActionsByReportActionID';
import PersonalDetailsByAccountID from './migrations/PersonalDetailsByAccountID';

export default function () {
Expand All @@ -22,7 +21,6 @@ export default function () {
AddEncryptedAuthToken,
RenameExpensifyNewsStatus,
AddLastVisibleActionCreated,
KeyReportActionsByReportActionID,
PersonalDetailsByAccountID,
];

Expand Down
64 changes: 0 additions & 64 deletions src/libs/migrations/KeyReportActionsByReportActionID.js

This file was deleted.

107 changes: 0 additions & 107 deletions tests/unit/MigrationTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Log from '../../src/libs/Log';
import getPlatform from '../../src/libs/getPlatform';
import AddLastVisibleActionCreated from '../../src/libs/migrations/AddLastVisibleActionCreated';
import MoveToIndexedDB from '../../src/libs/migrations/MoveToIndexedDB';
import KeyReportActionsByReportActionID from '../../src/libs/migrations/KeyReportActionsByReportActionID';
import PersonalDetailsByAccountID from '../../src/libs/migrations/PersonalDetailsByAccountID';
import CheckForPreviousReportActionID from '../../src/libs/migrations/CheckForPreviousReportActionID';
import ONYXKEYS from '../../src/ONYXKEYS';
Expand Down Expand Up @@ -150,112 +149,6 @@ describe('Migrations', () => {
}));
});

describe('KeyReportActionsByReportActionID', () => {
// 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 work even if there's no reportAction data in Onyx", () =>
KeyReportActionsByReportActionID().then(() =>
expect(LogSpy).toHaveBeenCalledWith('[Migrate Onyx] Skipped migration KeyReportActionsByReportActionID because there were no reportActions'),
));

it("Should work even if there's zombie reportAction data in Onyx", () =>
Onyx.multiSet({
[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]: null,
[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}2`]: null,
})
.then(KeyReportActionsByReportActionID)
.then(() => {
expect(LogSpy).toHaveBeenCalledWith('[Migrate Onyx] Skipped migration KeyReportActionsByReportActionID because there are no actions to migrate');
const connectionID = Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
waitForCollectionCallback: true,
callback: (allReportActions) => {
Onyx.disconnect(connectionID);
_.each(allReportActions, (reportActionsForReport) => expect(reportActionsForReport).toBeNull());
},
});
}));

it('Should migrate reportActions to be keyed by reportActionID instead of sequenceNumber', () =>
Onyx.multiSet({
[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]: {
1: {
reportActionID: '1000',
sequenceNumber: 1,
},
2: {
reportActionID: '2000',
sequenceNumber: 2,
},
},
[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}2`]: {
1: {
reportActionID: '3000',
sequenceNumber: 1,
},
2: {
reportActionID: '4000',
sequenceNumber: 2,
},
},
})
.then(KeyReportActionsByReportActionID)
.then(() => {
expect(LogSpy).toHaveBeenCalledWith('[Migrate Onyx] Re-keying reportActions by reportActionID for 2 reports');
const connectionID = Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
waitForCollectionCallback: true,
callback: (allReportActions) => {
Onyx.disconnect(connectionID);
expect(_.keys(allReportActions).length).toBe(2);
_.each(allReportActions, (reportActionsForReport) => {
_.each(reportActionsForReport, (reportAction, key) => {
expect(key).toBe(reportAction.reportActionID);
});
});
},
});
}));

it('Should return early if the migration has already happened', () =>
Onyx.multiSet({
[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}1`]: {
1000: {
reportActionID: '1000',
sequenceNumber: 1,
},
2000: {
reportActionID: '2000',
sequenceNumber: 2,
},
},
[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}2`]: {
3000: {
reportActionID: '3000',
},
4000: {
reportActionID: '4000',
},
},
})
.then(KeyReportActionsByReportActionID)
.then(() => {
expect(LogSpy).toHaveBeenCalledWith('[Migrate Onyx] Skipped migration KeyReportActionsByReportActionID because we already migrated it');
const connectionID = Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
waitForCollectionCallback: true,
callback: (allReportActions) => {
Onyx.disconnect(connectionID);
expect(_.keys(allReportActions).length).toBe(2);
_.each(allReportActions, (reportActionsForReport) => {
_.each(reportActionsForReport, (reportAction, key) => {
expect(key).toBe(reportAction.reportActionID);
});
});
},
});
}));
});

describe('PersonalDetailsByAccountID', () => {
const DEPRECATED_ONYX_KEYS = {
// Deprecated personal details object which was keyed by login instead of accountID.
Expand Down

0 comments on commit 6d67552

Please sign in to comment.