-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migration: remove featureFlags property
- Loading branch information
1 parent
c8495e5
commit d7d384c
Showing
3 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters