Files
crosscode-platform/apps/accounts/e2e/signin.spec.ts
T
joshuaandClaude Opus 5.5 fdd53ae4db Accounts: Playwright on the real pages; interaction cookie path fix
The interaction address is now /api/v2/interaction/<uid> (redirecting to
the sign-in page): oidc-provider scopes its cookie to that path, so every
step's API call gets it. Before, a real browser never sent it and every
sign-in 'expired'; the test browser now honours cookie paths too.
8 Playwright tests (deep link, wrong password, foreign return address,
sign-up, reset mid-sign-in, 2FA set-up, account page, admin) on the real
backend with an in-memory database, no Postgres needed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 15:01:32 +02:00

104 lines
6.2 KiB
TypeScript

import { expect, test, type Page } from "@playwright/test";
// The release checks (ROADMAP-v3 §9) on Accounts' real pages: signing in from a deep link lands
// back on that page, through sign-up, a password reset and two-step sign-in set up on the way; a
// foreign return address is refused. A test product (e2e/server.ts) starts and finishes sign-ins.
const PRODUCT = "http://localhost:5211";
const helper = async (page: Page, path: string) => (await (await page.request.get(`${PRODUCT}${path}`)).text()).trim();
async function signIn(page: Page, email: string, password = "Correct-horse-1") {
await page.getByLabel("Email address").fill(email);
await page.getByLabel("Password").fill(password);
await page.getByRole("button", { name: "Sign in" }).click();
}
test("signing in from a deep link returns to that exact page", async ({ page }) => {
await page.goto(`${PRODUCT}/start?returnTo=${encodeURIComponent("/events/youth-camp/register?ticket=adult")}`);
await expect(page.getByRole("heading", { name: "Sign in to Hope Family Church" })).toBeVisible();
await signIn(page, "thandi@hope.test");
await expect(page.locator("#return")).toHaveText("/events/youth-camp/register?ticket=adult");
await expect(page.locator("#email")).toHaveText("thandi@hope.test");
});
test("a wrong password says so without saying whether the account exists", async ({ page }) => {
await page.goto(`${PRODUCT}/start?returnTo=/`);
await signIn(page, "thandi@hope.test", "not-the-password");
await expect(page.locator("main").getByRole("alert")).toHaveText("That email address and password don't match.");
await signIn(page, "nobody@hope.test", "not-the-password");
await expect(page.locator("main").getByRole("alert")).toHaveText("That email address and password don't match.");
});
test("a foreign return address ends on the product's home page", async ({ page }) => {
await page.goto(`${PRODUCT}/start?returnTo=${encodeURIComponent("//evil.example/steal")}`);
await signIn(page, "thandi@hope.test");
await expect(page.locator("#return")).toHaveText("/");
});
test("sign-up with an emailed code, back to the page", async ({ page }) => {
await page.goto(`${PRODUCT}/start?returnTo=${encodeURIComponent("/give?fund=building")}`);
await page.getByRole("button", { name: "Create an account" }).click();
await page.getByLabel("Your name").fill("New Person");
await page.getByLabel("Email address").fill("new@hope.test");
await page.getByLabel("Password").fill("Correct-horse-2");
await page.getByLabel(/privacy notice/).check();
await page.getByRole("button", { name: "Create account" }).click();
await expect(page.getByRole("heading", { name: "Check your email" })).toBeVisible();
await page.getByLabel("Code").fill(await helper(page, "/test/code?to=new@hope.test"));
await page.getByRole("button", { name: "Continue" }).click();
await expect(page.locator("#return")).toHaveText("/give?fund=building");
await expect(page.locator("#email")).toHaveText("new@hope.test");
});
test("forgot password in the middle of signing in still returns to the page", async ({ page }) => {
await page.goto(`${PRODUCT}/start?returnTo=/my-tickets`);
await page.getByRole("link", { name: "Forgot your password?" }).click();
await page.getByLabel("Email address").fill("thandi@hope.test");
await page.getByRole("button", { name: "Send the link" }).click();
await expect(page.getByRole("status")).toContainText("a link is on its way");
await page.goto(await helper(page, "/test/link?to=thandi@hope.test"));
await page.getByLabel("New password").fill("Correct-horse-1");
await page.getByRole("button", { name: "Save and sign in" }).click();
await signIn(page, "thandi@hope.test");
await expect(page.locator("#return")).toHaveText("/my-tickets");
});
test("a product asking for two-step sign-in: set up with an app, recovery codes, then back", async ({ page }) => {
await page.goto(`${PRODUCT}/start?mfa=1&returnTo=/dashboard`);
await signIn(page, "thandi@hope.test");
await expect(page.getByRole("heading", { name: "Set up two-step sign-in" })).toBeVisible();
await page.getByRole("button", { name: /An authenticator app/ }).click();
const key = (await page.getByText(/Or type this key:/).innerText()).replace(/.*:\s*/, "").trim();
await page.getByLabel("Code").fill(await helper(page, `/test/totp?secret=${key}`));
await page.getByRole("button", { name: "Turn on" }).click();
await expect(page.getByRole("heading", { name: "Save your recovery codes" })).toBeVisible();
await page.getByRole("button", { name: "I've saved them" }).click();
await expect(page.locator("#return")).toHaveText("/dashboard");
await expect(page.locator("#amr")).toHaveText("pwd otp mfa");
});
test("the account page: signs in first, then saves details", async ({ page }) => {
await page.goto("/account");
await expect(page.getByRole("heading", { name: "Sign in to Hope Family Church" })).toBeVisible();
await page.getByLabel("Email address").fill("new@hope.test");
await page.getByLabel("Password").fill("Correct-horse-2");
await page.getByRole("button", { name: "Sign in" }).click();
await expect(page.getByRole("heading", { name: "Your account" })).toBeVisible();
await page.getByLabel("Name").fill("New Person-Smith");
await page.getByRole("button", { name: "Save", exact: true }).click();
await expect(page.getByRole("status")).toContainText("Your details are saved");
});
test("admin: needs two-step sign-in, then lists people", async ({ page }) => {
await page.goto("/admin");
await signIn(page, "admin@hope.test");
await expect(page.getByRole("heading", { name: "Set up two-step sign-in" })).toBeVisible();
await expect(page.getByText("Admins must use a second step")).toBeVisible();
await page.getByRole("button", { name: /An authenticator app/ }).click();
const key = (await page.getByText(/Or type this key:/).innerText()).replace(/.*:\s*/, "").trim();
await page.getByLabel("Code").fill(await helper(page, `/test/totp?secret=${key}`));
await page.getByRole("button", { name: "Turn on" }).click();
await page.getByRole("button", { name: "I've saved them" }).click();
await expect(page.getByRole("heading", { name: "Accounts admin" })).toBeVisible();
await expect(page.getByText("thandi@hope.test")).toBeVisible();
});