Home / File/ schema-serialization.test.js — fastify Source File

schema-serialization.test.js — fastify Source File

Architecture documentation for schema-serialization.test.js, a javascript file in the fastify codebase.

Entity Profile

Relationship Graph

Source Code

'use strict'

const { test } = require('node:test')
const Fastify = require('..')
const { waitForCb } = require('./toolkit')

const echoBody = (req, reply) => { reply.send(req.body) }

test('basic test', (t, testDone) => {
  t.plan(3)

  const fastify = Fastify()
  fastify.get('/', {
    schema: {
      response: {
        '2xx': {
          type: 'object',
          properties: {
            name: { type: 'string' },
            work: { type: 'string' }
          }
        }
      }
    }
  }, function (req, reply) {
    reply.code(200).send({ name: 'Foo', work: 'Bar', nick: 'Boo' })
  })

  fastify.inject('/', (err, res) => {
    t.assert.ifError(err)
    t.assert.deepStrictEqual(res.json(), { name: 'Foo', work: 'Bar' })
    t.assert.strictEqual(res.statusCode, 200)
    testDone()
  })
})

test('custom serializer options', (t, testDone) => {
  t.plan(3)

  const fastify = Fastify({
    serializerOpts: {
      rounding: 'ceil'
    }
  })
  fastify.get('/', {
    schema: {
      response: {
        '2xx': {
          type: 'integer'
        }
      }
    }
  }, function (req, reply) {
    reply.send(4.2)
  })

  fastify.inject('/', (err, res) => {
    t.assert.ifError(err)
    t.assert.strictEqual(res.payload, '5', 'it must use the ceil rounding')
    t.assert.strictEqual(res.statusCode, 200)
// ... (1112 more lines)

Domain

Subdomains

Functions

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free