Files
pleno-vue/tests/e2e/subuserCompleteRegistration.spec.ts
Jeppe Bundgaard 983585ede7 Refactor and cleanup:
- Migrate postinstall script to `postinstall-sync-playwright-root-links.mjs` for streamlined path resolution.
- Replace `axios` v1.15.0 with v1.13.5 and downgrade `vite` from v8.0.5 to v7.1.11.
- Update testing code for consistent formatting and enhanced readability (e.g., `poll` and `catch` calls).
- Remove unused or redundant dependency flags and align `package-lock.json` with new configuration.
2026-04-14 14:17:28 +02:00

80 lines
2.4 KiB
TypeScript

import { expect, test } from "@playwright/test";
import { mockApi } from "./support/network.js";
function json(route, body, status = 200) {
return route.fulfill({
status,
contentType: "application/json",
body: JSON.stringify(body),
});
}
test("loads the complete-registration page and completes subuser setup from the token link", async ({ page }) => {
await mockApi(page, { authenticated: false });
let submittedPayload = null;
await page.route("**/subusers/setup*", async (route) => {
const request = route.request();
const url = new URL(request.url());
if (request.method() === "GET") {
await json(route, {
data: {
message: "Token is valid",
subuser_id: 91,
},
});
return;
}
submittedPayload = request.postDataJSON();
await json(route, {
data: {
message: "Complete registration successful",
},
});
});
await page.goto("/complete-registration?token=valid-setup-token");
await expect(page.locator("#complete-registration-form")).toBeVisible();
await page.fill("#complete-registration-name", "Driver Demo");
await page.fill("#complete-registration-username", "driver.demo");
await page.fill("#complete-registration-email", "driver@example.com");
await page.fill("#complete-registration-password", "ValidPass123");
await page.fill("#complete-registration-confirm-password", "ValidPass123");
await page.click("#complete-registration-submit");
await expect(page.locator("#complete_registration_alert_success")).toHaveText("Complete registration successful");
await expect(page.locator('a[href="/login/driver"]')).toBeVisible();
expect(submittedPayload).toMatchObject({
token: "valid-setup-token",
name: "Driver Demo",
username: "driver.demo",
email: "driver@example.com",
password: "ValidPass123",
});
});
test("shows an inline error when the complete-registration token is invalid", async ({ page }) => {
await mockApi(page, { authenticated: false });
await page.route("**/subusers/setup*", async (route) => {
await json(
route,
{
data: {
message: "Invalid or expired token",
},
},
400
);
});
await page.goto("/complete-registration?token=invalid-setup-token");
await expect(page.locator("#complete_registration_alert_error")).toHaveText("Invalid or expired token");
await expect(page.locator("#complete-registration-invalid")).toBeVisible();
});