Skip to content

Commit

Permalink
Apply hapijs#3663 to v16
Browse files Browse the repository at this point in the history
  • Loading branch information
rokoroku committed Apr 23, 2018
1 parent 7869933 commit 41177fe
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/schema.js
Expand Up @@ -128,12 +128,12 @@ internals.routeBase = Joi.object({
modify: Joi.boolean(),
options: Joi.object(),
ranges: Joi.boolean(),
sample: Joi.number().min(0).max(100),
sample: Joi.number().min(0).max(100).when('modify', { is: true, then: Joi.forbidden() }),
schema: Joi.alternatives(Joi.object(), Joi.array(), Joi.func()).allow(true, false),
status: Joi.object().pattern(/\d\d\d/, Joi.alternatives(Joi.object(), Joi.array(), Joi.func()).allow(true, false))
})
.without('modify', 'sample')
.assert('options.stripUnknown', Joi.when('modify', { is: true, otherwise: Joi.forbidden() }), 'meet requirement of having peer modify set to true'),
.assert('options.stripUnknown', Joi.when('modify', { is: true, otherwise: Joi.boolean().valid(false) }), 'meet requirement of having peer modify set to true'),
security: Joi.object({
hsts: [
Joi.object({
Expand Down
24 changes: 23 additions & 1 deletion test/validation.js
Expand Up @@ -1380,10 +1380,32 @@ describe('validation', () => {
},
handler
});
}).to.throw(/"modify" conflict with forbidden peer "sample"/);
}).to.throw(/"sample" is not allowed/);
done();
});

it('do not throws on sample with false response modify', () => {

const server = Hapi.server({ debug: false });
expect(() => {

server.route({
method: 'GET',
path: '/',
config: {
response: {
schema: Joi.object({
a: Joi.number()
}).options({ stripUnknown: true }),
modify: false,
sample: 90
}
},
handler: () => ({ a: 1, b: 2 })
});
}).to.not.throw();
});

it('validates response using custom validation function', (done) => {

let i = 0;
Expand Down

0 comments on commit 41177fe

Please sign in to comment.