feat: add dashboard persistence store
This commit is contained in:
parent
5eeec0dcb5
commit
5e42ee8869
18 changed files with 1181 additions and 19 deletions
31
src/lib/server/db/model-migrations.test.ts
Normal file
31
src/lib/server/db/model-migrations.test.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
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,
|
||||
);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue