Files
NextChair/e2e/global-setup.ts
T
Stefan Lazic 3300045d9e Staff / Owner
Merged staff and owner settings
2026-08-05 16:35:52 +01:00

35 lines
1.7 KiB
TypeScript

import { execFileSync } from "node:child_process";
/**
* Applies migrations and loads the dev/demo seed data against whatever
* DATABASE_URL points at before the suite runs. Deliberately does not
* create or tear down the database itself — same division of
* responsibility as `npm run test:integration`, where the caller is
* responsible for pointing DATABASE_URL at a disposable Postgres.
*/
export default function globalSetup() {
if (!process.env.DATABASE_URL) {
throw new Error(
"DATABASE_URL is not set. Point it at a disposable Postgres before running the e2e suite, e.g.\n" +
' DATABASE_URL="postgresql://user:pass@localhost:5432/nextchair_e2e" npm run test:e2e',
);
}
const env = {
...process.env,
// A Super Administrator is provisioned separately from prisma/seed.ts
// (see scripts/ensure-super-admin.ts's own doc comment — it deliberately
// stays out of the dev/demo seed) — the merged-nav E2E scenarios need
// one to sign in as, so this fixes deterministic test-only credentials
// when the caller hasn't already set their own (same fallback pattern
// as AUTH_SECRET in playwright.config.ts).
SUPER_ADMIN_EMAIL: process.env.SUPER_ADMIN_EMAIL || "superadmin@blakeheritage.co.uk",
SUPER_ADMIN_PASSWORD: process.env.SUPER_ADMIN_PASSWORD || "password123",
SUPER_ADMIN_FIRST_NAME: process.env.SUPER_ADMIN_FIRST_NAME || "Super",
SUPER_ADMIN_LAST_NAME: process.env.SUPER_ADMIN_LAST_NAME || "Admin",
};
execFileSync("npx", ["prisma", "migrate", "deploy"], { stdio: "inherit", env });
execFileSync("npx", ["tsx", "prisma/seed.ts"], { stdio: "inherit", env });
execFileSync("npx", ["tsx", "scripts/ensure-super-admin.ts"], { stdio: "inherit", env });
}