27 lines
1.2 KiB
TypeScript
27 lines
1.2 KiB
TypeScript
// SPDX-License-Identifier: LicenseRef-ConusAI-Template-1.0
|
|
// `/api/ready` (spec §13): the migration level it compares against, read from this repository's
|
|
// folders. The verdict is `@conusai-kit/host/http`'s `checkReadiness` and its tests.
|
|
|
|
import { readdirSync } from "node:fs"
|
|
import { appRoot, expectedMigrations, GRANT_MIGRATIONS, missingMigrations } from "@app/config"
|
|
import { appModules } from "@app/modules"
|
|
import { buildRegistry } from "@conusai-kit/core"
|
|
import { describe, expect, it } from "vitest"
|
|
|
|
describe("the migration level", () => {
|
|
it("lists the app's files, then each module's, then the grants the migrate job adds", async () => {
|
|
const expected = await expectedMigrations(buildRegistry([...appModules]))
|
|
const files = readdirSync(`${appRoot()}/migrations/postgres`)
|
|
.filter((name) => name.endsWith(".sql"))
|
|
.map((name) => name.replace(/\.sql$/, ""))
|
|
.sort()
|
|
expect(expected.slice(0, files.length)).toEqual(files)
|
|
expect(expected).toContain("notes/0001_notes") // kit:notes
|
|
expect(expected.slice(-GRANT_MIGRATIONS.length)).toEqual([...GRANT_MIGRATIONS])
|
|
})
|
|
|
|
it("names what a database lacks", () => {
|
|
expect(missingMigrations(["a", "b", "c"], new Set(["a", "c", "z"]))).toEqual(["b"])
|
|
})
|
|
})
|