2023-04-19 16:08:16 +02:00
|
|
|
import { migrate } from './084';
|
2023-04-11 21:16:31 +02:00
|
|
|
|
|
|
|
describe('migration #84', () => {
|
2023-04-19 16:08:16 +02:00
|
|
|
it('updates the version metadata', async () => {
|
|
|
|
const originalVersionedData = buildOriginalVersionedData({
|
2023-04-11 21:16:31 +02:00
|
|
|
meta: {
|
2023-04-19 16:08:16 +02:00
|
|
|
version: 9999999,
|
2023-04-11 21:16:31 +02:00
|
|
|
},
|
2023-04-19 16:08:16 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
const newVersionedData = await migrate(originalVersionedData);
|
2023-04-11 21:16:31 +02:00
|
|
|
|
2023-04-19 16:08:16 +02:00
|
|
|
expect(newVersionedData.meta).toStrictEqual({
|
|
|
|
version: 84,
|
2023-04-11 21:16:31 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-04-19 16:08:16 +02:00
|
|
|
it('does not change the state if the network controller state does not exist', async () => {
|
|
|
|
const originalVersionedData = buildOriginalVersionedData({
|
2023-04-11 21:16:31 +02:00
|
|
|
data: {
|
2023-04-19 16:08:16 +02:00
|
|
|
test: '123',
|
2023-04-11 21:16:31 +02:00
|
|
|
},
|
2023-04-19 16:08:16 +02:00
|
|
|
});
|
2023-04-11 21:16:31 +02:00
|
|
|
|
2023-04-19 16:08:16 +02:00
|
|
|
const newVersionedData = await migrate(originalVersionedData);
|
2023-04-11 21:16:31 +02:00
|
|
|
|
2023-04-19 16:08:16 +02:00
|
|
|
expect(newVersionedData.data).toStrictEqual(originalVersionedData.data);
|
2023-04-11 21:16:31 +02:00
|
|
|
});
|
|
|
|
|
2023-04-19 16:08:16 +02:00
|
|
|
const nonObjects = [undefined, null, 'test', 1, ['test']];
|
|
|
|
for (const invalidState of nonObjects) {
|
|
|
|
it(`does not change the state if the network controller state is ${invalidState}`, async () => {
|
|
|
|
const originalVersionedData = buildOriginalVersionedData({
|
|
|
|
data: {
|
|
|
|
NetworkController: invalidState,
|
|
|
|
},
|
|
|
|
});
|
2023-04-11 21:16:31 +02:00
|
|
|
|
2023-04-19 16:08:16 +02:00
|
|
|
const newVersionedData = await migrate(originalVersionedData);
|
2023-04-11 21:16:31 +02:00
|
|
|
|
2023-04-19 16:08:16 +02:00
|
|
|
expect(newVersionedData.data).toStrictEqual(originalVersionedData.data);
|
|
|
|
});
|
|
|
|
}
|
2023-04-11 21:16:31 +02:00
|
|
|
|
2023-04-19 16:08:16 +02:00
|
|
|
it('does not change the state if the network controller state does not include "network"', async () => {
|
|
|
|
const originalVersionedData = buildOriginalVersionedData({
|
2023-04-11 21:16:31 +02:00
|
|
|
data: {
|
2023-04-19 16:08:16 +02:00
|
|
|
NetworkController: {
|
|
|
|
test: '123',
|
|
|
|
},
|
2023-04-11 21:16:31 +02:00
|
|
|
},
|
2023-04-19 16:08:16 +02:00
|
|
|
});
|
2023-04-11 21:16:31 +02:00
|
|
|
|
2023-04-19 16:08:16 +02:00
|
|
|
const newVersionedData = await migrate(originalVersionedData);
|
2023-04-11 21:16:31 +02:00
|
|
|
|
2023-04-19 16:08:16 +02:00
|
|
|
expect(newVersionedData.data).toStrictEqual(originalVersionedData.data);
|
2023-04-11 21:16:31 +02:00
|
|
|
});
|
|
|
|
|
2023-04-19 16:08:16 +02:00
|
|
|
it('replaces "network" in the network controller state with "networkId": null, "networkStatus": "unknown" if it is "loading"', async () => {
|
|
|
|
const originalVersionedData = buildOriginalVersionedData({
|
2023-04-11 21:16:31 +02:00
|
|
|
data: {
|
|
|
|
NetworkController: {
|
2023-04-19 16:08:16 +02:00
|
|
|
network: 'loading',
|
2023-04-11 21:16:31 +02:00
|
|
|
},
|
|
|
|
},
|
2023-04-19 16:08:16 +02:00
|
|
|
});
|
2023-04-11 21:16:31 +02:00
|
|
|
|
2023-04-19 16:08:16 +02:00
|
|
|
const newVersionedData = await migrate(originalVersionedData);
|
2023-04-11 21:16:31 +02:00
|
|
|
|
2023-04-19 16:08:16 +02:00
|
|
|
expect(newVersionedData.data).toStrictEqual({
|
|
|
|
NetworkController: {
|
|
|
|
networkId: null,
|
|
|
|
networkStatus: 'unknown',
|
2023-04-11 21:16:31 +02:00
|
|
|
},
|
2023-04-19 16:08:16 +02:00
|
|
|
});
|
2023-04-11 21:16:31 +02:00
|
|
|
});
|
|
|
|
|
2023-04-19 16:08:16 +02:00
|
|
|
it('replaces "network" in the network controller state with "networkId": network, "networkStatus": "available" if it is not "loading"', async () => {
|
|
|
|
const originalVersionedData = buildOriginalVersionedData({
|
2023-04-11 21:16:31 +02:00
|
|
|
data: {
|
|
|
|
NetworkController: {
|
2023-04-19 16:08:16 +02:00
|
|
|
network: '12345',
|
2023-04-11 21:16:31 +02:00
|
|
|
},
|
|
|
|
},
|
2023-04-19 16:08:16 +02:00
|
|
|
});
|
2023-04-11 21:16:31 +02:00
|
|
|
|
2023-04-19 16:08:16 +02:00
|
|
|
const newVersionedData = await migrate(originalVersionedData);
|
2023-04-11 21:16:31 +02:00
|
|
|
|
2023-04-19 16:08:16 +02:00
|
|
|
expect(newVersionedData.data).toStrictEqual({
|
|
|
|
NetworkController: {
|
|
|
|
networkId: '12345',
|
|
|
|
networkStatus: 'available',
|
2023-04-11 21:16:31 +02:00
|
|
|
},
|
2023-04-19 16:08:16 +02:00
|
|
|
});
|
2023-04-11 21:16:31 +02:00
|
|
|
});
|
|
|
|
});
|
2023-04-19 16:08:16 +02:00
|
|
|
|
|
|
|
function buildOriginalVersionedData({ meta = {}, data = {} } = {}) {
|
|
|
|
return {
|
|
|
|
meta: { version: 999999, ...meta },
|
|
|
|
data: { ...data },
|
|
|
|
};
|
|
|
|
}
|