| 32 | let server: http.Server | undefined; |
| 33 | |
| 34 | async function api<T>( |
| 35 | method: string, |
| 36 | pathname: string, |
| 37 | options: { body?: unknown; actor?: string } = {}, |
| 38 | ): Promise<{ status: number; body: ApiResponse<T> }> { |
| 39 | const headers: Record<string, string> = { 'Content-Type': 'application/json' }; |
| 40 | if (options.actor) { |
| 41 | headers['X-Actor'] = options.actor; |
| 42 | } |
| 43 | const response = await fetch(`${baseUrl}${pathname}`, { |
| 44 | method, |
| 45 | headers, |
| 46 | body: options.body ? JSON.stringify(options.body) : undefined, |
| 47 | }); |
| 48 | return { status: response.status, body: (await response.json()) as ApiResponse<T> }; |
| 49 | } |
| 50 | |
| 51 | beforeEach(async () => { |
| 52 | contentRoot = await mkdtemp(path.join(os.tmpdir(), 'patch-file-root-')); |