File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,22 @@ export default {
4
4
type : "string" ,
5
5
errors : true ,
6
6
keyword : "is-youtube-url" ,
7
- validate : ( _ , value ) => {
8
- return StringUtils . isValidYouTubeURL ( value ) ;
7
+ compile : function compile ( ) {
8
+ return function validate ( value ) {
9
+ validate . errors = null ;
10
+
11
+ if ( ! StringUtils . isValidYouTubeURL ( value ) ) {
12
+ validate . errors = [
13
+ {
14
+ keyword : "is-youtube-url" ,
15
+ message : "Invalid YouTube URL" ,
16
+ params : { invalidInput : value } ,
17
+ } ,
18
+ ] ;
19
+ return false ;
20
+ }
21
+
22
+ return true ;
23
+ } ;
9
24
} ,
10
25
} ;
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ describe("Keywords", () => {
22
22
type : "object" ,
23
23
properties : { foo : { type : "string" , "is-youtube-url" : true } } ,
24
24
} ;
25
+
25
26
const validate = ajv . compile ( schema ) ;
26
27
const valid = validate ( {
27
28
foo : "https://www.youtube.com/watch?v=uxQxd_z_uqc&t=24sd" ,
@@ -35,10 +36,14 @@ describe("Keywords", () => {
35
36
type : "object" ,
36
37
properties : { foo : { type : "string" , "is-youtube-url" : true } } ,
37
38
} ;
39
+
38
40
const validate = ajv . compile ( schema ) ;
39
41
const valid = validate ( { foo : "https://example.com" } ) ;
40
42
43
+ const [ error ] = validate . errors ;
44
+
41
45
expect ( valid ) . toBe ( false ) ;
46
+ expect ( error . message ) . toBe ( "Invalid YouTube URL" ) ;
42
47
} ) ;
43
48
} ) ;
44
49
You can’t perform that action at this time.
0 commit comments