Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) Safe-mode: OFF (not secure) /usr/local/lib/node_modules/homebridge-config-ui-x/node_modules/fastify/test/ drwxr-xr-x | |
| Viewing file: Select action/file-type: 'use strict'
const t = require('tap')
const test = t.test
const sget = require('simple-get').concat
const Fastify = require('..')
test('nullable string', t => {
t.plan(3)
const fastify = Fastify()
fastify.route({
method: 'POST',
url: '/',
handler: (req, reply) => {
t.same(req.body.hello, null)
reply.code(200).send(req.body)
},
schema: {
body: {
type: 'object',
properties: {
hello: {
type: 'string',
format: 'email',
nullable: true
}
}
},
response: {
200: {
type: 'object',
properties: {
hello: {
type: 'string',
format: 'email',
nullable: true
}
}
}
}
}
})
fastify.inject({
method: 'POST',
url: '/',
body: {
hello: null
}
}, (err, res) => {
t.error(err)
t.same(res.payload.hello, null)
})
})
test('object or null body', t => {
t.plan(5)
const fastify = Fastify()
fastify.route({
method: 'POST',
url: '/',
handler: (req, reply) => {
t.equal(req.body, null)
reply.code(200).send({ requestBody: req.body })
},
schema: {
body: {
type: ['object', 'null'],
properties: {
hello: {
type: 'string',
format: 'email'
}
}
},
response: {
200: {
type: 'object',
nullable: true,
properties: {
requestBody: {
type: 'string',
format: 'email',
nullable: true
}
}
}
}
}
})
fastify.listen(0, (err) => {
fastify.server.unref()
t.error(err)
sget({
method: 'POST',
url: 'http://localhost:' + fastify.server.address().port
}, (err, response, body) => {
t.error(err)
t.equal(response.statusCode, 200)
t.same(JSON.parse(body), { requestBody: null })
})
})
})
test('nullable body', t => {
t.plan(5)
const fastify = Fastify()
fastify.route({
method: 'POST',
url: '/',
handler: (req, reply) => {
t.equal(req.body, null)
reply.code(200).send({ requestBody: req.body })
},
schema: {
body: {
type: 'object',
nullable: true,
properties: {
hello: {
type: 'string',
format: 'email'
}
}
},
response: {
200: {
type: 'object',
nullable: true,
properties: {
requestBody: {
type: 'string',
format: 'email',
nullable: true
}
}
}
}
}
})
fastify.listen(0, (err) => {
fastify.server.unref()
t.error(err)
sget({
method: 'POST',
url: 'http://localhost:' + fastify.server.address().port
}, (err, response, body) => {
t.error(err)
t.equal(response.statusCode, 200)
t.same(JSON.parse(body), { requestBody: null })
})
})
})
|
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0119 ]-- |