2023-07-31 14:48:48 +02:00
|
|
|
import { migrate, version } from './090';
|
|
|
|
|
|
|
|
const PREVIOUS_VERSION = version - 1;
|
|
|
|
|
2023-08-16 21:26:20 +02:00
|
|
|
const sentryCaptureExceptionMock = jest.fn();
|
|
|
|
|
|
|
|
global.sentry = {
|
|
|
|
captureException: sentryCaptureExceptionMock,
|
|
|
|
};
|
|
|
|
|
2023-07-31 14:48:48 +02:00
|
|
|
describe('migration #90', () => {
|
2023-08-16 21:26:20 +02:00
|
|
|
afterEach(() => {
|
|
|
|
jest.resetAllMocks();
|
|
|
|
});
|
|
|
|
|
2023-07-31 14:48:48 +02:00
|
|
|
it('updates the version metadata', async () => {
|
|
|
|
const oldStorage = {
|
|
|
|
meta: {
|
|
|
|
version: PREVIOUS_VERSION,
|
|
|
|
},
|
|
|
|
data: {},
|
|
|
|
};
|
|
|
|
|
|
|
|
const newStorage = await migrate(oldStorage);
|
|
|
|
|
|
|
|
expect(newStorage.meta).toStrictEqual({
|
|
|
|
version,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not change the state if the phishing controller state does not exist', async () => {
|
|
|
|
const oldStorage = {
|
|
|
|
meta: {
|
|
|
|
version: PREVIOUS_VERSION,
|
|
|
|
},
|
|
|
|
data: { test: '123' },
|
|
|
|
};
|
|
|
|
|
|
|
|
const newStorage = await migrate(oldStorage);
|
|
|
|
|
|
|
|
expect(newStorage.data).toStrictEqual(oldStorage.data);
|
|
|
|
});
|
|
|
|
|
2023-08-16 21:26:20 +02:00
|
|
|
it('captures an exception if the phishing controller state is invalid', async () => {
|
2023-07-31 14:48:48 +02:00
|
|
|
const oldStorage = {
|
|
|
|
meta: {
|
|
|
|
version: PREVIOUS_VERSION,
|
|
|
|
},
|
|
|
|
data: { PhishingController: 'this is not valid' },
|
|
|
|
};
|
|
|
|
|
2023-08-16 21:26:20 +02:00
|
|
|
await migrate(oldStorage);
|
2023-07-31 14:48:48 +02:00
|
|
|
|
2023-08-16 21:26:20 +02:00
|
|
|
expect(sentryCaptureExceptionMock).toHaveBeenCalledTimes(1);
|
|
|
|
expect(sentryCaptureExceptionMock).toHaveBeenCalledWith(
|
|
|
|
new Error(`typeof state.PhishingController is string`),
|
|
|
|
);
|
2023-07-31 14:48:48 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('does not change the state if the listState property does not exist', async () => {
|
|
|
|
const oldStorage = {
|
|
|
|
meta: {
|
|
|
|
version: PREVIOUS_VERSION,
|
|
|
|
},
|
|
|
|
data: {
|
|
|
|
PhishingController: { test: 123 },
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const newStorage = await migrate(oldStorage);
|
|
|
|
|
|
|
|
expect(newStorage.data).toStrictEqual(oldStorage.data);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('deletes the "listState" property', async () => {
|
|
|
|
const oldStorage = {
|
|
|
|
meta: {
|
|
|
|
version: PREVIOUS_VERSION,
|
|
|
|
},
|
|
|
|
data: { PhishingController: { listState: {} } },
|
|
|
|
};
|
|
|
|
|
|
|
|
const newStorage = await migrate(oldStorage);
|
|
|
|
|
|
|
|
expect(newStorage.data.PhishingController.listState).toBeUndefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('deletes the listState if present', async () => {
|
|
|
|
const oldStorage = {
|
|
|
|
meta: {
|
|
|
|
version: PREVIOUS_VERSION,
|
|
|
|
},
|
|
|
|
data: { PhishingController: { listState: { test: 123 } } },
|
|
|
|
};
|
|
|
|
|
|
|
|
const newStorage = await migrate(oldStorage);
|
|
|
|
|
|
|
|
expect(newStorage.data).toStrictEqual({
|
|
|
|
PhishingController: {},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not delete the allowlist if present', async () => {
|
|
|
|
const oldStorage = {
|
|
|
|
meta: {
|
|
|
|
version: PREVIOUS_VERSION,
|
|
|
|
},
|
|
|
|
data: {
|
|
|
|
PhishingController: {
|
|
|
|
whitelist: ['foobar.com'],
|
|
|
|
listState: { test: 123 },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const newStorage = await migrate(oldStorage);
|
|
|
|
|
|
|
|
expect(newStorage.data).toStrictEqual({
|
|
|
|
PhishingController: { whitelist: ['foobar.com'] },
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|