Add Playwright test migration plan

This commit is contained in:
Jeppe Bundgaard
2026-03-09 10:20:39 +01:00
parent 721e942a12
commit 2f23b6ea75
608 changed files with 108055 additions and 14685 deletions
+95
View File
@@ -0,0 +1,95 @@
const API_HOST = "**://api.truckwash.io/**";
function json(body, status = 200) {
return {
status,
contentType: "application/json",
body: JSON.stringify(body)
};
}
export async function mockApi(page, options = {}) {
await page.route(API_HOST, async (route) => {
const request = route.request();
const url = request.url();
const method = request.method();
if (url.includes("/auth/recaptcha/pre-check") && method === "GET") {
await route.fulfill(
json({
data: {
recaptcha: {
enabled: false,
site_key: ""
},
rate_limit: {
enabled: false,
limit: 0,
remaining: 0,
reset: 0,
warning: null
}
}
})
);
return;
}
if (url.includes("/auth/login") && method === "POST") {
await route.fulfill(
json({
data: {
token: options.loginToken || "e2e-token"
}
})
);
return;
}
if (url.includes("/auth/session") && method === "GET") {
if (!options.authenticated) {
await route.fulfill(json({ message: "Unauthenticated" }, 401));
return;
}
await route.fulfill(
json({
data: {
id: 1,
customer_number: 12345,
group_id: 1,
email: "e2e@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: "E2E User",
permissions: ["user"],
economic_customer: []
}
})
);
return;
}
if (options.fallbackPassthrough) {
await route.fallback();
return;
}
await route.fulfill(json({ data: [] }));
});
}
export async function seedAuthenticatedState(page, token = "e2e-token") {
await page.addInitScript((value) => {
window.localStorage.setItem("token", value);
}, token);
}