1- import { ajv } from ".." ;
1+ import { keywords } from "." ;
2+ import Ajv from "ajv" ;
3+ import addCustomMessages from "ajv-errors" ;
4+ import addFormats from "ajv-formats" ;
5+
6+ const ajv = addFormats (
7+ addCustomMessages (
8+ new Ajv ( { allErrors : true , $data : true , removeAdditional : true } )
9+ )
10+ ) ;
11+
12+ keywords . map ( keyword => ajv . addKeyword ( keyword ) ) ;
213
314describe ( "Keywords" , ( ) => {
415 describe ( "getBadWords" , ( ) => {
5- test ( "should fail if getBadWords returns bad words" , ( ) => {
16+ it ( "should fail if getBadWords returns bad words" , ( ) => {
617 const schema = {
718 type : "object" ,
8- properties : { foo : { type : "string" , getBadWords : false } }
19+ properties : { foo : { type : "string" , "disallow-profanity" : false } }
920 } ;
1021 const validate = ajv . compile ( schema ) ;
1122 validate ( { foo : "hi penis" } ) ;
@@ -16,7 +27,7 @@ describe("Keywords", () => {
1627 } ) ;
1728
1829 describe ( "is-youtube-url" , ( ) => {
19- test ( "should pass if url is valid" , ( ) => {
30+ it ( "should pass if url is valid" , ( ) => {
2031 const schema = {
2132 type : "object" ,
2233 properties : { foo : { type : "string" , "is-youtube-url" : true } }
@@ -30,7 +41,7 @@ describe("Keywords", () => {
3041 expect ( valid ) . toBe ( true ) ;
3142 } ) ;
3243
33- test ( "should fail if url is invalid" , ( ) => {
44+ it ( "should fail if url is invalid" , ( ) => {
3445 const schema = {
3546 type : "object" ,
3647 properties : { foo : { type : "string" , "is-youtube-url" : true } }
@@ -43,7 +54,7 @@ describe("Keywords", () => {
4354 expect ( validate ?. errors ?. [ 0 ] . message ) . toBe ( "Invalid YouTube URL" ) ;
4455 } ) ;
4556
46- test ( "should pass if url is falsy but the minLength is 0 or not present" , ( ) => {
57+ it ( "should pass if url is falsy but the minLength is 0 or not present" , ( ) => {
4758 const schema = {
4859 type : "object" ,
4960 properties : {
@@ -57,7 +68,7 @@ describe("Keywords", () => {
5768 expect ( valid ) . toBe ( true ) ;
5869 } ) ;
5970
60- test ( "should fail if url is falsy value but the minLength equal or greater then 1" , ( ) => {
71+ it ( "should fail if url is falsy value but the minLength equal or greater then 1" , ( ) => {
6172 const schema = {
6273 type : "object" ,
6374 properties : {
@@ -73,7 +84,7 @@ describe("Keywords", () => {
7384 } ) ;
7485
7586 describe ( "has-text" , ( ) => {
76- test ( "should pass if the text has at least 5 characters" , ( ) => {
87+ it ( "should pass if the text has at least 5 characters" , ( ) => {
7788 const schema = {
7889 type : "object" ,
7990 properties : {
@@ -92,7 +103,7 @@ describe("Keywords", () => {
92103 expect ( valid ) . toBe ( true ) ;
93104 } ) ;
94105
95- test ( "should fail if the text doesn't have at least 5 characters" , ( ) => {
106+ it ( "should fail if the text doesn't have at least 5 characters" , ( ) => {
96107 const schema = {
97108 type : "object" ,
98109 properties : {
@@ -114,7 +125,7 @@ describe("Keywords", () => {
114125 ) ;
115126 } ) ;
116127
117- test ( "should fail if the has more then 5 characters" , ( ) => {
128+ it ( "should fail if the has more then 5 characters" , ( ) => {
118129 const schema = {
119130 type : "object" ,
120131 properties : {
@@ -136,7 +147,7 @@ describe("Keywords", () => {
136147 ) ;
137148 } ) ;
138149
139- test ( "should fail if there's no text" , ( ) => {
150+ it ( "should fail if there's no text" , ( ) => {
140151 const schema = {
141152 type : "object" ,
142153 properties : {
@@ -156,7 +167,7 @@ describe("Keywords", () => {
156167 expect ( validate ?. errors ?. [ 0 ] . message ) . toBe ( "The value must contain text" ) ;
157168 } ) ;
158169
159- test ( "should pass if the text contains a valid YouTube URL" , ( ) => {
170+ it ( "should pass if the text contains a valid YouTube URL" , ( ) => {
160171 const schema = {
161172 type : "object" ,
162173 properties : {
@@ -192,7 +203,7 @@ describe("Keywords", () => {
192203 } ) ;
193204
194205 describe ( "secure-string" , ( ) => {
195- test ( "should pass if the string is empty" , ( ) => {
206+ it ( "should pass if the string is empty" , ( ) => {
196207 const schema = {
197208 type : "object" ,
198209 properties : {
@@ -211,7 +222,7 @@ describe("Keywords", () => {
211222 expect ( valid ) . toBe ( true ) ;
212223 } ) ;
213224
214- test ( "should pass if the string is secure" , ( ) => {
225+ it ( "should pass if the string is secure" , ( ) => {
215226 const schema = {
216227 type : "object" ,
217228 properties : {
@@ -230,7 +241,7 @@ describe("Keywords", () => {
230241 expect ( valid ) . toBe ( true ) ;
231242 } ) ;
232243
233- test ( "should fail if the string contains dissallowed characters" , ( ) => {
244+ it ( "should fail if the string contains dissallowed characters" , ( ) => {
234245 const schema = {
235246 type : "object" ,
236247 properties : {
@@ -252,7 +263,7 @@ describe("Keywords", () => {
252263 ) ;
253264 } ) ;
254265
255- test ( "should fail if the string contains dissallowed characters" , ( ) => {
266+ it ( "should fail if the string contains dissallowed characters" , ( ) => {
256267 const schema = {
257268 type : "object" ,
258269 properties : {
@@ -274,7 +285,7 @@ describe("Keywords", () => {
274285 ) ;
275286 } ) ;
276287
277- test ( "should fail if the string contains profanity" , ( ) => {
288+ it ( "should fail if the string contains profanity" , ( ) => {
278289 const schema = {
279290 type : "object" ,
280291 properties : {
@@ -296,7 +307,7 @@ describe("Keywords", () => {
296307 ) ;
297308 } ) ;
298309
299- test ( "should fail if the string only contains space characters" , ( ) => {
310+ it ( "should fail if the string only contains space characters" , ( ) => {
300311 const schema = {
301312 type : "object" ,
302313 properties : {
@@ -318,7 +329,7 @@ describe("Keywords", () => {
318329 ) ;
319330 } ) ;
320331
321- test ( "should fail if the string only contains space characters" , ( ) => {
332+ it ( "should fail if the string only contains space characters" , ( ) => {
322333 const schema = {
323334 type : "object" ,
324335 properties : {
@@ -340,7 +351,7 @@ describe("Keywords", () => {
340351 ) ;
341352 } ) ;
342353
343- test ( "should fail if the string contains unicode characters" , ( ) => {
354+ it ( "should fail if the string contains unicode characters" , ( ) => {
344355 const schema = {
345356 type : "object" ,
346357 properties : {
@@ -362,7 +373,7 @@ describe("Keywords", () => {
362373 ) ;
363374 } ) ;
364375
365- test ( "should fail if the string contains combined characters" , ( ) => {
376+ it ( "should fail if the string contains combined characters" , ( ) => {
366377 const schema = {
367378 type : "object" ,
368379 properties : {
@@ -384,7 +395,7 @@ describe("Keywords", () => {
384395 ) ;
385396 } ) ;
386397
387- test ( "should fail in the correct order" , ( ) => {
398+ it ( "should fail in the correct order" , ( ) => {
388399 const schema = {
389400 type : "object" ,
390401 properties : {
0 commit comments