Skip to content

Commit

Permalink
test schema resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
adrai committed May 5, 2020
1 parent dce32e7 commit 0d535c4
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions test/schema-resolve.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use strict'

const t = require('tap')
const test = t.test
const Fastify = require('..')

test('schema resolve test', t => {
t.plan(3)

const fastify = new Fastify()

const sharedAddressSchema = {
$id: 'sharedAddress',
type: 'object',
required: ['line1', 'country', 'city', 'zipcode'],
properties: {
line1: { type: 'string' },
line2: { type: 'string' },
country: { type: 'string' },
city: { type: 'string' },
zipcode: { type: 'string' }
}
}

fastify.addSchema(sharedAddressSchema)

const bodyJsonSchema = {
type: 'object',
properties: {
vacation: { $ref: 'sharedAddress#' }
}
}
const schema = { body: bodyJsonSchema }

const routes = []
fastify.addHook('onRoute', (routeOptions) => {
routes.push(routeOptions)
})

fastify.post('/the/url', { schema }, () => { })

fastify.ready((err) => {
t.error(err)
t.notEqual(routes[0].schema.body.properties.vacation.$ref, 'sharedAddress#')
t.equal(routes[0].schema.body.properties.vacation.properties.line1.type, sharedAddressSchema.properties.line1.type)
})
})

0 comments on commit 0d535c4

Please sign in to comment.