Skip to content

Commit

Permalink
merge route and routeWithAuth from 3 tests into 2 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
callumfrance committed Oct 10, 2023
1 parent 0918ac9 commit 7f2993f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 47 deletions.
51 changes: 5 additions & 46 deletions packages/zod-openapi/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,20 +263,10 @@ describe('Query', () => {

describe('Header', () => {
const HeaderSchema = z.object({
'x-request-id': z.string().uuid(),
})

const HeaderSchemaAuth = z.object({
authorization: z.string(),
'x-request-id': z.string().uuid(),
})

const PingSchema = z
.object({
'x-request-id': z.string().uuid(),
})
.openapi('Post')

const PongSchema = z
.object({
'x-request-id': z.string().uuid(),
Expand All @@ -285,28 +275,10 @@ describe('Header', () => {
.openapi('Post')

const route = createRoute({
method: 'get',
path: '/ping',
request: {
headers: HeaderSchema,
},
responses: {
200: {
content: {
'application/json': {
schema: PingSchema,
},
},
description: 'Ping',
},
},
})

const routeWithAuth = createRoute({
method: 'get',
path: '/pong',
request: {
headers: HeaderSchemaAuth,
headers: HeaderSchema,
},
responses: {
200: {
Expand All @@ -329,38 +301,25 @@ describe('Header', () => {

app.openapi(route, controller)

app.openapi(routeWithAuth, controller)

it('Should return 200 response with correct contents', async () => {
const res = await app.request('/ping', {
const res = await app.request('/pong', {
headers: {
'x-request-id': '6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b',
Authorization: 'Bearer helloworld',
},
})
expect(res.status).toBe(200)
expect(await res.json()).toEqual({
'x-request-id': '6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b',
})
})

it('Should return 200 response for array of headers with Authorization included', async () => {
const res = await app.request('/pong', {
headers: {
Authorization: 'Bearer helloworld',
'x-request-id': '6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b',
},
})
expect(await res.json()).toEqual({
'authorization': 'Bearer helloworld',
'x-request-id': '6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b',
})
expect(res.status).toBe(200)
})

it('Should return 400 response with correct contents', async () => {
const res = await app.request('/ping', {
const res = await app.request('/pong', {
headers: {
'x-request-id': 'invalid-strings',
Authorization: 'Bearer helloworld',
},
})
expect(res.status).toBe(400)
Expand Down
7 changes: 6 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1765,11 +1765,16 @@
resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.24.51.tgz#645f33fe4e02defe26f2f5c0410e1c094eac7f5f"
integrity sha512-1P1OROm/rdubP5aFDSZQILU0vrLCJ4fvHt6EoqHEM+2D/G5MK3bIaymUKLit8Js9gbns5UyJnkP/TZROLw4tUA==

"@sinclair/typebox@^0.25.16", "@sinclair/typebox@^0.25.24":
"@sinclair/typebox@^0.25.16":
version "0.25.24"
resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.25.24.tgz#8c7688559979f7079aacaf31aa881c3aa410b718"
integrity sha512-XJfwUVUKDHF5ugKwIcxEgc9k8b7HbznCp6eUfWgu710hMPNIO4aw4/zB5RogDQz8nd6gyCDpU9O/m6qYEWY6yQ==

"@sinclair/typebox@^0.31.15":
version "0.31.17"
resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.31.17.tgz#f9ceed480957b919b203bb0b3e27bc559d1e8e19"
integrity sha512-GVYVHHOGINx+DT2DwjXoCQO0mRpztYKyb3d48tucuqhjhHpQYGp7Xx7dhhQGzILx/beuBrzfITMC7/5X7fw+UA==

"@sindresorhus/is@^0.14.0":
version "0.14.0"
resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-0.14.0.tgz#9fb3a3cf3132328151f353de4632e01e52102bea"
Expand Down

0 comments on commit 7f2993f

Please sign in to comment.