test setup

This commit is contained in:
2026-01-04 00:39:17 +01:00
parent 5308d3ee61
commit 99092e2759
10 changed files with 638 additions and 106 deletions

View File

@@ -32,13 +32,17 @@ export class WebsiteAuthManager {
if (request) {
const token = await WebsiteAuthManager.loginViaApi(request, apiBaseUrl, role);
// Critical: the website (localhost:3000) must receive `gp_session` so middleware can forward it.
// Playwright cookie format - either url OR domain+path
// Critical: the website must receive `gp_session` so middleware can forward it.
// Playwright runs in its own container and accesses website via PLAYWRIGHT_BASE_URL
// The cookie domain must match the hostname in the URL that Playwright uses
const url = new URL(baseURL);
const domain = url.hostname; // "website" in Docker, "localhost" locally
await context.addCookies([
{
name: 'gp_session',
value: token,
domain: 'localhost',
domain: domain,
path: '/',
httpOnly: true,
sameSite: 'Lax',
@@ -66,6 +70,8 @@ export class WebsiteAuthManager {
): Promise<string> {
const credentials = WebsiteAuthManager.getCredentials(role);
// In Docker, the API is at http://api:3000, but the website needs to receive cookies
// that will be forwarded to the API. The cookie domain should match the website.
const res = await request.post(`${apiBaseUrl}/auth/login`, {
data: {
email: credentials.email,

View File

@@ -1,4 +1,5 @@
import { routes, routeMatchers } from '../../../apps/website/lib/routing/RouteConfig';
import { stableUuidFromSeedKey } from '../../../adapters/bootstrap/racing/SeedIdHelper';
export type RouteAccess = 'public' | 'auth' | 'admin' | 'sponsor';
export type RouteParams = Record<string, string>;
@@ -12,12 +13,13 @@ export interface WebsiteRouteDefinition {
}
export class WebsiteRouteManager {
// Generate IDs the same way the seed does for postgres compatibility
private static readonly IDs = {
LEAGUE: 'league-1',
DRIVER: 'driver-1',
TEAM: 'team-1',
RACE: 'race-1',
PROTEST: 'protest-1',
LEAGUE: stableUuidFromSeedKey('league-1'),
DRIVER: stableUuidFromSeedKey('driver-1'),
TEAM: stableUuidFromSeedKey('team-1'),
RACE: stableUuidFromSeedKey('race-1'),
PROTEST: stableUuidFromSeedKey('protest-1'),
} as const;
public resolvePathTemplate(pathTemplate: string, params: RouteParams = {}): string {
@@ -68,9 +70,11 @@ export class WebsiteRouteManager {
}
public getParamEdgeCases(): WebsiteRouteDefinition[] {
// Use non-existent UUIDs that will trigger 404 responses
const nonExistentId = '00000000-0000-0000-0000-000000000000';
return [
{ pathTemplate: '/races/[id]', params: { id: 'does-not-exist' }, access: 'public', allowNotFound: true },
{ pathTemplate: '/leagues/[id]', params: { id: 'does-not-exist' }, access: 'public', allowNotFound: true },
{ pathTemplate: '/races/[id]', params: { id: nonExistentId }, access: 'public', allowNotFound: true },
{ pathTemplate: '/leagues/[id]', params: { id: nonExistentId }, access: 'public', allowNotFound: true },
];
}