queue/tests/migrations.test.ts

56 lines
1.4 KiB
TypeScript
Raw Normal View History

2022-03-05 13:10:45 +00:00
/// <reference path="../source/types.d.ts" />
import test from 'ava';
import {
dataMigrations,
deserializeQueue,
serializeQueue,
2023-03-26 12:32:57 +00:00
} from '../source/settings/migrations.js';
2022-03-05 13:10:45 +00:00
const queueItemSample: Queue.Item = {
added: new Date('2022-03-02T16:00:00Z'),
id: 1,
text: 'Sample',
url: 'https://example.org',
2022-10-25 10:04:11 +00:00
} as unknown as Queue.Item;
2022-03-05 13:10:45 +00:00
test('dataMigrations happy path', async (t) => {
let data: Record<string, any> = {
latestVersion: '0.1.0',
queue: [queueItemSample],
};
for (const migration of dataMigrations) {
data = (await migration.migrate(data)) as Record<string, any>;
t.snapshot(data, `Migration ${migration.version}`);
}
});
test('dataMigrations unhappy path', async (t) => {
let data: Record<string, any> = {};
for (const migration of dataMigrations) {
data = (await migration.migrate(data)) as Record<string, any>;
t.snapshot(data, `Migration ${migration.version}`);
}
});
test('Serializing & Deserializing Queue', (t) => {
2022-10-25 10:25:41 +00:00
const sample: Queue.Item = {
added: queueItemSample.added,
id: queueItemSample.id,
sortIndex: queueItemSample.id,
text: queueItemSample.text,
url: queueItemSample.url,
};
const serialized = serializeQueue([sample]);
2022-03-05 13:10:45 +00:00
t.snapshot(serialized, 'Serialized');
serialized.extra = 'Extra';
serialized.version = '0.0.0';
const deserialized = deserializeQueue(serialized);
t.snapshot(deserialized, 'Deserialized');
});