-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
reply-code.test.js
59 lines (50 loc) · 1.24 KB
/
reply-code.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
'use strict'
const t = require('tap')
const test = t.test
const Fastify = require('..')
test('code should handle null/undefined/float', t => {
t.plan(8)
const fastify = Fastify()
fastify.get('/null', function (request, reply) {
reply.status(null).send()
})
fastify.get('/undefined', function (request, reply) {
reply.status(undefined).send()
})
fastify.get('/404.5', function (request, reply) {
reply.status(404.5).send()
})
fastify.inject({
method: 'GET',
url: '/null'
}, (error, res) => {
t.error(error)
t.equal(res.statusCode, 500)
t.same(res.json(), {
statusCode: 500,
code: 'FST_ERR_BAD_STATUS_CODE',
error: 'Internal Server Error',
message: 'Called reply with an invalid status code: null'
})
})
fastify.inject({
method: 'GET',
url: '/undefined'
}, (error, res) => {
t.error(error)
t.equal(res.statusCode, 500)
t.same(res.json(), {
statusCode: 500,
code: 'FST_ERR_BAD_STATUS_CODE',
error: 'Internal Server Error',
message: 'Called reply with an invalid status code: undefined'
})
})
fastify.inject({
method: 'GET',
url: '/404.5'
}, (error, res) => {
t.error(error)
t.equal(res.statusCode, 404)
})
})