trails/e2e/auth.test.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

81 lines
3.3 KiB
TypeScript

import { test, expect, waitForHydration, type CDPSession, type Page } from "./fixtures/test";
import { setupVirtualAuthenticator, removeVirtualAuthenticator, submitRegistration, logout } from "./helpers/auth";
test.describe("Passkey Authentication", () => {
test("register with passkey and sign in", async ({ page }) => {
const cdp = await page.context().newCDPSession(page);
const authenticatorId = await setupVirtualAuthenticator(cdp);
const email = `test-${Date.now()}@example.com`;
const username = `testuser${Date.now()}`;
// Register
await submitRegistration(page, email, username);
await expect(page).toHaveURL("/", { timeout: 10000 });
// The avatar button's aria-label is the displayName or username;
// for a freshly-registered user with no displayName set, that's
// the username.
await expect(page.getByRole("navigation").getByRole("button", { name: username })).toBeVisible({ timeout: 5000 });
// Log out
await logout(page, username);
// Sign in with passkey
await page.goto("/auth/login");
await waitForHydration(page);
await page.getByRole("button", { name: /Sign in with Passkey/ }).click();
await expect(page).toHaveURL("/", { timeout: 10000 });
await expect(page.getByRole("navigation").getByRole("button", { name: username })).toBeVisible({ timeout: 5000 });
await removeVirtualAuthenticator(cdp, authenticatorId);
});
test("passkey login fails with no registered credential", async ({ page }) => {
const cdp = await page.context().newCDPSession(page);
const authenticatorId = await setupVirtualAuthenticator(cdp);
await page.goto("/auth/login");
await waitForHydration(page);
await page.getByRole("button", { name: /Sign in with Passkey/ }).click();
await expect(page.getByText(/No passkey found/i)).toBeVisible({ timeout: 10000 });
await removeVirtualAuthenticator(cdp, authenticatorId);
});
test("register rejects duplicate email", async ({ page }) => {
const cdp = await page.context().newCDPSession(page);
const authenticatorId = await setupVirtualAuthenticator(cdp);
const email = `dup-${Date.now()}@example.com`;
const firstUsername = `first${Date.now()}`;
// Register first user
await submitRegistration(page, email, firstUsername);
await expect(page).toHaveURL("/", { timeout: 10000 });
await logout(page, firstUsername);
// Try to register with same email
await submitRegistration(page, email, `second${Date.now()}`);
await expect(page.getByText(/already in use/i)).toBeVisible({ timeout: 10000 });
await removeVirtualAuthenticator(cdp, authenticatorId);
});
test("register rejects duplicate username", async ({ page }) => {
const cdp = await page.context().newCDPSession(page);
const authenticatorId = await setupVirtualAuthenticator(cdp);
const username = `uniq${Date.now()}`;
// Register first user
await submitRegistration(page, `first-${Date.now()}@example.com`, username);
await expect(page).toHaveURL("/", { timeout: 10000 });
await logout(page, username);
// Try to register with same username
await submitRegistration(page, `second-${Date.now()}@example.com`, username);
await expect(page.getByText(/already taken/i)).toBeVisible({ timeout: 10000 });
await removeVirtualAuthenticator(cdp, authenticatorId);
});
});