familynido/web/familynido-web/e2e/auth.setup.ts
Pablo Fernández a308041d59 Initial commit
FamilyNido — a self-hosted PWA for a single household: shared calendar,
chores, meals, school agenda, health records and a family wall. One
instance per family, deployable with `docker compose` on any home
server.

Stack: .NET 10 (ASP.NET Core Minimal APIs) + EF Core 10 + PostgreSQL 16
on the backend, Angular 21 (standalone, signals, zoneless) + Tailwind
CSS v4 on the frontend, SignalR for realtime, optional OIDC alongside
local credentials, integration via a versioned `/api/v1/**` public API.

See README.md for the module overview and how to deploy.
2026-05-13 00:23:14 +02:00

27 lines
1.1 KiB
TypeScript

import { expect, test as setup } from '@playwright/test';
const STATE_PATH = 'e2e/.auth/state.json';
/**
* Logs in once via the local-credentials endpoint and persists the resulting
* cookie as Playwright "storage state". Every other spec project depends on
* this setup and starts pre-authenticated.
*
* Reads E2E_USER_EMAIL and E2E_USER_PASSWORD; bails loudly if either is
* missing so a misconfigured run fails fast instead of looping through
* unauthenticated tests.
*/
setup('authenticate via local credentials', async ({ request, baseURL }) => {
const email = process.env['E2E_USER_EMAIL'];
const password = process.env['E2E_USER_PASSWORD'];
expect(email, 'E2E_USER_EMAIL must be set').toBeTruthy();
expect(password, 'E2E_USER_PASSWORD must be set').toBeTruthy();
const response = await request.post(`${baseURL}/api/auth/local/login`, {
data: { email, password },
});
expect(response.status(), `local login should return 200, got ${response.status()}`).toBe(200);
// Persist the cookie + any localStorage; subsequent specs reuse this state.
await request.storageState({ path: STATE_PATH });
});