Files
template-app/test/registry.test.ts
T

57 lines
2.5 KiB
TypeScript

// SPDX-License-Identifier: LicenseRef-ConusAI-Template-1.0
// The registry this app boots with (spec §4.1): built from the manifests in modules/index.ts and
// from nothing else, so what the router, the navigation and the permissions hold is what the
// modules declared.
import { buildRegistry } from "@conusai-kit/core"
import { entitiesOf } from "@conusai-kit/data"
import { KIT_JOBS_ENTITIES } from "@conusai-kit/jobs-pgboss"
import { describe, expect, it } from "vitest"
import { appModules, domainModules, kernelModules } from "../modules/index.js"
const registry = buildRegistry([...appModules])
describe("the app registry", () => {
it("boots with the kernel modules a tenant app needs", () => {
const kernel = ["tenancy", "auth", "files", "proposals"]
kernel.push("guides") // kit:guides
kernel.push("support") // kit:support
expect(kernelModules.map((module) => module.id)).toEqual(kernel)
expect(appModules.length).toBe(kernelModules.length + domainModules.length)
})
it("registers every tenancy and auth procedure", () => {
const names = [...registry.procedures.keys()]
expect(names).toContain("tenancy.org.create")
expect(names).toContain("tenancy.member.invite")
expect(names).toContain("auth.apiKey.create")
expect(registry.procedures.size).toBeGreaterThanOrEqual(15)
})
it("declares a permission for every tenant-scoped procedure", () => {
for (const [name, { def }] of registry.procedures) {
if (def.scope === "public" || def.scope === "user") continue
expect(registry.permissions[def.permission], `${name} declares ${def.permission}`).toBeTruthy()
}
})
it("lists every tenant-scoped procedure as needing an isolation fixture", () => {
const tenantScoped = [...registry.procedures.values()].filter(
({ def }) => def.scope !== "public" && def.scope !== "user",
)
expect(registry.isolationFixtures.length).toBe(tenantScoped.length)
})
it("has a table for every entity the app's schema must hold", () => {
const tables = [...entitiesOf(registry, "postgres"), ...KIT_JOBS_ENTITIES].map((entity) => entity.table)
expect(tables).toContain("organizations")
expect(tables).toContain("auth_sessions")
expect(tables).toContain("kit_processed_events")
expect(new Set(tables).size).toBe(tables.length)
})
it("gives the web shell a navigation entry per kernel area", () => {
expect(registry.nav.map((item) => item.href)).toEqual(expect.arrayContaining(["members", "settings", "api-keys"]))
})
})