1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-28 23:06:37 +01:00
metamask-extension/app/scripts/migrations/085.test.js

121 lines
2.5 KiB
JavaScript
Raw Normal View History

import { migrate, version } from './085';
const sentryCaptureExceptionMock = jest.fn();
global.sentry = {
captureException: sentryCaptureExceptionMock,
};
jest.mock('uuid', () => {
const actual = jest.requireActual('uuid');
return {
...actual,
v4: jest.fn(),
};
});
describe('migration #85', () => {
afterEach(() => {
jest.resetAllMocks();
});
it('should update the version metadata', async () => {
const oldStorage = {
meta: {
version: 84,
},
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: 84,
},
data: oldData,
};
const newStorage = await migrate(oldStorage);
expect(newStorage.data).toStrictEqual(oldData);
});
it('should capture an exception there is no network controller state', async () => {
const oldData = {
other: 'data',
};
const oldStorage = {
meta: {
version: 84,
},
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 previous provider state', async () => {
const oldData = {
other: 'data',
NetworkController: {
provider: {
some: 'provider',
},
},
};
const oldStorage = {
meta: {
version: 84,
},
data: oldData,
};
const newStorage = await migrate(oldStorage);
expect(newStorage.data).toStrictEqual(oldData);
});
it('should remove the previous provider state', async () => {
const oldData = {
other: 'data',
NetworkController: {
previousProviderStore: {
example: 'config',
},
provider: {
some: 'provider',
},
},
};
const oldStorage = {
meta: {
version: 84,
},
data: oldData,
};
const newStorage = await migrate(oldStorage);
expect(newStorage.data).toStrictEqual({
other: 'data',
NetworkController: {
provider: {
some: 'provider',
},
},
});
});
});