88 lines
2.6 KiB
TypeScript
88 lines
2.6 KiB
TypeScript
import { test, expect } from "@playwright/test";
|
|
import { mockApi, seedAuthenticatedState } from "./support/network.js";
|
|
import { isDesktopProject } from "./support/projects";
|
|
|
|
const AUTH_SESSION_URL = /\/auth\/session(?:\?.*)?$/;
|
|
|
|
function json(body: unknown, status = 200) {
|
|
return {
|
|
status,
|
|
contentType: "application/json",
|
|
headers: {
|
|
"access-control-allow-origin": "*",
|
|
},
|
|
body: JSON.stringify(body),
|
|
};
|
|
}
|
|
|
|
function deferred() {
|
|
let resolve!: () => void;
|
|
const promise = new Promise<void>((res) => {
|
|
resolve = res;
|
|
});
|
|
|
|
return { promise, resolve };
|
|
}
|
|
|
|
test.describe("session bootstrap", () => {
|
|
test("does not flash forbidden or unnamed UI while auth session is delayed", async ({ page }, testInfo) => {
|
|
test.skip(!isDesktopProject(testInfo), "Superuser shell bootstrap name assertions are desktop-focused.");
|
|
const releaseSession = deferred();
|
|
let sessionRequested = false;
|
|
const permissions = ["user", "admin", "superuser"];
|
|
const sessionData = {
|
|
id: 1,
|
|
customer_number: 12345,
|
|
group_id: 1,
|
|
email: "bootstrap@example.com",
|
|
phone: {
|
|
number: "12345678",
|
|
country_code: 45,
|
|
},
|
|
notifications: {
|
|
wash_certificate_email: null,
|
|
email_notifications_enabled: true,
|
|
sms_notifications_enabled: false,
|
|
},
|
|
created_at: "2026-01-01T00:00:00.000Z",
|
|
updated_at: "2026-01-01T00:00:00.000Z",
|
|
display_name: "Bootstrap User",
|
|
permissions,
|
|
economic_customer: [],
|
|
runtime_config: {
|
|
economic: {
|
|
transaction_draft_customer_number: null,
|
|
default_distribution_department_id: null,
|
|
},
|
|
release: {},
|
|
},
|
|
};
|
|
|
|
await mockApi(page, {
|
|
authenticated: true,
|
|
permissions,
|
|
sessionData,
|
|
});
|
|
await page.route(AUTH_SESSION_URL, async (route) => {
|
|
sessionRequested = true;
|
|
await releaseSession.promise;
|
|
await route.fulfill(json({ data: sessionData }));
|
|
});
|
|
await seedAuthenticatedState(page, "delayed-session-token");
|
|
|
|
await page.goto("/superuser", { waitUntil: "domcontentloaded" });
|
|
await expect.poll(() => sessionRequested).toBe(true);
|
|
await page.waitForTimeout(500);
|
|
|
|
await expect(page.getByText("403 Forbidden")).toHaveCount(0);
|
|
await expect(page.getByText("Unnamed")).toHaveCount(0);
|
|
|
|
releaseSession.resolve();
|
|
|
|
await expect(page.getByText("Bootstrap User")).toBeVisible({ timeout: 15_000 });
|
|
await expect(page.getByText(/System Status|Systemstatus/)).toBeVisible();
|
|
await expect(page.getByText("403 Forbidden")).toHaveCount(0);
|
|
await expect(page.getByText("Unnamed")).toHaveCount(0);
|
|
});
|
|
});
|