| 4 | endpoint[0] === '/' ? endpoint : '/' + endpoint; |
| 5 | |
| 6 | export const authedRequest = async ({ |
| 7 | request, |
| 8 | method, |
| 9 | endpoint, |
| 10 | data |
| 11 | }: { |
| 12 | request: APIRequestContext; |
| 13 | method: 'post' | 'put'; |
| 14 | endpoint: string; |
| 15 | data: Record<string, unknown>; |
| 16 | }) => { |
| 17 | const csrfToken = (await request.storageState()).cookies.find( |
| 18 | c => c.name === 'csrf_token' |
| 19 | )?.value; |
| 20 | |
| 21 | expect(csrfToken).toBeTruthy(); |
| 22 | |
| 23 | const res = await request[method]( |
| 24 | process.env.API_LOCATION + ensureLeadingSlash(endpoint), |
| 25 | { |
| 26 | data, |
| 27 | headers: { 'csrf-token': csrfToken! } |
| 28 | } |
| 29 | ); |
| 30 | expect(res.status()).toBe(200); |
| 31 | return res; |
| 32 | }; |