arbret/frontend/e2e/helpers/auth.ts

43 lines
1.2 KiB
TypeScript
Raw Normal View History

import { Page } from "@playwright/test";
/**
* Auth helpers for e2e tests.
*/
2025-12-26 19:21:34 +01:00
import { getBackendUrl } from "./backend-url";
2025-12-26 19:21:34 +01:00
// Use dynamic backend URL based on worker index
// Note: API_URL is evaluated at module load time, so it may use default value
// For dynamic per-test URLs, use getBackendUrl() directly
export const getApiUrl = () => getBackendUrl();
export function getRequiredEnv(name: string): string {
const value = process.env[name];
if (!value) {
throw new Error(`Required environment variable ${name} is not set.`);
}
return value;
}
export const REGULAR_USER = {
email: getRequiredEnv("DEV_USER_EMAIL"),
password: getRequiredEnv("DEV_USER_PASSWORD"),
};
export const ADMIN_USER = {
email: getRequiredEnv("DEV_ADMIN_EMAIL"),
password: getRequiredEnv("DEV_ADMIN_PASSWORD"),
};
export async function clearAuth(page: Page) {
await page.context().clearCookies();
}
export async function loginUser(page: Page, email: string, password: string) {
await page.goto("/login");
await page.fill('input[type="email"]', email);
await page.fill('input[type="password"]', password);
await page.click('button[type="submit"]');
await page.waitForURL((url) => !url.pathname.includes("/login"), { timeout: 10000 });
}