From 0d535c4e746853aa32050db0b54ff5032abbec0d Mon Sep 17 00:00:00 2001 From: Adriano Raiano Date: Tue, 5 May 2020 15:50:34 +0200 Subject: [PATCH] test schema resolve --- test/schema-resolve.test.js | 47 +++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 test/schema-resolve.test.js diff --git a/test/schema-resolve.test.js b/test/schema-resolve.test.js new file mode 100644 index 00000000000..ce8edec4c67 --- /dev/null +++ b/test/schema-resolve.test.js @@ -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) + }) +})