28 lines
1.2 KiB
TypeScript
28 lines
1.2 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { readFileSync } from "node:fs";
|
|
import test from "node:test";
|
|
|
|
import { consultationDomainIds } from "../src/lib/consultation-domain-registry.ts";
|
|
|
|
const migration = readFileSync(
|
|
new URL("../supabase/migrations/20260814050000_consultation_domain_registry.sql", import.meta.url),
|
|
"utf8",
|
|
);
|
|
|
|
function themeConstraintValues(sql: string) {
|
|
const constraint = sql.match(/add constraint chat_sessions_theme_check[\s\S]*?check \(theme in \(([\s\S]*?)\)\);/i);
|
|
assert.ok(constraint, "chat_sessions theme constraint must be present");
|
|
return [...constraint[1].matchAll(/'([a-z][a-z0-9_-]*)'/g)].map((match) => match[1]);
|
|
}
|
|
|
|
test("chat_sessions persists exactly the canonical consultation domains", () => {
|
|
assert.deepEqual(themeConstraintValues(migration), [...consultationDomainIds]);
|
|
});
|
|
|
|
test("chat_sessions does not persist aliases or independent product routes", () => {
|
|
const values = themeConstraintValues(migration);
|
|
for (const rejected of ["relationship", "finance", "health_pressure", "home", "prashna", "muhurta", "rectification", "compatibility", "spirituality"]) {
|
|
assert.equal(values.includes(rejected), false, rejected);
|
|
}
|
|
});
|