31 lines
1.2 KiB
TypeScript
31 lines
1.2 KiB
TypeScript
import { describe, expect, test } from "vitest";
|
|
import { DASHBOARD_SCHEMA_VERSION } from "$lib/model";
|
|
import { genericDashboardFixture } from "$lib/model/fixtures/generic";
|
|
import {
|
|
UnsupportedDashboardModelVersionError,
|
|
migrateDashboardDocumentForPersistence,
|
|
} from "./model-migrations";
|
|
|
|
describe("dashboard model migrations", () => {
|
|
test("accepts the current dashboard model version without migration", () => {
|
|
const result = migrateDashboardDocumentForPersistence(genericDashboardFixture);
|
|
|
|
expect(result.valid).toBe(true);
|
|
if (!result.valid) throw new Error("expected current fixture to be valid");
|
|
expect(result.document).toEqual(genericDashboardFixture);
|
|
expect(result.fromVersion).toBe(DASHBOARD_SCHEMA_VERSION);
|
|
expect(result.toVersion).toBe(DASHBOARD_SCHEMA_VERSION);
|
|
expect(result.migrated).toBe(false);
|
|
});
|
|
|
|
test("fails unsupported model versions with an explicit migration error", () => {
|
|
const previousVersion = {
|
|
...genericDashboardFixture,
|
|
schemaVersion: "dashboard.v0",
|
|
};
|
|
|
|
expect(() => migrateDashboardDocumentForPersistence(previousVersion)).toThrow(
|
|
UnsupportedDashboardModelVersionError,
|
|
);
|
|
});
|
|
});
|