MCPcopy
hub / github.com/vercel/next.js / sendRequest

Function sendRequest

test/e2e/proxy-request-with-middleware/test/index.test.ts:24–51  ·  view source on GitHub ↗
(method)

Source from the content-addressed store, hash-verified

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')

Callers 1

index.test.tsFile · 0.85

Calls 9

fetchViaHTTPFunction · 0.90
includesMethod · 0.80
toLowerCaseMethod · 0.80
toUpperCaseMethod · 0.80
itFunction · 0.50
expectFunction · 0.50
StringFunction · 0.50
stringifyMethod · 0.45
jsonMethod · 0.45

Tested by

no test coverage detected