Skip to content

Commit

Permalink
removed test
Browse files Browse the repository at this point in the history
  • Loading branch information
Eomm committed Dec 15, 2023
1 parent a7ee514 commit 6e22711
Showing 1 changed file with 0 additions and 73 deletions.
73 changes: 0 additions & 73 deletions test/schema-validation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1149,76 +1149,3 @@ test('Custom validator builder override by custom validator compiler in child in
})
t.equal(two.statusCode, 200)
})

test('Custom validator compiler override by custom validator builder in child instance', async t => {
t.plan(6)
const ajvDefaults = {
removeAdditional: true,
coerceTypes: true,
allErrors: true
}
const ajv1 = new AJV(ajvDefaults).addKeyword({ keyword: 'extended_one', type: 'object', validator: () => true })
const ajv2 = new AJV(ajvDefaults).addKeyword({ keyword: 'extended_two', type: 'object', validator: () => true })
const fastify = Fastify()

fastify.post('/one/:id', {
schema: {
params: {
type: 'object',
extended_one: true,
properties: {
id: { type: 'number' }
},
required: ['id']
}
},
handler: (req, _reply) => {
t.same(typeof req.params.id, 'number')
t.same(req.params.id, 42)
return 'ok'
}
})

fastify.register((embedded, _opts, done) => {
embedded.setSchemaController({
compilersFactory: {
buildValidator: function two () {
return (routeSchemaDef) => ajv2.compile(routeSchemaDef.schema)
}
}
})

embedded.post('/two/:id', {
schema: {
params: {
type: 'object',
extended_two: true,
properties: {
id: { type: 'number' }
},
required: ['id']
}
},
handler: (req, _reply) => {
t.same(typeof req.params.id, 'number')
t.same(req.params.id, 43)
return 'ok'
}
})
done()
})

fastify.setValidatorCompiler(function one (routeSchemaDef) { return ajv1.compile(routeSchemaDef.schema) })

const one = await fastify.inject({
method: 'POST',
url: '/one/42'
})
t.equal(one.statusCode, 200)

const two = await fastify.inject({
method: 'POST',
url: '/two/43'
})
t.equal(two.statusCode, 200)
})

0 comments on commit 6e22711

Please sign in to comment.