Aktueller Stand

This commit is contained in:
2026-01-22 19:05:45 +01:00
parent 85dee61a4d
commit e280e4eadb
1967 changed files with 397327 additions and 74093 deletions

View File

@@ -1,12 +1,11 @@
'use strict'
const t = require('tap')
const test = t.test
const { test } = require('node:test')
const Fastify = require('..')
const S = require('fluent-json-schema')
test('use fluent-json-schema object', t => {
t.plan(15)
test('use fluent-json-schema object', async (t) => {
t.plan(10)
const fastify = Fastify()
fastify.post('/:id', {
@@ -24,73 +23,62 @@ test('use fluent-json-schema object', t => {
}
})
// check params
fastify.inject({
const res1 = await fastify.inject({
method: 'POST',
url: '/1',
headers: { 'x-custom': 'me@me.me' },
query: { surname: 'bar' },
payload: { name: 'foo' }
}, (err, res) => {
t.error(err)
t.equal(res.statusCode, 400)
t.same(res.json(), { statusCode: 400, code: 'FST_ERR_VALIDATION', error: 'Bad Request', message: 'params/id must be >= 42' })
})
t.assert.strictEqual(res1.statusCode, 400)
t.assert.deepStrictEqual(res1.json(), { statusCode: 400, code: 'FST_ERR_VALIDATION', error: 'Bad Request', message: 'params/id must be >= 42' })
// check header
fastify.inject({
const res2 = await fastify.inject({
method: 'POST',
url: '/42',
headers: { 'x-custom': 'invalid' },
query: { surname: 'bar' },
payload: { name: 'foo' }
}, (err, res) => {
t.error(err)
t.equal(res.statusCode, 400)
t.same(res.json(), { statusCode: 400, code: 'FST_ERR_VALIDATION', error: 'Bad Request', message: 'headers/x-custom must match format "email"' })
})
t.assert.strictEqual(res2.statusCode, 400)
t.assert.deepStrictEqual(res2.json(), { statusCode: 400, code: 'FST_ERR_VALIDATION', error: 'Bad Request', message: 'headers/x-custom must match format "email"' })
// check query
fastify.inject({
const res3 = await fastify.inject({
method: 'POST',
url: '/42',
headers: { 'x-custom': 'me@me.me' },
query: { },
payload: { name: 'foo' }
}, (err, res) => {
t.error(err)
t.equal(res.statusCode, 400)
t.same(res.json(), { statusCode: 400, code: 'FST_ERR_VALIDATION', error: 'Bad Request', message: 'querystring must have required property \'surname\'' })
})
t.assert.strictEqual(res3.statusCode, 400)
t.assert.deepStrictEqual(res3.json(), { statusCode: 400, code: 'FST_ERR_VALIDATION', error: 'Bad Request', message: 'querystring must have required property \'surname\'' })
// check body
fastify.inject({
const res4 = await fastify.inject({
method: 'POST',
url: '/42',
headers: { 'x-custom': 'me@me.me' },
query: { surname: 'bar' },
payload: { name: [1, 2, 3] }
}, (err, res) => {
t.error(err)
t.equal(res.statusCode, 400)
t.same(res.json(), { statusCode: 400, code: 'FST_ERR_VALIDATION', error: 'Bad Request', message: 'body/name must be string' })
})
t.assert.strictEqual(res4.statusCode, 400)
t.assert.deepStrictEqual(res4.json(), { statusCode: 400, code: 'FST_ERR_VALIDATION', error: 'Bad Request', message: 'body/name must be string' })
// check response
fastify.inject({
const res5 = await fastify.inject({
method: 'POST',
url: '/42',
headers: { 'x-custom': 'me@me.me' },
query: { surname: 'bar' },
payload: { name: 'foo' }
}, (err, res) => {
t.error(err)
t.equal(res.statusCode, 200)
t.same(res.json(), { name: 'a', surname: 'b' })
})
t.assert.strictEqual(res5.statusCode, 200)
t.assert.deepStrictEqual(res5.json(), { name: 'a', surname: 'b' })
})
test('use complex fluent-json-schema object', t => {
test('use complex fluent-json-schema object', (t, done) => {
t.plan(1)
const fastify = Fastify()
@@ -113,10 +101,13 @@ test('use complex fluent-json-schema object', t => {
.prop('office', S.ref('https://fastify/demo#/definitions/addressSchema')).required()
fastify.post('/the/url', { schema: { body: bodyJsonSchema } }, () => { })
fastify.ready(err => t.error(err))
fastify.ready(err => {
t.assert.ifError(err)
done()
})
})
test('use fluent schema and plain JSON schema', t => {
test('use fluent schema and plain JSON schema', (t, done) => {
t.plan(1)
const fastify = Fastify()
@@ -154,10 +145,13 @@ test('use fluent schema and plain JSON schema', t => {
.prop('office', S.ref('https://fastify/demo#/definitions/addressSchema')).required()
fastify.post('/the/url', { schema: { body: bodyJsonSchema } }, () => { })
fastify.ready(err => t.error(err))
fastify.ready(err => {
t.assert.ifError(err)
done()
})
})
test('Should call valueOf internally', t => {
test('Should call valueOf internally', (t, done) => {
t.plan(1)
const fastify = new Fastify()
@@ -208,5 +202,8 @@ test('Should call valueOf internally', t => {
}
})
fastify.ready(t.error)
fastify.ready(err => {
t.assert.ifError(err)
done()
})
})