Home / File/ validation-error-handling.test.js — fastify Source File

validation-error-handling.test.js — fastify Source File

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

Entity Profile

Relationship Graph

Source Code

'use strict'

const { describe, test } = require('node:test')
const Joi = require('joi')
const Fastify = require('..')

const schema = {
  body: {
    type: 'object',
    properties: {
      name: { type: 'string' },
      work: { type: 'string' }
    },
    required: ['name', 'work']
  }
}

function echoBody (req, reply) {
  reply.code(200).send(req.body.name)
}

test('should work with valid payload', async (t) => {
  t.plan(2)

  const fastify = Fastify()

  fastify.post('/', { schema }, echoBody)

  const response = await fastify.inject({
    method: 'POST',
    payload: {
      name: 'michelangelo',
      work: 'sculptor, painter, architect and poet'
    },
    url: '/'
  })
  t.assert.deepStrictEqual(response.payload, 'michelangelo')
  t.assert.strictEqual(response.statusCode, 200)
})

test('should fail immediately with invalid payload', async (t) => {
  t.plan(2)

  const fastify = Fastify()

  fastify.post('/', { schema }, echoBody)

  const response = await fastify.inject({
    method: 'POST',
    payload: {
      hello: 'michelangelo'
    },
    url: '/'
  })

  t.assert.deepStrictEqual(response.json(), {
    statusCode: 400,
    code: 'FST_ERR_VALIDATION',
    error: 'Bad Request',
    message: "body must have required property 'name'"
// ... (841 more lines)

Domain

Subdomains

Functions

Frequently Asked Questions

What does validation-error-handling.test.js do?
validation-error-handling.test.js is a source file in the fastify codebase, written in javascript. It belongs to the CoreKernel domain, LifecycleManager subdomain.
What functions are defined in validation-error-handling.test.js?
validation-error-handling.test.js defines 1 function(s): echoBody.
Where is validation-error-handling.test.js in the architecture?
validation-error-handling.test.js is located at test/validation-error-handling.test.js (domain: CoreKernel, subdomain: LifecycleManager, directory: test).

Analyze Your Own Codebase

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

Try Supermodel Free