File tree 2 files changed +23
-8
lines changed
2 files changed +23
-8
lines changed Original file line number Diff line number Diff line change 47
47
"@hapi/code" : " ^9.0.3" ,
48
48
"@hapi/eslint-plugin" : " ^7.0.0" ,
49
49
"@hapi/inert" : " ^7.0.1" ,
50
- "@hapi/joi-legacy-test" : " npm:@hapi/joi@^15.0.0" ,
51
50
"@hapi/lab" : " ^26.0.0" ,
52
51
"@hapi/vision" : " ^7.0.1" ,
53
52
"@hapi/wreck" : " ^18.0.1" ,
Original file line number Diff line number Diff line change @@ -5,7 +5,6 @@ const Code = require('@hapi/code');
5
5
const Hapi = require ( '..' ) ;
6
6
const Inert = require ( '@hapi/inert' ) ;
7
7
const Joi = require ( 'joi' ) ;
8
- const JoiLegacy = require ( '@hapi/joi-legacy-test' ) ;
9
8
const Lab = require ( '@hapi/lab' ) ;
10
9
11
10
@@ -18,20 +17,37 @@ const expect = Code.expect;
18
17
19
18
describe ( 'validation' , ( ) => {
20
19
21
- it ( 'validates using joi v15' , async ( ) => {
20
+ it ( 'validates using custom validator' , async ( ) => {
21
+
22
+ const Validator = class {
23
+ static compile ( schema ) {
24
+
25
+ if ( schema . a === 'is-number' ) {
26
+ return {
27
+ validate ( value , options ) {
28
+
29
+ if ( parseInt ( value ?. a , 10 ) . toString ( ) === value ?. a . toString ( ) ) {
30
+ return { value } ;
31
+ }
32
+
33
+ throw new Error ( 'Validation failed' ) ;
34
+ }
35
+ } ;
36
+ }
37
+ }
38
+ } ;
22
39
23
40
const server = Hapi . server ( ) ;
24
- server . validator ( JoiLegacy ) ;
41
+ server . validator ( Validator ) ;
25
42
server . route ( {
26
43
method : 'POST' ,
27
44
path : '/' ,
28
45
handler : ( ) => 'ok' ,
29
46
options : {
30
47
validate : {
31
- payload : JoiLegacy . object ( {
32
- a : JoiLegacy . number ( ) ,
33
- b : JoiLegacy . array ( )
34
- } )
48
+ payload : {
49
+ a : 'is-number'
50
+ }
35
51
}
36
52
}
37
53
} ) ;
You can’t perform that action at this time.
0 commit comments