Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix E2E deploy test for API bodies #41542

Merged
merged 1 commit into from Oct 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
64 changes: 39 additions & 25 deletions test/e2e/middleware-fetches-with-body/index.test.ts
Expand Up @@ -64,7 +64,10 @@ describe('Middleware fetches with body', () => {
)

expect(res.status).toBe(413)
expect(res.statusText).toBe('Body exceeded 1mb limit')

if (!(global as any).isNextDeploy) {
expect(res.statusText).toBe('Body exceeded 1mb limit')
}
})

it('should be able to send and return body size equal to 1mb', async () => {
Expand Down Expand Up @@ -129,7 +132,10 @@ describe('Middleware fetches with body', () => {
)

expect(res.status).toBe(413)
expect(res.statusText).toBe('Body exceeded 5kb limit')

if (!(global as any).isNextDeploy) {
expect(res.statusText).toBe('Body exceeded 5kb limit')
}
})

it('should be able to send and return body size equal to 5kb', async () => {
Expand Down Expand Up @@ -171,7 +177,10 @@ describe('Middleware fetches with body', () => {
)

expect(res.status).toBe(413)
expect(res.statusText).toBe('Body exceeded 5mb limit')

if (!(global as any).isNextDeploy) {
expect(res.statusText).toBe('Body exceeded 5mb limit')
}
})

it('should return 413 for body greater than 5mb', async () => {
Expand All @@ -189,30 +198,35 @@ describe('Middleware fetches with body', () => {
)

expect(res.status).toBe(413)
expect(res.statusText).toBe('Body exceeded 5mb limit')
})

it('should be able to send and return body size equal to 5mb', async () => {
const bodySize = 5 * 1024 * 1024
const body = 'FGHI1J2K3L4M5N6O7P8Q9R0SaTbUcVdW'.repeat(bodySize / 32)

const res = await fetchViaHTTP(
next.url,
'/api/size_limit_5mb',
{},
{
body,
method: 'POST',
}
)
const data = await res.json()

expect(res.status).toBe(200)
expect(data.body.length).toBe(bodySize)
expect(data.body.split('FGHI1J2K3L4M5N6O7P8Q9R0SaTbUcVdW').length).toBe(
bodySize / 32 + 1
)
if (!(global as any).isNextDeploy) {
expect(res.statusText).toBe('Body exceeded 5mb limit')
}
})

if (!(global as any).isNextDeploy) {
it('should be able to send and return body size equal to 5mb', async () => {
const bodySize = 5 * 1024 * 1024
const body = 'FGHI1J2K3L4M5N6O7P8Q9R0SaTbUcVdW'.repeat(bodySize / 32)

const res = await fetchViaHTTP(
next.url,
'/api/size_limit_5mb',
{},
{
body,
method: 'POST',
}
)
const data = await res.json()

expect(res.status).toBe(200)
expect(data.body.length).toBe(bodySize)
expect(data.body.split('FGHI1J2K3L4M5N6O7P8Q9R0SaTbUcVdW').length).toBe(
bodySize / 32 + 1
)
})
}
})

describe('with bodyParser = false', () => {
Expand Down