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-02 23:22:35 +02:00
|
|
|
describe('migration #92', () => {
|
|
|
|
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-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
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|