Skip to content

Commit

Permalink
Fix E2E deploy test for API bodies (#41542)
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Oct 19, 2022
1 parent bc335d7 commit 3e2aec5
Showing 1 changed file with 39 additions and 25 deletions.
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

0 comments on commit 3e2aec5

Please sign in to comment.