49 lines
1.2 KiB
TypeScript
49 lines
1.2 KiB
TypeScript
|
/// <reference path="../source/types.d.ts" />
|
||
|
|
||
|
import test from 'ava';
|
||
|
|
||
|
import {
|
||
|
dataMigrations,
|
||
|
deserializeQueue,
|
||
|
serializeQueue,
|
||
|
} from '../source/settings/migrations';
|
||
|
|
||
|
const queueItemSample: Queue.Item = {
|
||
|
added: new Date('2022-03-02T16:00:00Z'),
|
||
|
id: 1,
|
||
|
text: 'Sample',
|
||
|
url: 'https://example.org',
|
||
|
};
|
||
|
|
||
|
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) => {
|
||
|
const serialized = serializeQueue([queueItemSample]);
|
||
|
t.snapshot(serialized, 'Serialized');
|
||
|
|
||
|
serialized.extra = 'Extra';
|
||
|
serialized.version = '0.0.0';
|
||
|
|
||
|
const deserialized = deserializeQueue(serialized);
|
||
|
t.snapshot(deserialized, 'Deserialized');
|
||
|
});
|