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' } })) await ok(await api.post(`/api/sites/${site.id}/areas`, { data: { name: 'Press Shop', kind: 'building' } })) for (const role of ['supervisor', 'reporter'] as const) { await ok(await api.post('/api/users', { data: { ...users[role], role, password: PASSWORD } })) } await api.dispose() }