Files
budget2.0/src/store/migrations.test.ts
T
Lucas WintherandClaude Opus 5 15ae45a804 feat(store): add IndexedDB persistence and schema migrations
The dataset is one atomic record, so a write can never leave posts and
purchases inconsistent.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-01 19:55:08 +02:00

25 lines
997 B
TypeScript

import { test, expect, describe } from "bun:test";
import { migrate, UnsupportedSchemaError } from "./migrations.ts";
import { createSeedDataset, SCHEMA_VERSION } from "../domain/seed.ts";
describe("migrate", () => {
test("passes a current-version dataset through unchanged", () => {
const data = createSeedDataset("2026-09");
expect(migrate(data)).toEqual(data);
});
test("rejects a version newer than this build understands", () => {
const future = { ...createSeedDataset("2026-09"), settings: { baseCurrency: "DKK", foldStartMonth: "2026-09", schemaVersion: SCHEMA_VERSION + 1 } };
expect(() => migrate(future)).toThrow(UnsupportedSchemaError);
});
test("rejects a value that is not an object", () => {
expect(() => migrate("nope")).toThrow(/not a dataset/i);
expect(() => migrate(null)).toThrow(/not a dataset/i);
});
test("rejects a dataset with no schemaVersion", () => {
expect(() => migrate({ posts: [] })).toThrow(/schemaVersion/);
});
});