Skip to content

Commit b61abcc

Browse files
committed
Improving coverage
1 parent 8ac08a3 commit b61abcc

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

packages/app/fastify-api-contracts/src/fastifyApiContracts.spec.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ describe('fastifyApiContracts', () => {
147147
})
148148

149149
it('uses API spec to build valid DELETE route with header in fastify app', async () => {
150-
expect.assertions(2)
150+
expect.assertions(4)
151151
const contract = buildDeleteRoute({
152152
successResponseBodySchema: BODY_SCHEMA,
153153
requestPathParamsSchema: PATH_PARAMS_SCHEMA,
@@ -161,12 +161,21 @@ describe('fastifyApiContracts', () => {
161161
})
162162

163163
const app = await initApp(route)
164+
// using headers directly
164165
const response = await injectDelete(app, contract, {
165166
headers: { authorization: 'dummy' },
166167
pathParams: { userId: '1' },
167168
})
168169

169170
expect(response.statusCode).toBe(200)
171+
172+
// using headers factory
173+
const response2 = await injectDelete(app, contract, {
174+
headers: () => Promise.resolve({ authorization: 'dummy' }),
175+
pathParams: { userId: '1' },
176+
})
177+
178+
expect(response2.statusCode).toBe(200)
170179
})
171180
})
172181

@@ -319,7 +328,7 @@ describe('fastifyApiContracts', () => {
319328
})
320329

321330
it('uses API spec to build valid PUT route with header in fastify app', async () => {
322-
expect.assertions(4)
331+
expect.assertions(8)
323332
const contract = buildPayloadRoute({
324333
method: 'put',
325334
requestBodySchema: REQUEST_BODY_SCHEMA,
@@ -337,13 +346,23 @@ describe('fastifyApiContracts', () => {
337346
})
338347

339348
const app = await initApp(route)
349+
// using headers directly
340350
const response = await injectPut(app, contract, {
341351
headers: { authorization: 'dummy' },
342352
pathParams: { userId: '1' },
343353
body: { id: '2' },
344354
})
345355

346356
expect(response.statusCode).toBe(200)
357+
358+
// using headers factory
359+
const response2 = await injectPut(app, contract, {
360+
headers: () => Promise.resolve({ authorization: 'dummy' }),
361+
pathParams: { userId: '1' },
362+
body: { id: '2' },
363+
})
364+
365+
expect(response2.statusCode).toBe(200)
347366
})
348367

349368
it('supports isNonJSONResponseExpected and isEmptyResponseExpected parameters', async () => {

0 commit comments

Comments
 (0)