Files
proxdeploy/tests/helpers/db.ts
T
florian.wildeandClaude Opus 5.5 871bb3a77c feat: Grundgerüst mit Anmeldung, Layout und Design-Tokens
Next.js 16, Prisma 7, Tailwind 4 und Vitest/Playwright, Konfiguration aus
Laufzettel übernommen, weil dort derselbe Stack erprobt ist.

Die Farben der Branding-Vorgabe stehen als Tokens in globals.css, das
helle Theme setzt dieselben Namen neu. Amber und Rot sind dort
abgedunkelt, sonst reicht der Kontrast nicht – ein Test prüft beide
Themes gegen 4,5:1.

Anmeldung mit lokalem Benutzer, Rolle je Anfrage aus der Datenbank,
Audit-Log per Trigger nur anhängbar. Geprüft im gebauten Stand auf
1440 px und 390 px.

Closes #001

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 09:23:41 +02:00

29 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { PrismaPg } from "@prisma/adapter-pg";
import { PrismaClient } from "@/generated/prisma/client";
const url = process.env["TEST_DATABASE_URL"];
// In CI darf nichts still übersprungen werden – dort lieber hart abbrechen.
if (!url && process.env["CI"]) {
throw new Error("TEST_DATABASE_URL fehlt. In CI dürfen die Datenbanktests nicht übersprungen werden.");
}
export const datenbankVerfuegbar = Boolean(url);
export const testPrisma = new PrismaClient({
adapter: new PrismaPg({ connectionString: url ?? "postgresql://localhost:5437/proxdeploy_test" }),
});
/**
* Leert alle Tabellen. Das Protokoll ist per Trigger nur anhängbar – TRUNCATE löst
* Zeilen-Trigger nicht aus und ist deshalb der einzige Weg, es zu leeren.
*/
export async function datenbankLeeren(): Promise<void> {
const tabellen = await testPrisma.$queryRaw<{ tablename: string }[]>`
SELECT tablename FROM pg_tables WHERE schemaname = 'public' AND tablename NOT LIKE '_prisma%'
`;
if (tabellen.length === 0) return;
const liste = tabellen.map((t) => `"public"."${t.tablename}"`).join(", ");
await testPrisma.$executeRawUnsafe(`TRUNCATE ${liste} RESTART IDENTITY CASCADE`);
}