Skip to content

Commit

Permalink
migration: remove featureFlags property
Browse files Browse the repository at this point in the history
  • Loading branch information
joaoloureirop committed Nov 27, 2024
1 parent c8495e5 commit d7d384c
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
59 changes: 59 additions & 0 deletions app/store/migrations/061.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import migrate from './061';
import { captureException } from '@sentry/react-native';
import mockedEngine from '../../core/__mocks__/MockedEngine';

jest.mock('@sentry/react-native', () => ({
captureException: jest.fn(),
}));
const mockedCaptureException = jest.mocked(captureException);

jest.mock('../../core/Engine', () => ({
init: () => mockedEngine.init(),
}));

describe('Migration #61 - remove featureFlags property from redux state', () => {
beforeEach(() => {
jest.restoreAllMocks();
jest.resetAllMocks();
});

const invalidStates = [
{
state: null,
errorMessage: "FATAL ERROR: Migration 61: Invalid state error: 'object'",
scenario: 'state is invalid',
},
];

for (const { errorMessage, scenario, state } of invalidStates) {
it(`should capture exception if ${scenario}`, async () => {
const newState = await migrate(state);

expect(newState).toStrictEqual(state);
expect(mockedCaptureException).toHaveBeenCalledWith(expect.any(Error));
expect(mockedCaptureException.mock.calls[0][0].message).toBe(
errorMessage,
);
});
}

it('remove featureFlags property from redux state', async () => {
const oldState = {
engine: {
backgroundState: {},
},
featureFlags: {
minimumAppVersion: 29,
},
};

const expectedState = {
engine: {
backgroundState: {},
},
};

const migratedState = await migrate(oldState);
expect(migratedState).toStrictEqual(expectedState);
});
});
12 changes: 12 additions & 0 deletions app/store/migrations/061.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { hasProperty } from '@metamask/utils';
import { ensureValidState } from "./util";

export default function migrate(state: unknown) {
if (!ensureValidState(state, 61)) {
return state;
}
if (hasProperty(state, 'featureFlags')) {
delete state.featureFlags;
}
return state;
}
4 changes: 3 additions & 1 deletion app/store/migrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import migration57 from './057';
import migration58 from './058';
import migration59 from './059';
import migration60 from './060';
import migration61 from './061';

type MigrationFunction = (state: unknown) => unknown;
type AsyncMigrationFunction = (state: unknown) => Promise<unknown>;
Expand Down Expand Up @@ -133,7 +134,8 @@ export const migrationList: MigrationsList = {
57: migration57,
58: migration58,
59: migration59,
60: migration60
60: migration60,
61: migration61
};

// Enable both synchronous and asynchronous migrations
Expand Down

0 comments on commit d7d384c

Please sign in to comment.