Merge pull request #514 from trails-cool/e2e-fixtures
e2e: shared auth + journal seed helpers; flag unregistered specs
This commit is contained in:
commit
ec87445550
12 changed files with 158 additions and 241 deletions
|
|
@ -1,50 +1,5 @@
|
||||||
import { test, expect, waitForHydration, type CDPSession, type Page } from "./fixtures/test";
|
import { test, expect, waitForHydration, type CDPSession, type Page } from "./fixtures/test";
|
||||||
|
import { setupVirtualAuthenticator, removeVirtualAuthenticator, submitRegistration, logout } from "./helpers/auth";
|
||||||
// Virtual authenticator helpers
|
|
||||||
async function setupVirtualAuthenticator(cdp: CDPSession) {
|
|
||||||
await cdp.send("WebAuthn.enable");
|
|
||||||
const { authenticatorId } = await cdp.send("WebAuthn.addVirtualAuthenticator", {
|
|
||||||
options: {
|
|
||||||
protocol: "ctap2",
|
|
||||||
transport: "internal",
|
|
||||||
hasResidentKey: true,
|
|
||||||
hasUserVerification: true,
|
|
||||||
isUserVerified: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
return authenticatorId;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function removeVirtualAuthenticator(cdp: CDPSession, authenticatorId: string) {
|
|
||||||
await cdp.send("WebAuthn.removeVirtualAuthenticator", { authenticatorId });
|
|
||||||
await cdp.send("WebAuthn.disable");
|
|
||||||
}
|
|
||||||
|
|
||||||
async function registerUser(page: Page, email: string, username: string) {
|
|
||||||
await page.goto("/auth/register");
|
|
||||||
await expect(page.getByRole("heading", { name: "Register" })).toBeVisible();
|
|
||||||
await waitForHydration(page);
|
|
||||||
await page.getByLabel("Email").click();
|
|
||||||
await page.getByLabel("Email").fill(email);
|
|
||||||
await page.getByLabel("Username").click();
|
|
||||||
await page.getByLabel("Username").fill(username);
|
|
||||||
// Verify both fields retained values before submitting
|
|
||||||
await expect(page.getByLabel("Email")).toHaveValue(email);
|
|
||||||
await expect(page.getByLabel("Username")).toHaveValue(username);
|
|
||||||
// Accept the Terms of Service (required)
|
|
||||||
await page.getByRole("checkbox").check();
|
|
||||||
await page.getByRole("button", { name: /Register with Passkey/ }).click();
|
|
||||||
}
|
|
||||||
|
|
||||||
async function logout(page: Page, accountLabel: string) {
|
|
||||||
// The account cluster lives inside an avatar dropdown now. Click the
|
|
||||||
// avatar (its aria-label is displayName || username), then click the
|
|
||||||
// Log Out menuitem inside the popup.
|
|
||||||
await waitForHydration(page);
|
|
||||||
await page.getByRole("navigation").getByRole("button", { name: accountLabel }).click();
|
|
||||||
await page.getByRole("menuitem", { name: "Log Out" }).click();
|
|
||||||
await expect(page.getByRole("navigation").getByRole("link", { name: "Sign In" })).toBeVisible({ timeout: 5000 });
|
|
||||||
}
|
|
||||||
|
|
||||||
test.describe("Passkey Authentication", () => {
|
test.describe("Passkey Authentication", () => {
|
||||||
test("register with passkey and sign in", async ({ page }) => {
|
test("register with passkey and sign in", async ({ page }) => {
|
||||||
|
|
@ -55,7 +10,7 @@ test.describe("Passkey Authentication", () => {
|
||||||
const username = `testuser${Date.now()}`;
|
const username = `testuser${Date.now()}`;
|
||||||
|
|
||||||
// Register
|
// Register
|
||||||
await registerUser(page, email, username);
|
await submitRegistration(page, email, username);
|
||||||
await expect(page).toHaveURL("/", { timeout: 10000 });
|
await expect(page).toHaveURL("/", { timeout: 10000 });
|
||||||
// The avatar button's aria-label is the displayName or username;
|
// The avatar button's aria-label is the displayName or username;
|
||||||
// for a freshly-registered user with no displayName set, that's
|
// for a freshly-registered user with no displayName set, that's
|
||||||
|
|
@ -95,12 +50,12 @@ test.describe("Passkey Authentication", () => {
|
||||||
const firstUsername = `first${Date.now()}`;
|
const firstUsername = `first${Date.now()}`;
|
||||||
|
|
||||||
// Register first user
|
// Register first user
|
||||||
await registerUser(page, email, firstUsername);
|
await submitRegistration(page, email, firstUsername);
|
||||||
await expect(page).toHaveURL("/", { timeout: 10000 });
|
await expect(page).toHaveURL("/", { timeout: 10000 });
|
||||||
await logout(page, firstUsername);
|
await logout(page, firstUsername);
|
||||||
|
|
||||||
// Try to register with same email
|
// Try to register with same email
|
||||||
await registerUser(page, email, `second${Date.now()}`);
|
await submitRegistration(page, email, `second${Date.now()}`);
|
||||||
await expect(page.getByText(/already in use/i)).toBeVisible({ timeout: 10000 });
|
await expect(page.getByText(/already in use/i)).toBeVisible({ timeout: 10000 });
|
||||||
|
|
||||||
await removeVirtualAuthenticator(cdp, authenticatorId);
|
await removeVirtualAuthenticator(cdp, authenticatorId);
|
||||||
|
|
@ -113,12 +68,12 @@ test.describe("Passkey Authentication", () => {
|
||||||
const username = `uniq${Date.now()}`;
|
const username = `uniq${Date.now()}`;
|
||||||
|
|
||||||
// Register first user
|
// Register first user
|
||||||
await registerUser(page, `first-${Date.now()}@example.com`, username);
|
await submitRegistration(page, `first-${Date.now()}@example.com`, username);
|
||||||
await expect(page).toHaveURL("/", { timeout: 10000 });
|
await expect(page).toHaveURL("/", { timeout: 10000 });
|
||||||
await logout(page, username);
|
await logout(page, username);
|
||||||
|
|
||||||
// Try to register with same username
|
// Try to register with same username
|
||||||
await registerUser(page, `second-${Date.now()}@example.com`, username);
|
await submitRegistration(page, `second-${Date.now()}@example.com`, username);
|
||||||
await expect(page.getByText(/already taken/i)).toBeVisible({ timeout: 10000 });
|
await expect(page.getByText(/already taken/i)).toBeVisible({ timeout: 10000 });
|
||||||
|
|
||||||
await removeVirtualAuthenticator(cdp, authenticatorId);
|
await removeVirtualAuthenticator(cdp, authenticatorId);
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,5 @@
|
||||||
import { test, expect, waitForHydration, type CDPSession, type Page } from "./fixtures/test";
|
import { test, expect, waitForHydration, type CDPSession, type Page } from "./fixtures/test";
|
||||||
|
import { setupVirtualAuthenticator, registerUser } from "./helpers/auth";
|
||||||
async function setupVirtualAuthenticator(cdp: CDPSession) {
|
|
||||||
await cdp.send("WebAuthn.enable");
|
|
||||||
const { authenticatorId } = await cdp.send("WebAuthn.addVirtualAuthenticator", {
|
|
||||||
options: {
|
|
||||||
protocol: "ctap2",
|
|
||||||
transport: "internal",
|
|
||||||
hasResidentKey: true,
|
|
||||||
hasUserVerification: true,
|
|
||||||
isUserVerified: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
return authenticatorId;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function registerUser(page: Page, email: string, username: string) {
|
|
||||||
await page.goto("/auth/register");
|
|
||||||
await expect(page.getByRole("heading", { name: "Register" })).toBeVisible();
|
|
||||||
await waitForHydration(page);
|
|
||||||
await page.getByLabel("Email").fill(email);
|
|
||||||
await page.getByLabel("Username").fill(username);
|
|
||||||
await page.getByRole("checkbox").check();
|
|
||||||
await page.getByRole("button", { name: /Register with Passkey/ }).click();
|
|
||||||
await expect(page).toHaveURL("/", { timeout: 10000 });
|
|
||||||
}
|
|
||||||
|
|
||||||
async function setProfileVisibility(page: Page, value: "public" | "private") {
|
async function setProfileVisibility(page: Page, value: "public" | "private") {
|
||||||
await page.goto("/settings");
|
await page.goto("/settings");
|
||||||
|
|
|
||||||
84
e2e/helpers/auth.ts
Normal file
84
e2e/helpers/auth.ts
Normal file
|
|
@ -0,0 +1,84 @@
|
||||||
|
// Shared auth helpers for journal specs. These were previously
|
||||||
|
// copy-pasted per spec file and had already drifted (the auth spec's
|
||||||
|
// registerUser lost the final URL assertion the other copies had, and
|
||||||
|
// the settings spec's variant skipped hydration and the Terms
|
||||||
|
// checkbox). One canonical copy lives here.
|
||||||
|
|
||||||
|
import { expect, waitForHydration, type CDPSession, type Page } from "../fixtures/test";
|
||||||
|
|
||||||
|
export async function setupVirtualAuthenticator(cdp: CDPSession): Promise<string> {
|
||||||
|
await cdp.send("WebAuthn.enable");
|
||||||
|
const { authenticatorId } = await cdp.send("WebAuthn.addVirtualAuthenticator", {
|
||||||
|
options: {
|
||||||
|
protocol: "ctap2",
|
||||||
|
transport: "internal",
|
||||||
|
hasResidentKey: true,
|
||||||
|
hasUserVerification: true,
|
||||||
|
isUserVerified: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return authenticatorId;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function removeVirtualAuthenticator(
|
||||||
|
cdp: CDPSession,
|
||||||
|
authenticatorId: string,
|
||||||
|
): Promise<void> {
|
||||||
|
await cdp.send("WebAuthn.removeVirtualAuthenticator", { authenticatorId });
|
||||||
|
await cdp.send("WebAuthn.disable");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fill and submit the registration form (passkey + Terms acceptance).
|
||||||
|
* Makes no assertion about the outcome — use this directly for
|
||||||
|
* expected-failure attempts (duplicate email/username), and
|
||||||
|
* registerUser for the success path.
|
||||||
|
*/
|
||||||
|
export async function submitRegistration(
|
||||||
|
page: Page,
|
||||||
|
email: string,
|
||||||
|
username: string,
|
||||||
|
): Promise<void> {
|
||||||
|
await page.goto("/auth/register");
|
||||||
|
await expect(page.getByRole("heading", { name: "Register" })).toBeVisible();
|
||||||
|
await waitForHydration(page);
|
||||||
|
await page.getByLabel("Email").click();
|
||||||
|
await page.getByLabel("Email").fill(email);
|
||||||
|
await page.getByLabel("Username").click();
|
||||||
|
await page.getByLabel("Username").fill(username);
|
||||||
|
// Verify both fields retained values before submitting
|
||||||
|
await expect(page.getByLabel("Email")).toHaveValue(email);
|
||||||
|
await expect(page.getByLabel("Username")).toHaveValue(username);
|
||||||
|
// Accept the Terms of Service (required)
|
||||||
|
await page.getByRole("checkbox").check();
|
||||||
|
await page.getByRole("button", { name: /Register with Passkey/ }).click();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Register a user with a passkey and wait for the signed-in redirect. */
|
||||||
|
export async function registerUser(page: Page, email: string, username: string): Promise<void> {
|
||||||
|
await submitRegistration(page, email, username);
|
||||||
|
await expect(page).toHaveURL("/", { timeout: 10000 });
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Register a throwaway user with unique credentials derived from `prefix`. */
|
||||||
|
export async function registerFreshUser(
|
||||||
|
page: Page,
|
||||||
|
prefix: string,
|
||||||
|
): Promise<{ email: string; username: string }> {
|
||||||
|
const email = `${prefix}-${Date.now()}@example.com`;
|
||||||
|
const username = `${prefix}${Date.now()}`;
|
||||||
|
await registerUser(page, email, username);
|
||||||
|
return { email, username };
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function logout(page: Page, accountLabel: string): Promise<void> {
|
||||||
|
// The account cluster lives inside an avatar dropdown. Click the
|
||||||
|
// avatar (its aria-label is displayName || username), then click the
|
||||||
|
// Log Out menuitem inside the popup.
|
||||||
|
await waitForHydration(page);
|
||||||
|
await page.getByRole("navigation").getByRole("button", { name: accountLabel }).click();
|
||||||
|
await page.getByRole("menuitem", { name: "Log Out" }).click();
|
||||||
|
await expect(
|
||||||
|
page.getByRole("navigation").getByRole("link", { name: "Sign In" }),
|
||||||
|
).toBeVisible({ timeout: 5000 });
|
||||||
|
}
|
||||||
39
e2e/helpers/journal.ts
Normal file
39
e2e/helpers/journal.ts
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
// 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 };
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { test, expect } from "./fixtures/test";
|
import { test, expect } from "./fixtures/test";
|
||||||
|
import { JOURNAL, PLANNER, seedRoute, routeHasGeom } from "./helpers/journal";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Integration tests that require the full dev stack:
|
* Integration tests that require the full dev stack:
|
||||||
|
|
@ -9,8 +10,6 @@ import { test, expect } from "./fixtures/test";
|
||||||
* Locally, run `pnpm dev:full` first (with E2E=true for the callback tests).
|
* Locally, run `pnpm dev:full` first (with E2E=true for the callback tests).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const JOURNAL = "http://localhost:3000";
|
|
||||||
const PLANNER = "http://localhost:3001";
|
|
||||||
|
|
||||||
const VALID_GPX = `<?xml version="1.0" encoding="UTF-8"?>
|
const VALID_GPX = `<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<gpx version="1.1" xmlns="http://www.topografix.com/GPX/1/1">
|
<gpx version="1.1" xmlns="http://www.topografix.com/GPX/1/1">
|
||||||
|
|
@ -30,9 +29,7 @@ const ONE_POINT_GPX = `<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
test.describe("Integration: Planner callback → geometry stored", () => {
|
test.describe("Integration: Planner callback → geometry stored", () => {
|
||||||
test("valid GPX stores geometry atomically", async ({ request }) => {
|
test("valid GPX stores geometry atomically", async ({ request }) => {
|
||||||
const seedResp = await request.post(`${JOURNAL}/api/e2e/seed`);
|
const { routeId, token } = await seedRoute(request);
|
||||||
expect(seedResp.ok()).toBeTruthy();
|
|
||||||
const { routeId, token } = await seedResp.json() as { routeId: string; token: string };
|
|
||||||
|
|
||||||
const callbackResp = await request.post(`${JOURNAL}/api/routes/${routeId}/callback`, {
|
const callbackResp = await request.post(`${JOURNAL}/api/routes/${routeId}/callback`, {
|
||||||
headers: { Authorization: `Bearer ${token}` },
|
headers: { Authorization: `Bearer ${token}` },
|
||||||
|
|
@ -40,14 +37,11 @@ test.describe("Integration: Planner callback → geometry stored", () => {
|
||||||
});
|
});
|
||||||
expect(callbackResp.status()).toBe(200);
|
expect(callbackResp.status()).toBe(200);
|
||||||
|
|
||||||
const geomResp = await request.get(`${JOURNAL}/api/e2e/route/${routeId}`);
|
expect(await routeHasGeom(request, routeId)).toBe(true);
|
||||||
const { hasGeom } = await geomResp.json() as { hasGeom: boolean };
|
|
||||||
expect(hasGeom).toBe(true);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("invalid GPX returns 400 and does not store geometry", async ({ request }) => {
|
test("invalid GPX returns 400 and does not store geometry", async ({ request }) => {
|
||||||
const seedResp = await request.post(`${JOURNAL}/api/e2e/seed`);
|
const { routeId, token } = await seedRoute(request);
|
||||||
const { routeId, token } = await seedResp.json() as { routeId: string; token: string };
|
|
||||||
|
|
||||||
const callbackResp = await request.post(`${JOURNAL}/api/routes/${routeId}/callback`, {
|
const callbackResp = await request.post(`${JOURNAL}/api/routes/${routeId}/callback`, {
|
||||||
headers: { Authorization: `Bearer ${token}` },
|
headers: { Authorization: `Bearer ${token}` },
|
||||||
|
|
@ -57,14 +51,11 @@ test.describe("Integration: Planner callback → geometry stored", () => {
|
||||||
const body = await callbackResp.json() as { error: string };
|
const body = await callbackResp.json() as { error: string };
|
||||||
expect(body.error).toMatch(/at least 2 track points/);
|
expect(body.error).toMatch(/at least 2 track points/);
|
||||||
|
|
||||||
const geomResp = await request.get(`${JOURNAL}/api/e2e/route/${routeId}`);
|
expect(await routeHasGeom(request, routeId)).toBe(false);
|
||||||
const { hasGeom } = await geomResp.json() as { hasGeom: boolean };
|
|
||||||
expect(hasGeom).toBe(false);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("missing token returns 401", async ({ request }) => {
|
test("missing token returns 401", async ({ request }) => {
|
||||||
const seedResp = await request.post(`${JOURNAL}/api/e2e/seed`);
|
const { routeId } = await seedRoute(request);
|
||||||
const { routeId } = await seedResp.json() as { routeId: string };
|
|
||||||
|
|
||||||
const resp = await request.post(`${JOURNAL}/api/routes/${routeId}/callback`, {
|
const resp = await request.post(`${JOURNAL}/api/routes/${routeId}/callback`, {
|
||||||
data: { gpx: VALID_GPX },
|
data: { gpx: VALID_GPX },
|
||||||
|
|
@ -73,8 +64,7 @@ test.describe("Integration: Planner callback → geometry stored", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("token is single-use — second submit is rejected (Phase B replay guard)", async ({ request }) => {
|
test("token is single-use — second submit is rejected (Phase B replay guard)", async ({ request }) => {
|
||||||
const seedResp = await request.post(`${JOURNAL}/api/e2e/seed`);
|
const { routeId, token } = await seedRoute(request);
|
||||||
const { routeId, token } = await seedResp.json() as { routeId: string; token: string };
|
|
||||||
|
|
||||||
// First save succeeds.
|
// First save succeeds.
|
||||||
const first = await request.post(`${JOURNAL}/api/routes/${routeId}/callback`, {
|
const first = await request.post(`${JOURNAL}/api/routes/${routeId}/callback`, {
|
||||||
|
|
@ -163,9 +153,7 @@ test.describe("Integration: POI metadata roundtrip", () => {
|
||||||
</trkseg></trk>
|
</trkseg></trk>
|
||||||
</gpx>`;
|
</gpx>`;
|
||||||
|
|
||||||
const seedResp = await request.post(`${JOURNAL}/api/e2e/seed`);
|
const { routeId, token } = await seedRoute(request);
|
||||||
expect(seedResp.ok()).toBeTruthy();
|
|
||||||
const { routeId, token } = await seedResp.json() as { routeId: string; token: string };
|
|
||||||
|
|
||||||
const callbackResp = await request.post(`${JOURNAL}/api/routes/${routeId}/callback`, {
|
const callbackResp = await request.post(`${JOURNAL}/api/routes/${routeId}/callback`, {
|
||||||
headers: { Authorization: `Bearer ${token}` },
|
headers: { Authorization: `Bearer ${token}` },
|
||||||
|
|
@ -182,8 +170,7 @@ test.describe("Integration: POI metadata roundtrip", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("GPX without POI extensions shows no waypoints section", async ({ page, request }) => {
|
test("GPX without POI extensions shows no waypoints section", async ({ page, request }) => {
|
||||||
const seedResp = await request.post(`${JOURNAL}/api/e2e/seed`);
|
const { routeId, token } = await seedRoute(request);
|
||||||
const { routeId, token } = await seedResp.json() as { routeId: string; token: string };
|
|
||||||
await request.post(`${JOURNAL}/api/routes/${routeId}/callback`, {
|
await request.post(`${JOURNAL}/api/routes/${routeId}/callback`, {
|
||||||
headers: { Authorization: `Bearer ${token}` },
|
headers: { Authorization: `Bearer ${token}` },
|
||||||
data: { gpx: VALID_GPX },
|
data: { gpx: VALID_GPX },
|
||||||
|
|
|
||||||
|
|
@ -17,10 +17,9 @@
|
||||||
// computes a route and the Save button has GPX to ship.
|
// computes a route and the Save button has GPX to ship.
|
||||||
|
|
||||||
import { test, expect } from "./fixtures/test";
|
import { test, expect } from "./fixtures/test";
|
||||||
|
import { JOURNAL, PLANNER, seedRoute, routeHasGeom } from "./helpers/journal";
|
||||||
import { mockBRouter } from "./fixtures/brouter-mock";
|
import { mockBRouter } from "./fixtures/brouter-mock";
|
||||||
|
|
||||||
const JOURNAL = "http://localhost:3000";
|
|
||||||
const PLANNER = "http://localhost:3001";
|
|
||||||
|
|
||||||
// Mock BRouter so the in-browser route compute is deterministic and
|
// Mock BRouter so the in-browser route compute is deterministic and
|
||||||
// fast — same approach as `planner-coloring.test.ts`. Without this the
|
// fast — same approach as `planner-coloring.test.ts`. Without this the
|
||||||
|
|
@ -35,9 +34,7 @@ const WAYPOINTS = encodeURIComponent(JSON.stringify([
|
||||||
]));
|
]));
|
||||||
|
|
||||||
async function seedRouteAndPlannerSession(request: import("@playwright/test").APIRequestContext) {
|
async function seedRouteAndPlannerSession(request: import("@playwright/test").APIRequestContext) {
|
||||||
const seedResp = await request.post(`${JOURNAL}/api/e2e/seed`);
|
const { routeId, token } = await seedRoute(request);
|
||||||
expect(seedResp.ok()).toBeTruthy();
|
|
||||||
const { routeId, token } = (await seedResp.json()) as { routeId: string; token: string };
|
|
||||||
|
|
||||||
// Create a planner session with the journal callback wired up — no
|
// Create a planner session with the journal callback wired up — no
|
||||||
// GPX seeded into the session itself. We pass waypoints via URL
|
// GPX seeded into the session itself. We pass waypoints via URL
|
||||||
|
|
@ -85,9 +82,7 @@ test.describe("Journal ↔ Planner save handoff (Phase A + B)", () => {
|
||||||
expect(observed.some((s) => s.includes(token))).toBe(false);
|
expect(observed.some((s) => s.includes(token))).toBe(false);
|
||||||
|
|
||||||
// Sanity: the journal's route now has geometry.
|
// Sanity: the journal's route now has geometry.
|
||||||
const geomResp = await request.get(`${JOURNAL}/api/e2e/route/${routeId}`);
|
expect(await routeHasGeom(request, routeId)).toBe(true);
|
||||||
const { hasGeom } = (await geomResp.json()) as { hasGeom: boolean };
|
|
||||||
expect(hasGeom).toBe(true);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("token is single-use — second save through the planner UI fails", async ({ page, request }) => {
|
test("token is single-use — second save through the planner UI fails", async ({ page, request }) => {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import { test, expect } from "./fixtures/test";
|
import { test, expect } from "./fixtures/test";
|
||||||
|
import { JOURNAL, seedKomootConnection, seedRoute } from "./helpers/journal";
|
||||||
|
|
||||||
// Fixed test data — the e2e seed endpoint creates a stable user + Komoot connection
|
// Fixed test data — the e2e seed endpoint creates a stable user + Komoot connection
|
||||||
const KOMOOT_USER_ID = "99999999999";
|
const KOMOOT_USER_ID = "99999999999";
|
||||||
const JOURNAL = "http://localhost:3000";
|
|
||||||
|
|
||||||
const SAMPLE_GPX = `<?xml version="1.0" encoding="UTF-8"?>
|
const SAMPLE_GPX = `<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<gpx version="1.1" creator="komoot" xmlns="http://www.topografix.com/GPX/1/1">
|
<gpx version="1.1" creator="komoot" xmlns="http://www.topografix.com/GPX/1/1">
|
||||||
|
|
@ -34,19 +34,6 @@ const MOCK_TOURS_RESPONSE = {
|
||||||
page: { totalPages: 1, number: 0 },
|
page: { totalPages: 1, number: 0 },
|
||||||
};
|
};
|
||||||
|
|
||||||
// Seeds a Komoot connection for the e2e test user and returns a session cookie.
|
|
||||||
async function seedKomootConnection(
|
|
||||||
request: import("@playwright/test").APIRequestContext,
|
|
||||||
mode: "public" | "authenticated" = "public",
|
|
||||||
) {
|
|
||||||
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 };
|
|
||||||
}
|
|
||||||
|
|
||||||
test.describe("Komoot connection page", () => {
|
test.describe("Komoot connection page", () => {
|
||||||
test("unauthenticated user is redirected to login", async ({ page }) => {
|
test("unauthenticated user is redirected to login", async ({ page }) => {
|
||||||
await page.goto("/settings/connections/komoot");
|
await page.goto("/settings/connections/komoot");
|
||||||
|
|
@ -105,10 +92,8 @@ test.describe("Komoot import page", () => {
|
||||||
test.setTimeout(60000);
|
test.setTimeout(60000);
|
||||||
|
|
||||||
test("redirects to connect page when not connected", async ({ page, request }) => {
|
test("redirects to connect page when not connected", async ({ page, request }) => {
|
||||||
// Seed user without Komoot connection (use seed endpoint to just get a session)
|
|
||||||
const seedResp = await request.post(`${JOURNAL}/api/e2e/seed`);
|
|
||||||
const data = await seedResp.json() as { routeId: string; token: string };
|
|
||||||
// We only need the session — navigate to import page unauthenticated redirects to login
|
// We only need the session — navigate to import page unauthenticated redirects to login
|
||||||
|
await seedRoute(request);
|
||||||
await page.goto("/sync/import/komoot");
|
await page.goto("/sync/import/komoot");
|
||||||
await expect(page).toHaveURL(/\/auth\/login|\/settings\/connections\/komoot/, { timeout: 5000 });
|
await expect(page).toHaveURL(/\/auth\/login|\/settings\/connections\/komoot/, { timeout: 5000 });
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,5 @@
|
||||||
import { test, expect, waitForHydration, type CDPSession, type Page } from "./fixtures/test";
|
import { test, expect, waitForHydration, type CDPSession, type Page } from "./fixtures/test";
|
||||||
|
import { setupVirtualAuthenticator, registerUser } from "./helpers/auth";
|
||||||
async function setupVirtualAuthenticator(cdp: CDPSession) {
|
|
||||||
await cdp.send("WebAuthn.enable");
|
|
||||||
const { authenticatorId } = await cdp.send("WebAuthn.addVirtualAuthenticator", {
|
|
||||||
options: {
|
|
||||||
protocol: "ctap2",
|
|
||||||
transport: "internal",
|
|
||||||
hasResidentKey: true,
|
|
||||||
hasUserVerification: true,
|
|
||||||
isUserVerified: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
return authenticatorId;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function registerUser(page: Page, email: string, username: string) {
|
|
||||||
await page.goto("/auth/register");
|
|
||||||
await expect(page.getByRole("heading", { name: "Register" })).toBeVisible();
|
|
||||||
await waitForHydration(page);
|
|
||||||
await page.getByLabel("Email").fill(email);
|
|
||||||
await page.getByLabel("Username").fill(username);
|
|
||||||
await page.getByRole("checkbox").check();
|
|
||||||
await page.getByRole("button", { name: /Register with Passkey/ }).click();
|
|
||||||
await expect(page).toHaveURL("/", { timeout: 10000 });
|
|
||||||
}
|
|
||||||
|
|
||||||
async function setProfileVisibility(page: Page, value: "public" | "private") {
|
async function setProfileVisibility(page: Page, value: "public" | "private") {
|
||||||
await page.goto("/settings");
|
await page.goto("/settings");
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,5 @@
|
||||||
import { test, expect, waitForHydration, type CDPSession, type Page } from "./fixtures/test";
|
import { test, expect, waitForHydration, type CDPSession, type Page } from "./fixtures/test";
|
||||||
|
import { setupVirtualAuthenticator, registerUser } from "./helpers/auth";
|
||||||
// Reuses the virtual-authenticator + register helpers from auth.test.ts.
|
|
||||||
// Inlined rather than factored out to keep this file independently runnable.
|
|
||||||
async function setupVirtualAuthenticator(cdp: CDPSession) {
|
|
||||||
await cdp.send("WebAuthn.enable");
|
|
||||||
const { authenticatorId } = await cdp.send("WebAuthn.addVirtualAuthenticator", {
|
|
||||||
options: {
|
|
||||||
protocol: "ctap2",
|
|
||||||
transport: "internal",
|
|
||||||
hasResidentKey: true,
|
|
||||||
hasUserVerification: true,
|
|
||||||
isUserVerified: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
return authenticatorId;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function registerUser(page: Page, email: string, username: string) {
|
|
||||||
await page.goto("/auth/register");
|
|
||||||
await expect(page.getByRole("heading", { name: "Register" })).toBeVisible();
|
|
||||||
await waitForHydration(page);
|
|
||||||
await page.getByLabel("Email").fill(email);
|
|
||||||
await page.getByLabel("Username").fill(username);
|
|
||||||
await page.getByRole("checkbox").check();
|
|
||||||
await page.getByRole("button", { name: /Register with Passkey/ }).click();
|
|
||||||
await expect(page).toHaveURL("/", { timeout: 10000 });
|
|
||||||
}
|
|
||||||
|
|
||||||
async function createRoute(page: Page, name: string): Promise<string> {
|
async function createRoute(page: Page, name: string): Promise<string> {
|
||||||
await page.goto("/routes/new");
|
await page.goto("/routes/new");
|
||||||
|
|
|
||||||
|
|
@ -1,36 +1,5 @@
|
||||||
import { test, expect, type CDPSession, type Page } from "./fixtures/test";
|
import { test, expect, type CDPSession, type Page } from "./fixtures/test";
|
||||||
|
import { setupVirtualAuthenticator, removeVirtualAuthenticator, registerFreshUser } from "./helpers/auth";
|
||||||
async function setupVirtualAuthenticator(cdp: CDPSession) {
|
|
||||||
await cdp.send("WebAuthn.enable");
|
|
||||||
const { authenticatorId } = await cdp.send("WebAuthn.addVirtualAuthenticator", {
|
|
||||||
options: {
|
|
||||||
protocol: "ctap2",
|
|
||||||
transport: "internal",
|
|
||||||
hasResidentKey: true,
|
|
||||||
hasUserVerification: true,
|
|
||||||
isUserVerified: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
return authenticatorId;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function removeVirtualAuthenticator(cdp: CDPSession, authenticatorId: string) {
|
|
||||||
await cdp.send("WebAuthn.removeVirtualAuthenticator", { authenticatorId });
|
|
||||||
await cdp.send("WebAuthn.disable");
|
|
||||||
}
|
|
||||||
|
|
||||||
async function registerAndLogin(page: Page, cdp: CDPSession) {
|
|
||||||
const email = `settings-${Date.now()}@example.com`;
|
|
||||||
const username = `settingsuser${Date.now()}`;
|
|
||||||
|
|
||||||
await page.goto("/auth/register");
|
|
||||||
await page.getByLabel("Email").fill(email);
|
|
||||||
await page.getByLabel("Username").fill(username);
|
|
||||||
await page.getByRole("button", { name: /Register with Passkey/ }).click();
|
|
||||||
await expect(page).toHaveURL("/", { timeout: 10000 });
|
|
||||||
|
|
||||||
return { email, username };
|
|
||||||
}
|
|
||||||
|
|
||||||
test.describe("Account Settings", () => {
|
test.describe("Account Settings", () => {
|
||||||
test("unauthenticated user is redirected to login", async ({ page }) => {
|
test("unauthenticated user is redirected to login", async ({ page }) => {
|
||||||
|
|
@ -41,7 +10,7 @@ test.describe("Account Settings", () => {
|
||||||
test("settings page loads for authenticated user", async ({ page }) => {
|
test("settings page loads for authenticated user", async ({ page }) => {
|
||||||
const cdp = await page.context().newCDPSession(page);
|
const cdp = await page.context().newCDPSession(page);
|
||||||
const authenticatorId = await setupVirtualAuthenticator(cdp);
|
const authenticatorId = await setupVirtualAuthenticator(cdp);
|
||||||
await registerAndLogin(page, cdp);
|
await registerFreshUser(page, "settings");
|
||||||
|
|
||||||
await page.goto("/settings");
|
await page.goto("/settings");
|
||||||
await expect(page.getByRole("heading", { name: "Settings" })).toBeVisible();
|
await expect(page.getByRole("heading", { name: "Settings" })).toBeVisible();
|
||||||
|
|
@ -55,7 +24,7 @@ test.describe("Account Settings", () => {
|
||||||
test("update display name and bio", async ({ page }) => {
|
test("update display name and bio", async ({ page }) => {
|
||||||
const cdp = await page.context().newCDPSession(page);
|
const cdp = await page.context().newCDPSession(page);
|
||||||
const authenticatorId = await setupVirtualAuthenticator(cdp);
|
const authenticatorId = await setupVirtualAuthenticator(cdp);
|
||||||
const { username } = await registerAndLogin(page, cdp);
|
const { username } = await registerFreshUser(page, "settings");
|
||||||
|
|
||||||
await page.goto("/settings");
|
await page.goto("/settings");
|
||||||
|
|
||||||
|
|
@ -79,7 +48,7 @@ test.describe("Account Settings", () => {
|
||||||
test("passkey list shows registered passkey", async ({ page }) => {
|
test("passkey list shows registered passkey", async ({ page }) => {
|
||||||
const cdp = await page.context().newCDPSession(page);
|
const cdp = await page.context().newCDPSession(page);
|
||||||
const authenticatorId = await setupVirtualAuthenticator(cdp);
|
const authenticatorId = await setupVirtualAuthenticator(cdp);
|
||||||
await registerAndLogin(page, cdp);
|
await registerFreshUser(page, "settings");
|
||||||
|
|
||||||
await page.goto("/settings");
|
await page.goto("/settings");
|
||||||
// Should show the passkey registered during registration
|
// Should show the passkey registered during registration
|
||||||
|
|
@ -92,7 +61,7 @@ test.describe("Account Settings", () => {
|
||||||
test("add and delete passkey from settings", async ({ page }) => {
|
test("add and delete passkey from settings", async ({ page }) => {
|
||||||
const cdp = await page.context().newCDPSession(page);
|
const cdp = await page.context().newCDPSession(page);
|
||||||
const authenticatorId = await setupVirtualAuthenticator(cdp);
|
const authenticatorId = await setupVirtualAuthenticator(cdp);
|
||||||
await registerAndLogin(page, cdp);
|
await registerFreshUser(page, "settings");
|
||||||
|
|
||||||
await page.goto("/settings");
|
await page.goto("/settings");
|
||||||
|
|
||||||
|
|
@ -119,7 +88,7 @@ test.describe("Account Settings", () => {
|
||||||
test("delete last passkey shows warning", async ({ page }) => {
|
test("delete last passkey shows warning", async ({ page }) => {
|
||||||
const cdp = await page.context().newCDPSession(page);
|
const cdp = await page.context().newCDPSession(page);
|
||||||
const authenticatorId = await setupVirtualAuthenticator(cdp);
|
const authenticatorId = await setupVirtualAuthenticator(cdp);
|
||||||
await registerAndLogin(page, cdp);
|
await registerFreshUser(page, "settings");
|
||||||
|
|
||||||
await page.goto("/settings");
|
await page.goto("/settings");
|
||||||
|
|
||||||
|
|
@ -142,7 +111,7 @@ test.describe("Account Settings", () => {
|
||||||
test("settings link reachable from nav when logged in", async ({ page }) => {
|
test("settings link reachable from nav when logged in", async ({ page }) => {
|
||||||
const cdp = await page.context().newCDPSession(page);
|
const cdp = await page.context().newCDPSession(page);
|
||||||
const authenticatorId = await setupVirtualAuthenticator(cdp);
|
const authenticatorId = await setupVirtualAuthenticator(cdp);
|
||||||
const { username } = await registerAndLogin(page, cdp);
|
const { username } = await registerFreshUser(page, "settings");
|
||||||
|
|
||||||
// Settings now lives inside the avatar dropdown; opening the
|
// Settings now lives inside the avatar dropdown; opening the
|
||||||
// dropdown reveals the menuitem.
|
// dropdown reveals the menuitem.
|
||||||
|
|
@ -161,7 +130,7 @@ test.describe("Account Settings", () => {
|
||||||
test("account deletion requires correct username", async ({ page }) => {
|
test("account deletion requires correct username", async ({ page }) => {
|
||||||
const cdp = await page.context().newCDPSession(page);
|
const cdp = await page.context().newCDPSession(page);
|
||||||
const authenticatorId = await setupVirtualAuthenticator(cdp);
|
const authenticatorId = await setupVirtualAuthenticator(cdp);
|
||||||
const { username } = await registerAndLogin(page, cdp);
|
const { username } = await registerFreshUser(page, "settings");
|
||||||
|
|
||||||
await page.goto("/settings");
|
await page.goto("/settings");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,5 @@
|
||||||
import { test, expect, waitForHydration, type CDPSession, type Page } from "./fixtures/test";
|
import { test, expect, waitForHydration, type CDPSession, type Page } from "./fixtures/test";
|
||||||
|
import { setupVirtualAuthenticator, registerUser } from "./helpers/auth";
|
||||||
// Inline virtual-authenticator + register helpers, mirroring the pattern
|
|
||||||
// in auth.test.ts / public-content.test.ts so this file runs standalone.
|
|
||||||
async function setupVirtualAuthenticator(cdp: CDPSession) {
|
|
||||||
await cdp.send("WebAuthn.enable");
|
|
||||||
const { authenticatorId } = await cdp.send("WebAuthn.addVirtualAuthenticator", {
|
|
||||||
options: {
|
|
||||||
protocol: "ctap2",
|
|
||||||
transport: "internal",
|
|
||||||
hasResidentKey: true,
|
|
||||||
hasUserVerification: true,
|
|
||||||
isUserVerified: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
return authenticatorId;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function registerUser(page: Page, email: string, username: string) {
|
|
||||||
await page.goto("/auth/register");
|
|
||||||
await expect(page.getByRole("heading", { name: "Register" })).toBeVisible();
|
|
||||||
await waitForHydration(page);
|
|
||||||
await page.getByLabel("Email").fill(email);
|
|
||||||
await page.getByLabel("Username").fill(username);
|
|
||||||
await page.getByRole("checkbox").check();
|
|
||||||
await page.getByRole("button", { name: /Register with Passkey/ }).click();
|
|
||||||
await expect(page).toHaveURL("/", { timeout: 10000 });
|
|
||||||
}
|
|
||||||
|
|
||||||
async function setProfileVisibility(page: Page, value: "public" | "private") {
|
async function setProfileVisibility(page: Page, value: "public" | "private") {
|
||||||
await page.goto("/settings");
|
await page.goto("/settings");
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,9 @@ export default defineConfig({
|
||||||
trace: "on-first-retry",
|
trace: "on-first-retry",
|
||||||
screenshot: "only-on-failure",
|
screenshot: "only-on-failure",
|
||||||
},
|
},
|
||||||
|
// NOTE: specs only run if a project below matches them — a new
|
||||||
|
// e2e/*.test.ts file MUST be registered here or it silently never
|
||||||
|
// executes (settings/explore/social sat unregistered for months).
|
||||||
projects: [
|
projects: [
|
||||||
{
|
{
|
||||||
name: "journal",
|
name: "journal",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue