From aedab573a0c8b7b54b53c8ca98ad19afd474ca6c Mon Sep 17 00:00:00 2001 From: Ivan Kalashnikov Date: Sun, 18 Jan 2026 21:10:05 +0700 Subject: [PATCH] test: add migration tests for moving settings from MiscConfig to TasksConfig --- .../migrate-misc-to-tasks-config.spec.ts | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 packages/shared-schema/tests/migrations/migrate-misc-to-tasks-config.spec.ts diff --git a/packages/shared-schema/tests/migrations/migrate-misc-to-tasks-config.spec.ts b/packages/shared-schema/tests/migrations/migrate-misc-to-tasks-config.spec.ts new file mode 100644 index 000000000..b331af008 --- /dev/null +++ b/packages/shared-schema/tests/migrations/migrate-misc-to-tasks-config.spec.ts @@ -0,0 +1,72 @@ +import { describe, it, expect } from 'vitest'; +import { MIGRATIONS } from '../../src/migrations'; + +describe('Migrate MiscConfig to TasksConfig', () => { + const migration = MIGRATIONS.find((m) => m.fromVersion === 16 && m.toVersion === 17); + + if (!migration) { + throw new Error('Migration for version 16 to 17 not found'); + } + + it('should migrate settings from misc to tasks', () => { + const initialState = { + misc: { + isConfirmBeforeTaskDelete: true, + isAutoAddWorkedOnToToday: true, + isAutMarkParentAsDone: false, + isTrayShowCurrentTask: true, + defaultProjectId: 'project_1', + taskNotesTpl: 'Template', + }, + tasks: {}, + }; + + const migratedState = migration.migrateState(initialState) as { + misc: Record; + tasks: Record; + }; + + expect(migratedState.tasks).toEqual({ + isConfirmBeforeTaskDelete: true, + isAutoAddWorkedOnToToday: true, + isAutoMarkParentAsDone: false, + isTrayShowCurrentTask: true, + defaultProjectId: 'project_1', + notesTemplate: 'Template', + }); + + expect(migratedState.misc).toEqual({}); + }); + + it('should not modify state if misc is empty', () => { + const initialState = { + misc: {}, + tasks: {}, + }; + + const migratedState = migration.migrateState(initialState) as { + misc: Record; + tasks: Record; + }; + + expect(migratedState).toEqual(initialState); + }); + + it('should not modify state if tasks already migrated', () => { + const initialState = { + misc: { + isConfirmBeforeTaskDelete: true, + }, + tasks: { + isConfirmBeforeTaskDelete: true, + }, + }; + + const migratedState = migration.migrateState(initialState) as { + misc: Record; + tasks: Record; + }; + + expect(migratedState).toEqual(initialState); + }); +});