route.3.test.js — fastify Source File
Architecture documentation for route.3.test.js, a javascript file in the fastify codebase.
Entity Profile
Source Code
'use strict'
const { test } = require('node:test')
const joi = require('joi')
const Fastify = require('..')
test('does not mutate joi schemas', (t, done) => {
t.plan(5)
const fastify = Fastify()
function validatorCompiler ({ schema, method, url, httpPart }) {
// Needed to extract the params part,
// without the JSON-schema encapsulation
// that is automatically added by the short
// form of params.
schema = joi.object(schema.properties)
return validateHttpData
function validateHttpData (data) {
return schema.validate(data)
}
}
fastify.setValidatorCompiler(validatorCompiler)
fastify.route({
path: '/foo/:an_id',
method: 'GET',
schema: {
params: { an_id: joi.number() }
},
handler (req, res) {
t.assert.strictEqual(Object.keys(req.params).length, 1)
t.assert.strictEqual(req.params.an_id, '42')
res.send({ hello: 'world' })
}
})
fastify.inject({
method: 'GET',
url: '/foo/42'
}, (err, res) => {
t.assert.ifError(err)
t.assert.strictEqual(res.statusCode, 200)
t.assert.deepStrictEqual(res.json(), { hello: 'world' })
done()
})
})
test('multiple routes with one schema', (t, done) => {
t.plan(2)
const fastify = Fastify()
const schema = {
query: {
type: 'object',
properties: {
id: { type: 'number' }
// ... (154 more lines)
Source
Frequently Asked Questions
What does route.3.test.js do?
route.3.test.js is a source file in the fastify codebase, written in javascript.
Where is route.3.test.js in the architecture?
route.3.test.js is located at test/route.3.test.js (directory: test).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free