2023-03-06 14:36:01 +01:00
|
|
|
import { migrate, version } from './078';
|
2023-02-16 20:23:29 +01:00
|
|
|
|
|
|
|
describe('migration #78', () => {
|
2023-03-06 14:36:01 +01:00
|
|
|
it('updates the version metadata', async () => {
|
2023-02-16 20:23:29 +01:00
|
|
|
const oldStorage = {
|
|
|
|
meta: {
|
|
|
|
version: 77,
|
|
|
|
},
|
2023-03-06 14:36:01 +01:00
|
|
|
data: {},
|
2023-02-16 20:23:29 +01:00
|
|
|
};
|
|
|
|
|
2023-03-06 14:36:01 +01:00
|
|
|
const newStorage = await migrate(oldStorage);
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
expect(newStorage.meta).toStrictEqual({
|
2023-03-06 14:36:01 +01:00
|
|
|
version,
|
2023-02-16 20:23:29 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-03-06 14:36:01 +01:00
|
|
|
it('does not change the state if the phishing controller state does not exist', async () => {
|
2023-02-16 20:23:29 +01:00
|
|
|
const oldStorage = {
|
|
|
|
meta: {
|
|
|
|
version: 77,
|
|
|
|
},
|
2023-03-06 14:36:01 +01:00
|
|
|
data: { test: '123' },
|
2023-02-16 20:23:29 +01:00
|
|
|
};
|
|
|
|
|
2023-03-06 14:36:01 +01:00
|
|
|
const newStorage = await migrate(oldStorage);
|
|
|
|
|
|
|
|
expect(newStorage.data).toStrictEqual(oldStorage.data);
|
|
|
|
});
|
|
|
|
|
|
|
|
const nonObjects = [undefined, null, 'test', 1, ['test']];
|
|
|
|
|
|
|
|
for (const invalidState of nonObjects) {
|
|
|
|
it(`does not change the state if the phishing controller state is ${invalidState}`, async () => {
|
|
|
|
const oldStorage = {
|
|
|
|
meta: {
|
|
|
|
version: 77,
|
2023-02-16 20:23:29 +01:00
|
|
|
},
|
2023-03-06 14:36:01 +01:00
|
|
|
data: { PhishingController: invalidState },
|
|
|
|
};
|
|
|
|
|
|
|
|
const newStorage = await migrate(oldStorage);
|
|
|
|
|
|
|
|
expect(newStorage.data).toStrictEqual(oldStorage.data);
|
2023-02-16 20:23:29 +01:00
|
|
|
});
|
2023-03-06 14:36:01 +01:00
|
|
|
}
|
2023-02-16 20:23:29 +01:00
|
|
|
|
2023-03-06 14:36:01 +01:00
|
|
|
it('does not change the state if the phishing controller state does not include "phishing" or "lastFetched" properties', async () => {
|
2023-02-16 20:23:29 +01:00
|
|
|
const oldStorage = {
|
|
|
|
meta: {
|
|
|
|
version: 77,
|
|
|
|
},
|
2023-03-06 14:36:01 +01:00
|
|
|
data: { PhishingController: { test: '123' } },
|
2023-02-16 20:23:29 +01:00
|
|
|
};
|
|
|
|
|
2023-03-06 14:36:01 +01:00
|
|
|
const newStorage = await migrate(oldStorage);
|
|
|
|
|
|
|
|
expect(newStorage.data).toStrictEqual(oldStorage.data);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('deletes the "phishing" property', async () => {
|
|
|
|
const oldStorage = {
|
2023-02-16 20:23:29 +01:00
|
|
|
meta: {
|
2023-03-06 14:36:01 +01:00
|
|
|
version: 77,
|
2023-02-16 20:23:29 +01:00
|
|
|
},
|
2023-03-06 14:36:01 +01:00
|
|
|
data: { PhishingController: { test: '123', phishing: [] } },
|
|
|
|
};
|
|
|
|
|
|
|
|
const newStorage = await migrate(oldStorage);
|
|
|
|
|
|
|
|
expect(newStorage.data).toStrictEqual({
|
|
|
|
PhishingController: { test: '123' },
|
2023-02-16 20:23:29 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-03-06 14:36:01 +01:00
|
|
|
it('deletes the "lastFetched" property', async () => {
|
2023-02-16 20:23:29 +01:00
|
|
|
const oldStorage = {
|
|
|
|
meta: {
|
|
|
|
version: 77,
|
|
|
|
},
|
2023-03-06 14:36:01 +01:00
|
|
|
data: { PhishingController: { test: '123', lastFetched: 100 } },
|
2023-02-16 20:23:29 +01:00
|
|
|
};
|
|
|
|
|
2023-03-06 14:36:01 +01:00
|
|
|
const newStorage = await migrate(oldStorage);
|
|
|
|
|
|
|
|
expect(newStorage.data).toStrictEqual({
|
|
|
|
PhishingController: { test: '123' },
|
2023-02-16 20:23:29 +01:00
|
|
|
});
|
|
|
|
});
|
2023-03-06 14:36:01 +01:00
|
|
|
|
|
|
|
it('deletes the "phishing" and "lastFetched" properties', async () => {
|
2023-02-16 20:23:29 +01:00
|
|
|
const oldStorage = {
|
|
|
|
meta: {
|
|
|
|
version: 77,
|
|
|
|
},
|
|
|
|
data: {
|
2023-03-06 14:36:01 +01:00
|
|
|
PhishingController: { test: '123', lastFetched: 100, phishing: [] },
|
2023-02-16 20:23:29 +01:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2023-03-06 14:36:01 +01:00
|
|
|
const newStorage = await migrate(oldStorage);
|
|
|
|
|
|
|
|
expect(newStorage.data).toStrictEqual({
|
|
|
|
PhishingController: { test: '123' },
|
2023-02-16 20:23:29 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|