Files
Nexus/scripts/db-target-guard.test.mjs
Hartmut 19aeb2ba04
CI / Lint (push) Successful in 3m4s
CI / Typecheck (push) Successful in 3m6s
CI / Architecture Guardrails (push) Successful in 3m8s
CI / Assistant Split Regression (push) Successful in 3m48s
CI / Build (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
CI / Fresh-Linux Docker Deploy (push) Has been cancelled
CI / Release Images (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
rename(phase 3): compose/DB/infra + stray code refs capakraken → nexus (#62)
rename(phase 3): compose/DB/infra + stray code refs capakraken → nexus (#62)

Co-authored-by: Hartmut Nörenberg <hn@hartmut-noerenberg.com>
Co-committed-by: Hartmut Nörenberg <hn@hartmut-noerenberg.com>
2026-05-21 20:07:18 +02:00

36 lines
1.4 KiB
JavaScript

import assert from "node:assert/strict";
import { describe, it } from "node:test";
import {
inspectDatabaseUrl,
shouldGuardPrismaCommand,
} from "./db-target-guard.mjs";
describe("db target guard", () => {
it("accepts the expected nexus database target", () => {
const result = inspectDatabaseUrl(
"postgresql://nexus:secret@localhost:5432/nexus",
"nexus",
);
assert.equal(result.databaseName, "nexus");
assert.equal(result.expectedDatabase, "nexus");
assert.equal(result.target, "postgresql://nexus@localhost:5432/nexus");
});
it("rejects a mismatched database target", () => {
assert.throws(
() => inspectDatabaseUrl("postgresql://nexus:secret@localhost:5432/planarchy", "nexus"),
/Unexpected database target 'planarchy'\. Expected 'nexus'\./,
);
});
it("guards only prisma commands that actually target a database", () => {
assert.equal(shouldGuardPrismaCommand(["generate"]), false);
assert.equal(shouldGuardPrismaCommand(["validate", "--schema", "./prisma/schema.prisma"]), false);
assert.equal(shouldGuardPrismaCommand(["db", "push", "--schema", "./prisma/schema.prisma"]), true);
assert.equal(shouldGuardPrismaCommand(["migrate", "deploy", "--schema", "./prisma/schema.prisma"]), true);
assert.equal(shouldGuardPrismaCommand(["studio", "--schema", "./prisma/schema.prisma"]), true);
assert.equal(shouldGuardPrismaCommand(["db", "push", "--help"]), false);
});
});