import { request } from '@playwright/test' import { baseURL } from '../playwright.config' import { PASSWORD, users } from './fixtures' /** Creates the workspace, a site and one user per role in the fresh server. */ export default async function globalSetup() { const api = await request.newContext({ baseURL }) // oxlint-disable-next-line typescript/no-explicit-any -- loosely typed setup calls const ok = async (res: Awaited>): Promise => { if (!res.ok()) throw new Error(`${res.url()} → ${res.status()} ${await res.text()}`) return res.json() } await ok(await api.post('/api/setup', { data: { organizationName: 'E2E Plant', ...users.admin, password: PASSWORD } })) const { site } = await ok(await api.post('/api/sites', { data: { name: 'Main Plant' } })) const { area } = await ok(await api.post(`/api/sites/${site.id}/areas`, { data: { name: 'Press Shop', kind: 'building' } })) const { kiosk } = await ok(await api.post('/api/kiosks', { data: { name: 'Canteen tablet' }, headers: { origin: baseURL } })) // Shared with the test workers process.env.E2E_KIOSK_TOKEN = kiosk.token process.env.E2E_SITE_ID = site.id process.env.E2E_AREA_ID = area.id for (const role of ['supervisor', 'reporter'] as const) { await ok(await api.post('/api/users', { data: { ...users[role], role, password: PASSWORD } })) } await api.dispose() }