2022-06-20 11:46:52 +02:00
|
|
|
import { createNext, FileRef } from 'e2e-utils'
|
2024-04-09 00:25:43 +02:00
|
|
|
import { NextInstance } from 'e2e-utils'
|
2022-06-20 11:46:52 +02:00
|
|
|
import { fetchViaHTTP } from 'next-test-utils'
|
|
|
|
import path from 'path'
|
|
|
|
|
|
|
|
describe('Edge API endpoints can receive body', () => {
|
|
|
|
let next: NextInstance
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
|
|
|
next = await createNext({
|
|
|
|
files: {
|
|
|
|
'pages/api/edge.js': new FileRef(
|
|
|
|
path.resolve(__dirname, './app/pages/api/edge.js')
|
|
|
|
),
|
2022-07-20 02:33:00 +02:00
|
|
|
'pages/api/index.js': new FileRef(
|
|
|
|
path.resolve(__dirname, './app/pages/api/index.js')
|
|
|
|
),
|
2022-06-20 11:46:52 +02:00
|
|
|
},
|
|
|
|
dependencies: {},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
afterAll(() => next.destroy())
|
|
|
|
|
|
|
|
it('reads the body as text', async () => {
|
|
|
|
const res = await fetchViaHTTP(
|
|
|
|
next.url,
|
|
|
|
'/api/edge',
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
body: 'hello, world.',
|
|
|
|
method: 'POST',
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(res.status).toBe(200)
|
|
|
|
expect(await res.text()).toBe('got: hello, world.')
|
|
|
|
})
|
2022-07-20 02:33:00 +02:00
|
|
|
|
|
|
|
it('reads the body from index', async () => {
|
|
|
|
const res = await fetchViaHTTP(
|
|
|
|
next.url,
|
|
|
|
'/api',
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
body: 'hello, world.',
|
|
|
|
method: 'POST',
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(res.status).toBe(200)
|
|
|
|
expect(await res.text()).toBe('got: hello, world.')
|
|
|
|
})
|
2022-06-20 11:46:52 +02:00
|
|
|
})
|