Remove migrations and testing for it.
This commit is contained in:
parent
8eb5e7d972
commit
6a5d39e8ad
|
@ -1,62 +0,0 @@
|
|||
import type {Migration} from '@holllo/migration-helper';
|
||||
|
||||
export const dataMigrations: Array<Migration<string>> = [
|
||||
{
|
||||
version: '0.1.7',
|
||||
async migrate(data: Record<string, any>) {
|
||||
const migrated: Record<string, any> = {
|
||||
version: '0.1.7',
|
||||
};
|
||||
|
||||
const items = (data.queue as Queue.Item[]) ?? [];
|
||||
for (const item of items) {
|
||||
const key = `qi${item.id}`;
|
||||
migrated[key] = item;
|
||||
}
|
||||
|
||||
return migrated;
|
||||
},
|
||||
},
|
||||
{
|
||||
version: '0.3.0',
|
||||
async migrate(data: Record<string, any>) {
|
||||
const migrated: Record<string, any> = {
|
||||
version: '0.3.0',
|
||||
};
|
||||
|
||||
for (const [key, value] of Object.entries<Queue.Item>(data)) {
|
||||
if (key.startsWith('qi')) {
|
||||
migrated[key] = value;
|
||||
migrated[key].sortIndex = value.id;
|
||||
}
|
||||
}
|
||||
|
||||
return migrated;
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export function deserializeQueue(data: Record<string, any>): Queue.Item[] {
|
||||
const deserialized: Queue.Item[] = [];
|
||||
|
||||
for (const [key, item] of Object.entries(data)) {
|
||||
if (/^qi\d+$/.test(key)) {
|
||||
item.added = new Date(item.added);
|
||||
deserialized.push(item);
|
||||
}
|
||||
}
|
||||
|
||||
return deserialized;
|
||||
}
|
||||
|
||||
export function serializeQueue(queue: Queue.Item[]): Record<string, any> {
|
||||
const serialized: Record<string, any> = {};
|
||||
|
||||
for (const item of queue) {
|
||||
const key = `qi${item.id}`;
|
||||
serialized[key] = {...item};
|
||||
serialized[key].added = item.added.toISOString();
|
||||
}
|
||||
|
||||
return serialized;
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
/// <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');
|
||||
});
|
|
@ -1,72 +0,0 @@
|
|||
# Snapshot report for `tests/migrations.test.ts`
|
||||
|
||||
The actual snapshot is saved in `migrations.test.ts.snap`.
|
||||
|
||||
Generated by [AVA](https://avajs.dev).
|
||||
|
||||
## dataMigrations happy path
|
||||
|
||||
> Migration 0.1.7
|
||||
|
||||
{
|
||||
qi1: {
|
||||
added: Date 2022-03-02 16:00:00 UTC {},
|
||||
id: 1,
|
||||
text: 'Sample',
|
||||
url: 'https://example.org',
|
||||
},
|
||||
version: '0.1.7',
|
||||
}
|
||||
|
||||
> Migration 0.3.0
|
||||
|
||||
{
|
||||
qi1: {
|
||||
added: Date 2022-03-02 16:00:00 UTC {},
|
||||
id: 1,
|
||||
sortIndex: 1,
|
||||
text: 'Sample',
|
||||
url: 'https://example.org',
|
||||
},
|
||||
version: '0.3.0',
|
||||
}
|
||||
|
||||
## dataMigrations unhappy path
|
||||
|
||||
> Migration 0.1.7
|
||||
|
||||
{
|
||||
version: '0.1.7',
|
||||
}
|
||||
|
||||
> Migration 0.3.0
|
||||
|
||||
{
|
||||
version: '0.3.0',
|
||||
}
|
||||
|
||||
## Serializing & Deserializing Queue
|
||||
|
||||
> Serialized
|
||||
|
||||
{
|
||||
qi1: {
|
||||
added: '2022-03-02T16:00:00.000Z',
|
||||
id: 1,
|
||||
sortIndex: 1,
|
||||
text: 'Sample',
|
||||
url: 'https://example.org',
|
||||
},
|
||||
}
|
||||
|
||||
> Deserialized
|
||||
|
||||
[
|
||||
{
|
||||
added: Date 2022-03-02 16:00:00 UTC {},
|
||||
id: 1,
|
||||
sortIndex: 1,
|
||||
text: 'Sample',
|
||||
url: 'https://example.org',
|
||||
},
|
||||
]
|
Binary file not shown.
Loading…
Reference in New Issue