push to maple-street
This commit is contained in:
+34
-1
@@ -1,6 +1,7 @@
|
||||
import { expect, type Page } from "@playwright/test";
|
||||
|
||||
const BASE = "http://localhost:3000";
|
||||
const E2E_PASSWORD = "e2e-password-123";
|
||||
|
||||
/**
|
||||
* Shared E2E helpers. Both test files run against the same Postgres, so they
|
||||
@@ -20,7 +21,19 @@ export async function signInAs(page: Page, email: string) {
|
||||
const body = (await res.json()) as { url?: string };
|
||||
expect(body.url, "magic-link should return a sign-in url").toBeTruthy();
|
||||
await page.goto(body.url!);
|
||||
await expect(page).toHaveURL(/complete/);
|
||||
// New accounts are prompted to choose credentials after their first magic
|
||||
// link. Set the deterministic test password, then continue into the shell.
|
||||
if (new URL(page.url()).pathname === "/welcome") {
|
||||
await expect(
|
||||
page.getByRole("heading", { name: "Set your login" }),
|
||||
).toBeVisible();
|
||||
await page.getByLabel("Username").fill(email);
|
||||
await page.getByLabel("Password", { exact: true }).fill(E2E_PASSWORD);
|
||||
await page.getByLabel("Confirm password").fill(E2E_PASSWORD);
|
||||
await page.getByRole("button", { name: "Save and continue" }).click();
|
||||
}
|
||||
// The completion route redirects into the shell, which requires a session.
|
||||
await expect(page).toHaveURL(`${BASE}/schedule`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -36,6 +49,26 @@ export async function resetDb(page: Page) {
|
||||
return res.status;
|
||||
});
|
||||
expect(status, "admin reset should succeed").toBe(200);
|
||||
// The reset recreates every user with a new id, so the session obtained
|
||||
// before the reset now points at a deleted row. Re-authenticate so helper
|
||||
// routes called in the same context see a live account (the guard returns 401
|
||||
// for stale ids).
|
||||
await signInAs(page, "admin@glenloch.local");
|
||||
}
|
||||
|
||||
/**
|
||||
* The first service instance's id, read from the instances helper route. Needs
|
||||
* a `schedule.publish` session (coordinator or admin).
|
||||
*/
|
||||
export async function firstInstanceId(page: Page): Promise<string> {
|
||||
const res = await page.request.get(`${BASE}/api/dev/schedule/instances`);
|
||||
expect(res.ok(), "instances route should succeed").toBe(true);
|
||||
const body = (await res.json()) as { instances: { id: string }[] };
|
||||
expect(
|
||||
body.instances.length,
|
||||
"at least one instance should exist",
|
||||
).toBeGreaterThan(0);
|
||||
return body.instances[0].id;
|
||||
}
|
||||
|
||||
export { BASE };
|
||||
|
||||
Reference in New Issue
Block a user