import assert from "node:assert/strict"; import { randomUUID } from "node:crypto"; import { spawnSync } from "node:child_process"; import { fileURLToPath } from "node:url"; import test from "node:test"; import { startPostgresFixture, type PostgresFixture } from "./helpers/postgres-fixture.ts"; // TASK-chart-types-and-report-buttons-20260928 T6. Fictional users only. // Runs in the gate's DB job (needs Docker). const runner = fileURLToPath(new URL("../scripts/db-migrate.mjs", import.meta.url)); const docker = spawnSync("docker", ["version", "--format", "{{.Server.Version}}"], { stdio: "ignore" }).status === 0; const SERVICE = ["service_runtime", "service-runtime-test-password"] as const; function applyMigrations(fixture: PostgresFixture): void { const result = spawnSync(process.execPath, [runner], { encoding: "utf8", env: { ...process.env, SCHEMA_DATABASE_URL: fixture.connectionUrl("schema_owner", "schema-owner-test-password") }, }); assert.equal(result.status, 0, result.stderr || result.stdout); } test("profiles.ayanamsa accepts the six offered values and rejects the rest", { skip: docker ? false : "docker unavailable", }, () => { const fixture = startPostgresFixture(); try { applyMigrations(fixture); const owner = randomUUID(); fixture.psql(`insert into identity.users (id, name, email, email_verified, email_verified_at) values ('${owner}', 'Fictional ayanamsa owner', '${owner}@example.invalid', true, now());`); assert.equal(fixture.psql(`select ayanamsa from public.profiles where id = '${owner}'`), "raman"); // The account PATCH writes through service_role. for (const value of ["raman", "lahiri", "kp", "true_citra", "true_pushya", "fagan_bradley"]) { fixture.psqlAs(...SERVICE, `set role service_role; update public.profiles set ayanamsa = '${value}' where id = '${owner}';`); assert.equal(fixture.psql(`select ayanamsa from public.profiles where id = '${owner}'`), value); } for (const value of ["djwhal_khul", "sassanian", "fagan"]) { assert.throws( () => fixture.psql(`update public.profiles set ayanamsa = '${value}' where id = '${owner}'`), /profiles_ayanamsa_check/, ); } } finally { fixture.stop(); } });