Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove support for pre v16 joi #4474

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"@hapi/code": "^9.0.3",
"@hapi/eslint-plugin": "^7.0.0",
"@hapi/inert": "^7.0.1",
"@hapi/joi-legacy-test": "npm:@hapi/joi@^15.0.0",
"@hapi/lab": "^26.0.0",
"@hapi/vision": "^7.0.1",
"@hapi/wreck": "^18.0.1",
Expand Down
30 changes: 23 additions & 7 deletions test/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const Code = require('@hapi/code');
const Hapi = require('..');
const Inert = require('@hapi/inert');
const Joi = require('joi');
const JoiLegacy = require('@hapi/joi-legacy-test');
const Lab = require('@hapi/lab');


Expand All @@ -18,20 +17,37 @@ const expect = Code.expect;

describe('validation', () => {

it('validates using joi v15', async () => {
it('validates using custom validator', async () => {

const Validator = class {
static compile(schema) {

if (schema.a === 'is-number') {
return {
validate(value, options) {

if (parseInt(value?.a, 10).toString() === value?.a.toString()) {
return { value };
}

throw new Error('Validation failed');
}
};
}
}
};

const server = Hapi.server();
server.validator(JoiLegacy);
server.validator(Validator);
server.route({
method: 'POST',
path: '/',
handler: () => 'ok',
options: {
validate: {
payload: JoiLegacy.object({
a: JoiLegacy.number(),
b: JoiLegacy.array()
})
payload: {
a: 'is-number'
}
}
}
});
Expand Down
Loading