2023-08-03 17:42:21 +02:00
|
|
|
import { cloneDeep } from 'lodash';
|
2023-08-02 23:22:35 +02:00
|
|
|
import { migrate, version } from './092';
|
|
|
|
|
2023-08-03 17:42:21 +02:00
|
|
|
const PREVIOUS_VERSION = version - 1;
|
|
|
|
|
2023-08-16 21:26:20 +02:00
|
|
|
const sentryCaptureExceptionMock = jest.fn();
|
|
|
|
|
|
|
|
global.sentry = {
|
|
|
|
startSession: jest.fn(),
|
|
|
|
endSession: jest.fn(),
|
|
|
|
toggleSession: jest.fn(),
|
|
|
|
captureException: sentryCaptureExceptionMock,
|
|
|
|
};
|
|
|
|
|
2023-08-02 23:22:35 +02:00
|
|
|
describe('migration #92', () => {
|
2023-08-16 21:26:20 +02:00
|
|
|
afterEach(() => {
|
|
|
|
jest.resetAllMocks();
|
|
|
|
});
|
|
|
|
|
2023-08-02 23:22:35 +02:00
|
|
|
it('should update the version metadata', async () => {
|
|
|
|
const oldStorage = {
|
|
|
|
meta: {
|
2023-08-03 17:42:21 +02:00
|
|
|
version: PREVIOUS_VERSION,
|
2023-08-02 23:22:35 +02:00
|
|
|
},
|
|
|
|
data: {},
|
|
|
|
};
|
|
|
|
|
|
|
|
const newStorage = await migrate(oldStorage);
|
|
|
|
expect(newStorage.meta).toStrictEqual({
|
|
|
|
version,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-08-03 17:42:21 +02:00
|
|
|
it('should return state unaltered if there is no phishing controller state', async () => {
|
2023-08-02 23:22:35 +02:00
|
|
|
const oldData = {
|
|
|
|
other: 'data',
|
|
|
|
};
|
|
|
|
const oldStorage = {
|
|
|
|
meta: {
|
2023-08-03 17:42:21 +02:00
|
|
|
version: PREVIOUS_VERSION,
|
2023-08-02 23:22:35 +02:00
|
|
|
},
|
|
|
|
data: oldData,
|
|
|
|
};
|
|
|
|
|
2023-08-03 17:42:21 +02:00
|
|
|
const newStorage = await migrate(cloneDeep(oldStorage));
|
2023-08-02 23:22:35 +02:00
|
|
|
expect(newStorage.data).toStrictEqual(oldData);
|
|
|
|
});
|
|
|
|
|
2023-08-16 21:26:20 +02:00
|
|
|
it('captures an exception if the phishing controller state is invalid', async () => {
|
|
|
|
const oldStorage = {
|
|
|
|
meta: {
|
|
|
|
version: PREVIOUS_VERSION,
|
|
|
|
},
|
|
|
|
data: { PhishingController: 'this is not valid' },
|
|
|
|
};
|
|
|
|
|
|
|
|
await migrate(oldStorage);
|
|
|
|
|
|
|
|
expect(sentryCaptureExceptionMock).toHaveBeenCalledTimes(1);
|
|
|
|
expect(sentryCaptureExceptionMock).toHaveBeenCalledWith(
|
|
|
|
new Error(`typeof state.PhishingController is string`),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2023-08-03 17:42:21 +02:00
|
|
|
it('should return state unaltered if there is no phishing controller last fetched state', async () => {
|
2023-08-02 23:22:35 +02:00
|
|
|
const oldData = {
|
|
|
|
other: 'data',
|
2023-08-03 17:42:21 +02:00
|
|
|
PhishingController: {
|
|
|
|
whitelist: [],
|
2023-08-02 23:22:35 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
const oldStorage = {
|
|
|
|
meta: {
|
2023-08-03 17:42:21 +02:00
|
|
|
version: PREVIOUS_VERSION,
|
2023-08-02 23:22:35 +02:00
|
|
|
},
|
|
|
|
data: oldData,
|
|
|
|
};
|
|
|
|
|
2023-08-03 17:42:21 +02:00
|
|
|
const newStorage = await migrate(cloneDeep(oldStorage));
|
2023-08-02 23:22:35 +02:00
|
|
|
expect(newStorage.data).toStrictEqual(oldData);
|
|
|
|
});
|
|
|
|
|
2023-08-03 17:42:21 +02:00
|
|
|
it('should remove both last fetched properties from phishing controller state', async () => {
|
2023-08-02 23:22:35 +02:00
|
|
|
const oldData = {
|
|
|
|
other: 'data',
|
2023-08-03 17:42:21 +02:00
|
|
|
PhishingController: {
|
|
|
|
whitelist: [],
|
|
|
|
hotlistLastFetched: 0,
|
|
|
|
stalelistLastFetched: 0,
|
2023-08-02 23:22:35 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
const oldStorage = {
|
|
|
|
meta: {
|
2023-08-03 17:42:21 +02:00
|
|
|
version: PREVIOUS_VERSION,
|
2023-08-02 23:22:35 +02:00
|
|
|
},
|
|
|
|
data: oldData,
|
|
|
|
};
|
|
|
|
|
|
|
|
const newStorage = await migrate(oldStorage);
|
|
|
|
expect(newStorage.data).toStrictEqual({
|
|
|
|
other: 'data',
|
2023-08-03 17:42:21 +02:00
|
|
|
PhishingController: {
|
|
|
|
whitelist: [],
|
2023-08-02 23:22:35 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|