queue/tests/migrations.test.ts

56 lines
1.4 KiB
TypeScript

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