import { expect, type Page } from "@playwright/test"; const BASE = "http://localhost:3000"; /** * Shared E2E helpers. Both test files run against the same Postgres, so they * share the dev-console sign-in transport and the DB reset used to establish a * known-clean state before each suite. */ /** * Dev console transport: request a magic link, then complete it in the browser * context so the Auth.js session cookie is set for the navigation under test. */ export async function signInAs(page: Page, email: string) { const res = await page.request.post(`${BASE}/api/dev/magic-link`, { data: { email }, }); expect(res.ok(), "magic-link request should succeed").toBe(true); const body = (await res.json()) as { url?: string }; expect(body.url, "magic-link should return a sign-in url").toBeTruthy(); await page.goto(body.url!); await expect(page).toHaveURL(/complete/); } /** * Reset the DB to the clean seed. Admin-only (admin.settings): truncates the * seed-owned tables and repopulates them, so each suite starts from a known * state instead of accumulating the mutations of prior runs. Runs from inside * the page (page.request does not share the session cookie). */ export async function resetDb(page: Page) { await signInAs(page, "admin@glenloch.local"); const status = await page.evaluate(async () => { const res = await fetch("/api/dev/reset", { method: "POST" }); return res.status; }); expect(status, "admin reset should succeed").toBe(200); } export { BASE };