From 6a5d39e8adfd4f76d1a99cf44b1db583e837b8a7 Mon Sep 17 00:00:00 2001 From: Bauke Date: Thu, 4 May 2023 14:25:01 +0200 Subject: [PATCH] Remove migrations and testing for it. --- source/settings/migrations.ts | 62 --------------- tests/migrations.test.ts | 55 ------------- tests/snapshots/tests/migrations.test.ts.md | 72 ------------------ tests/snapshots/tests/migrations.test.ts.snap | Bin 588 -> 0 bytes 4 files changed, 189 deletions(-) delete mode 100644 source/settings/migrations.ts delete mode 100644 tests/migrations.test.ts delete mode 100644 tests/snapshots/tests/migrations.test.ts.md delete mode 100644 tests/snapshots/tests/migrations.test.ts.snap diff --git a/source/settings/migrations.ts b/source/settings/migrations.ts deleted file mode 100644 index 4cea947..0000000 --- a/source/settings/migrations.ts +++ /dev/null @@ -1,62 +0,0 @@ -import type {Migration} from '@holllo/migration-helper'; - -export const dataMigrations: Array> = [ - { - version: '0.1.7', - async migrate(data: Record) { - const migrated: Record = { - 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) { - const migrated: Record = { - version: '0.3.0', - }; - - for (const [key, value] of Object.entries(data)) { - if (key.startsWith('qi')) { - migrated[key] = value; - migrated[key].sortIndex = value.id; - } - } - - return migrated; - }, - }, -]; - -export function deserializeQueue(data: Record): 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 { - const serialized: Record = {}; - - for (const item of queue) { - const key = `qi${item.id}`; - serialized[key] = {...item}; - serialized[key].added = item.added.toISOString(); - } - - return serialized; -} diff --git a/tests/migrations.test.ts b/tests/migrations.test.ts deleted file mode 100644 index 6f74412..0000000 --- a/tests/migrations.test.ts +++ /dev/null @@ -1,55 +0,0 @@ -/// - -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 = { - latestVersion: '0.1.0', - queue: [queueItemSample], - }; - - for (const migration of dataMigrations) { - data = (await migration.migrate(data)) as Record; - t.snapshot(data, `Migration ${migration.version}`); - } -}); - -test('dataMigrations unhappy path', async (t) => { - let data: Record = {}; - - for (const migration of dataMigrations) { - data = (await migration.migrate(data)) as Record; - 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'); -}); diff --git a/tests/snapshots/tests/migrations.test.ts.md b/tests/snapshots/tests/migrations.test.ts.md deleted file mode 100644 index 589909c..0000000 --- a/tests/snapshots/tests/migrations.test.ts.md +++ /dev/null @@ -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', - }, - ] diff --git a/tests/snapshots/tests/migrations.test.ts.snap b/tests/snapshots/tests/migrations.test.ts.snap deleted file mode 100644 index a4c37c432f0d5d3af19172ea8730b5a45c97a831..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 588 zcmV-S0<--=RzVsUM3700000000BsRKIW2Kp4Hxj@<%+Bq|cWgk&VdMBR&vD5_YHx@4#j3PP0a z(mRrCjcx8ODCtyz#KgeAKqUs~(0_o5frXukfxm#25k5Oy8{CqhN+2N0(|u=ur{{a` z-MzTqj?>k3{bWlRX=2eo!_HZbQj6PDv8`vi#$|M5xEEof6J9~vI=mA{ zbgE1<;iCUXd&=1fa`XVuW=k8o+Dl(-XlIw azO#on#rgmGrik}qF8DX<^kPJg2LJ$(*Ct~C