Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Soviut authored Dec 14, 2024
1 parent 6b15349 commit d61edf8
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/validator/validator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,25 +115,25 @@ describe('JSON', () => {
expect(data).toEqual({ foo: 'bar' })
})

it('Should not validate if Content-Type is not set', async () => {
it('Should return 415 response if Content-Type is not set', async () => {
const res = await app.request('http://localhost/post', {
method: 'POST',
body: JSON.stringify({ foo: 'bar' }),
})
expect(res.status).toBe(200)
expect(res.status).toBe(415)
const data = await res.json()
expect(data.foo).toBeUndefined()
})

it('Should not validate if Content-Type is wrong', async () => {
it('Should return 415 response if Content-Type is wrong', async () => {
const res = await app.request('http://localhost/post', {
method: 'POST',
headers: {
'Content-Type': 'text/plain;charset=utf-8',
},
body: JSON.stringify({ foo: 'bar' }),
})
expect(res.status).toBe(200)
expect(res.status).toBe(415)
})

it('Should validate if Content-Type is a application/json with a charset', async () => {
Expand Down Expand Up @@ -231,6 +231,29 @@ describe('FormData', () => {
expect(await res.json()).toEqual({ message: 'hi' })
})

it('Should return 415 response if Content-Type is not set', async () => {
const formData = new FormData()
formData.append('message', 'hi')
const res = await app.request('http://localhost/post', {
method: 'POST',
body: formData,
})
expect(res.status).toBe(415)
})

it('Should return 415 response if Content-Type is wrong', async () => {
const formData = new FormData()
formData.append('message', 'hi')
const res = await app.request('http://localhost/post', {
method: 'POST',
headers: {
'Content-Type': 'text/plain;charset=utf-8',
},
body: formData,
})
expect(res.status).toBe(415)
})

it('Should validate a URL Encoded Data', async () => {
const params = new URLSearchParams()
params.append('foo', 'bar')
Expand Down

0 comments on commit d61edf8

Please sign in to comment.