mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 01:39:44 +01:00
b874a301f5
* capture exception for sentry when invariant conditions are met in migration 82 * Code cleanup * Capture exceptions in invariant conditions for migrations 83,84,85,86,89,91,93,94 * Update app/scripts/migrations/082.test.js Co-authored-by: Mark Stacey <markjstacey@gmail.com> * Code cleanup * Fix SentryObject type declaration * Stop throwing error if preferences controller is undefined * Refactor 084 and 086 to remove double negative * Capture exceptions for invariant states in in migrations 87,88,90 and 92 * lint fix * log warning in migration 82 when preferences controller is undefined --------- Co-authored-by: Mark Stacey <markjstacey@gmail.com>
164 lines
3.5 KiB
JavaScript
164 lines
3.5 KiB
JavaScript
import { migrate, version } from './086';
|
|
|
|
const sentryCaptureExceptionMock = jest.fn();
|
|
|
|
global.sentry = {
|
|
captureException: sentryCaptureExceptionMock,
|
|
};
|
|
|
|
jest.mock('uuid', () => {
|
|
const actual = jest.requireActual('uuid');
|
|
|
|
return {
|
|
...actual,
|
|
v4: jest.fn(),
|
|
};
|
|
});
|
|
|
|
describe('migration #86', () => {
|
|
afterEach(() => {
|
|
jest.resetAllMocks();
|
|
});
|
|
|
|
it('should update the version metadata', async () => {
|
|
const oldStorage = {
|
|
meta: {
|
|
version: 85,
|
|
},
|
|
data: {},
|
|
};
|
|
|
|
const newStorage = await migrate(oldStorage);
|
|
expect(newStorage.meta).toStrictEqual({
|
|
version,
|
|
});
|
|
});
|
|
|
|
it('should return state unaltered if there is no network controller state', async () => {
|
|
const oldData = {
|
|
other: 'data',
|
|
};
|
|
const oldStorage = {
|
|
meta: {
|
|
version: 85,
|
|
},
|
|
data: oldData,
|
|
};
|
|
|
|
const newStorage = await migrate(oldStorage);
|
|
expect(newStorage.data).toStrictEqual(oldData);
|
|
});
|
|
|
|
it('should capture an exception if there is no network controller state', async () => {
|
|
const oldData = {
|
|
other: 'data',
|
|
};
|
|
const oldStorage = {
|
|
meta: {
|
|
version: 85,
|
|
},
|
|
data: oldData,
|
|
};
|
|
|
|
await migrate(oldStorage);
|
|
|
|
expect(sentryCaptureExceptionMock).toHaveBeenCalledTimes(1);
|
|
expect(sentryCaptureExceptionMock).toHaveBeenCalledWith(
|
|
new Error(`typeof state.NetworkController is undefined`),
|
|
);
|
|
});
|
|
|
|
it('should return state unaltered if there is no network controller provider state', async () => {
|
|
const oldData = {
|
|
other: 'data',
|
|
NetworkController: {
|
|
networkConfigurations: {
|
|
foo: 'bar',
|
|
},
|
|
},
|
|
};
|
|
const oldStorage = {
|
|
meta: {
|
|
version: 85,
|
|
},
|
|
data: oldData,
|
|
};
|
|
|
|
const newStorage = await migrate(oldStorage);
|
|
expect(newStorage.data).toStrictEqual(oldData);
|
|
});
|
|
|
|
it('should capture an exception if there is no network controller provider state and no providerConfig state', async () => {
|
|
const oldData = {
|
|
other: 'data',
|
|
NetworkController: {
|
|
networkConfigurations: {
|
|
foo: 'bar',
|
|
},
|
|
},
|
|
};
|
|
const oldStorage = {
|
|
meta: {
|
|
version: 85,
|
|
},
|
|
data: oldData,
|
|
};
|
|
|
|
await migrate(oldStorage);
|
|
|
|
expect(sentryCaptureExceptionMock).toHaveBeenCalledTimes(1);
|
|
expect(sentryCaptureExceptionMock).toHaveBeenCalledWith(
|
|
new Error(`typeof state.NetworkController.provider is undefined`),
|
|
);
|
|
});
|
|
|
|
it('should not capture an exception if there is no network controller provider state but there is a providerConfig state', async () => {
|
|
const oldData = {
|
|
other: 'data',
|
|
NetworkController: {
|
|
networkConfigurations: {
|
|
foo: 'bar',
|
|
},
|
|
providerConfig: {},
|
|
},
|
|
};
|
|
const oldStorage = {
|
|
meta: {
|
|
version: 85,
|
|
},
|
|
data: oldData,
|
|
};
|
|
|
|
await migrate(oldStorage);
|
|
|
|
expect(sentryCaptureExceptionMock).toHaveBeenCalledTimes(0);
|
|
});
|
|
|
|
it('should rename the provider config state', async () => {
|
|
const oldData = {
|
|
other: 'data',
|
|
NetworkController: {
|
|
provider: {
|
|
some: 'provider',
|
|
},
|
|
},
|
|
};
|
|
const oldStorage = {
|
|
meta: {
|
|
version: 85,
|
|
},
|
|
data: oldData,
|
|
};
|
|
|
|
const newStorage = await migrate(oldStorage);
|
|
expect(newStorage.data).toStrictEqual({
|
|
other: 'data',
|
|
NetworkController: {
|
|
providerConfig: {
|
|
some: 'provider',
|
|
},
|
|
},
|
|
});
|
|
});
|
|
});
|