Home / File/ validation.test.js — fastify Source File

validation.test.js — fastify Source File

Architecture documentation for validation.test.js, a javascript file in the fastify codebase.

File javascript 2 classes

Entity Profile

Relationship Graph

Source Code

'use strict'

const { test } = require('node:test')

const Ajv = require('ajv')
const ajv = new Ajv({ coerceTypes: true })

const validation = require('../../lib/validation')
const { normalizeSchema } = require('../../lib/schemas')
const symbols = require('../../lib/validation').symbols
const { kSchemaVisited } = require('../../lib/symbols')

test('Symbols', t => {
  t.plan(5)
  t.assert.strictEqual(typeof symbols.responseSchema, 'symbol')
  t.assert.strictEqual(typeof symbols.bodySchema, 'symbol')
  t.assert.strictEqual(typeof symbols.querystringSchema, 'symbol')
  t.assert.strictEqual(typeof symbols.paramsSchema, 'symbol')
  t.assert.strictEqual(typeof symbols.headersSchema, 'symbol')
})

;['compileSchemasForValidation',
  'compileSchemasForSerialization'].forEach(func => {
  test(`${func} schema - missing schema`, t => {
    t.plan(2)
    const context = {}
    validation[func](context)
    t.assert.strictEqual(typeof context[symbols.bodySchema], 'undefined')
    t.assert.strictEqual(typeof context[symbols.responseSchema], 'undefined')
  })

  test(`${func} schema - missing output schema`, t => {
    t.plan(1)
    const context = { schema: {} }
    validation[func](context, null)
    t.assert.strictEqual(typeof context[symbols.responseSchema], 'undefined')
  })
})

test('build schema - output schema', t => {
  t.plan(2)
  const opts = {
    schema: {
      response: {
        '2xx': {
          type: 'object',
          properties: {
            hello: { type: 'string' }
          }
        },
        201: {
          type: 'object',
          properties: {
            hello: { type: 'number' }
          }
        }
      }
    }
  }
  validation.compileSchemasForSerialization(opts, ({ schema, method, url, httpPart }) => ajv.compile(schema))
// ... (293 more lines)

Frequently Asked Questions

What does validation.test.js do?
validation.test.js is a source file in the fastify codebase, written in javascript.
Where is validation.test.js in the architecture?
validation.test.js is located at test/internals/validation.test.js (directory: test/internals).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free