(method)
| 22 | }) |
| 23 | |
| 24 | function sendRequest(method) { |
| 25 | const body = !['get', 'head'].includes(method.toLowerCase()) |
| 26 | ? JSON.stringify({ |
| 27 | key: 'value', |
| 28 | }) |
| 29 | : undefined |
| 30 | it(`should proxy ${method} request ${ |
| 31 | body ? 'with body' : '' |
| 32 | }`, async () => { |
| 33 | const headers = { |
| 34 | 'content-type': 'application/json', |
| 35 | 'x-custom-header': 'some value', |
| 36 | } |
| 37 | const res = await fetchViaHTTP(next.url, `api`, '', { |
| 38 | method: method.toUpperCase(), |
| 39 | headers, |
| 40 | body: method.toLowerCase() !== 'get' ? body : undefined, |
| 41 | }) |
| 42 | const data = await res.json() |
| 43 | expect(data.method).toEqual(method) |
| 44 | if (body) { |
| 45 | expect(data.headers['content-length'] || String(body.length)).toEqual( |
| 46 | String(body.length) |
| 47 | ) |
| 48 | } |
| 49 | expect(data.headers).toEqual(expect.objectContaining(headers)) |
| 50 | }) |
| 51 | } |
| 52 | |
| 53 | sendRequest('GET') |
| 54 | sendRequest('POST') |
no test coverage detected