From be95b9beb6ea325111841d1b9fda726b3e4839c5 Mon Sep 17 00:00:00 2001 From: Gil Pedersen Date: Fri, 17 Nov 2023 15:52:54 +0100 Subject: [PATCH] Remove support for pre v16 joi compiled schemas --- package.json | 1 - test/validation.js | 30 +++++++++++++++++++++++------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 7258b5806..335adba24 100755 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/validation.js b/test/validation.js index b4e363ff0..05b45d4ed 100755 --- a/test/validation.js +++ b/test/validation.js @@ -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'); @@ -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' + } } } });