Skip to content

Commit 259126d

Browse files
ATTENTION REQUIRED: unclear behaviour in the third test
1 parent 71d880d commit 259126d

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

test/enforce-schema.test.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,37 @@ test('Should pass if no options passed and schema validation explicitly disabled
3232

3333
await fastify.register(enforceSchema)
3434

35-
fastify.post('/foo', { schema: false }, (req, reply) => {
35+
fastify.get('/foo', { schema: false }, (req, reply) => {
3636
reply.code(201).send('ok')
3737
})
3838

3939
const res = await fastify.inject({
40-
method: 'POST',
40+
method: 'GET',
4141
url: '/foo'
4242
})
4343

4444
t.equal(res.statusCode, 201)
4545
t.equal(res.payload, 'ok')
4646
})
4747

48+
test('Should fail if no options passed: every POST should have a body unless explicitly set to false', async (t) => {
49+
t.plan(1)
50+
51+
const fastify = Fastify()
52+
53+
// NOTE: My understanding is that we shouldn't need to manually specify { required: ['body'] } for the body to be required, but this isn't current behavior
54+
await fastify.register(enforceSchema)
55+
56+
try {
57+
fastify.post('/foo', { schema: { response: { 201: {} } }}, (req, reply) => {
58+
reply.code(201).send('ok')
59+
})
60+
} catch (error) {
61+
// This is the error message I would expect to see
62+
t.equal(error.message, 'POST: /foo is missing a body schema')
63+
}
64+
})
65+
4866
test('Should fail if schema is missing', async (t) => {
4967
t.plan(1)
5068

0 commit comments

Comments
 (0)