trails/e2e/helpers/journal.ts
Ullrich Schäfer 0e267afac7
e2e: shared auth + journal seed helpers; flag unregistered specs
The virtual-authenticator setup and registerUser were copy-pasted into
six spec files and had drifted: the auth spec's copy lost the final
URL assertion, and the settings spec's variant skipped hydration and
the Terms checkbox entirely. Seed-route boilerplate and hardcoded
localhost URLs were repeated across three more files.

- helpers/auth.ts: setup/removeVirtualAuthenticator,
  submitRegistration (no outcome assertion, for expected-failure
  attempts), registerUser (asserts the signed-in redirect),
  registerFreshUser, logout
- helpers/journal.ts: JOURNAL/PLANNER base URLs, seedRoute,
  routeHasGeom, seedKomootConnection
- nine spec files now import the helpers instead of re-deriving them

Found while consolidating: settings.test.ts, explore.test.ts, and
social.test.ts are not matched by any playwright project and have
never run — which is how the settings spec's broken register helper
survived. Registering them (and fixing whatever has rotted) is a
follow-up; the config now carries a warning so the trap is at least
documented.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-10 07:31:51 +02:00

39 lines
1.6 KiB
TypeScript

// Shared journal-side constants and seed helpers. The /api/e2e/*
// endpoints only exist when the journal runs with E2E=true.
import type { APIRequestContext } from "@playwright/test";
import { expect } from "../fixtures/test";
export const JOURNAL = "http://localhost:3000";
export const PLANNER = "http://localhost:3001";
/** Mint a route + single-use callback JWT via /api/e2e/seed. */
export async function seedRoute(
request: APIRequestContext,
): Promise<{ routeId: string; token: string }> {
const resp = await request.post(`${JOURNAL}/api/e2e/seed`);
expect(resp.ok(), "POST /api/e2e/seed failed — is the journal running with E2E=true?").toBeTruthy();
return (await resp.json()) as { routeId: string; token: string };
}
/** Whether the route has PostGIS geometry stored (via /api/e2e/route/:id). */
export async function routeHasGeom(
request: APIRequestContext,
routeId: string,
): Promise<boolean> {
const resp = await request.get(`${JOURNAL}/api/e2e/route/${routeId}`);
expect(resp.ok()).toBeTruthy();
const { hasGeom } = (await resp.json()) as { hasGeom: boolean };
return hasGeom;
}
/** Seeds a Komoot connection for the e2e test user; returns the session cookie. */
export async function seedKomootConnection(
request: APIRequestContext,
mode: "public" | "authenticated" = "public",
): Promise<{ cookie: string }> {
const resp = await request.post(`${JOURNAL}/api/e2e/komoot`, { data: { mode } });
if (!resp.ok()) throw new Error(`komoot seed failed: ${resp.status()}`);
const cookie = resp.headers()["set-cookie"];
return { cookie };
}