@@ -5,6 +5,18 @@ import { convertAction } from './convertAction.ts';
5
5
console . warn = vi . fn ( ) ;
6
6
7
7
describe ( 'convertAction' , ( ) => {
8
+ test ( 'should convert base64 action' , ( ) => {
9
+ expect ( convertAction ( { } , v . base64 < string > ( ) , undefined ) ) . toStrictEqual ( {
10
+ contentEncoding : 'base64' ,
11
+ } ) ;
12
+ expect (
13
+ convertAction ( { type : 'string' } , v . base64 < string > ( ) , undefined )
14
+ ) . toStrictEqual ( {
15
+ type : 'string' ,
16
+ contentEncoding : 'base64' ,
17
+ } ) ;
18
+ } ) ;
19
+
8
20
test ( 'should convert description action' , ( ) => {
9
21
expect ( convertAction ( { } , v . description ( 'test' ) , undefined ) ) . toStrictEqual ( {
10
22
description : 'test' ,
@@ -34,6 +46,30 @@ describe('convertAction', () => {
34
46
} ) ;
35
47
} ) ;
36
48
49
+ test ( 'should convert IPv4 action' , ( ) => {
50
+ expect ( convertAction ( { } , v . ipv4 < string > ( ) , undefined ) ) . toStrictEqual ( {
51
+ format : 'ipv4' ,
52
+ } ) ;
53
+ expect (
54
+ convertAction ( { type : 'string' } , v . ipv4 < string > ( ) , undefined )
55
+ ) . toStrictEqual ( {
56
+ type : 'string' ,
57
+ format : 'ipv4' ,
58
+ } ) ;
59
+ } ) ;
60
+
61
+ test ( 'should convert IPv6 action' , ( ) => {
62
+ expect ( convertAction ( { } , v . ipv6 < string > ( ) , undefined ) ) . toStrictEqual ( {
63
+ format : 'ipv6' ,
64
+ } ) ;
65
+ expect (
66
+ convertAction ( { type : 'string' } , v . ipv6 < string > ( ) , undefined )
67
+ ) . toStrictEqual ( {
68
+ type : 'string' ,
69
+ format : 'ipv6' ,
70
+ } ) ;
71
+ } ) ;
72
+
37
73
test ( 'should convert ISO date action' , ( ) => {
38
74
expect ( convertAction ( { } , v . isoDate < string > ( ) , undefined ) ) . toStrictEqual ( {
39
75
format : 'date' ,
@@ -46,41 +82,43 @@ describe('convertAction', () => {
46
82
} ) ;
47
83
} ) ;
48
84
49
- test ( 'should convert ISO timestamp action' , ( ) => {
50
- expect (
51
- convertAction ( { } , v . isoTimestamp < string > ( ) , undefined )
52
- ) . toStrictEqual ( {
53
- format : 'date-time' ,
54
- } ) ;
85
+ test ( 'should convert ISO date time action' , ( ) => {
86
+ expect ( convertAction ( { } , v . isoDateTime < string > ( ) , undefined ) ) . toStrictEqual (
87
+ {
88
+ format : 'date-time' ,
89
+ }
90
+ ) ;
55
91
expect (
56
- convertAction ( { type : 'string' } , v . isoTimestamp < string > ( ) , undefined )
92
+ convertAction ( { type : 'string' } , v . isoDateTime < string > ( ) , undefined )
57
93
) . toStrictEqual ( {
58
94
type : 'string' ,
59
95
format : 'date-time' ,
60
96
} ) ;
61
97
} ) ;
62
98
63
- test ( 'should convert IPv4 action' , ( ) => {
64
- expect ( convertAction ( { } , v . ipv4 < string > ( ) , undefined ) ) . toStrictEqual ( {
65
- format : 'ipv4 ' ,
99
+ test ( 'should convert ISO time action' , ( ) => {
100
+ expect ( convertAction ( { } , v . isoTime < string > ( ) , undefined ) ) . toStrictEqual ( {
101
+ format : 'time ' ,
66
102
} ) ;
67
103
expect (
68
- convertAction ( { type : 'string' } , v . ipv4 < string > ( ) , undefined )
104
+ convertAction ( { type : 'string' } , v . isoTime < string > ( ) , undefined )
69
105
) . toStrictEqual ( {
70
106
type : 'string' ,
71
- format : 'ipv4 ' ,
107
+ format : 'time ' ,
72
108
} ) ;
73
109
} ) ;
74
110
75
- test ( 'should convert IPv6 action' , ( ) => {
76
- expect ( convertAction ( { } , v . ipv6 < string > ( ) , undefined ) ) . toStrictEqual ( {
77
- format : 'ipv6' ,
111
+ test ( 'should convert ISO timestamp action' , ( ) => {
112
+ expect (
113
+ convertAction ( { } , v . isoTimestamp < string > ( ) , undefined )
114
+ ) . toStrictEqual ( {
115
+ format : 'date-time' ,
78
116
} ) ;
79
117
expect (
80
- convertAction ( { type : 'string' } , v . ipv6 < string > ( ) , undefined )
118
+ convertAction ( { type : 'string' } , v . isoTimestamp < string > ( ) , undefined )
81
119
) . toStrictEqual ( {
82
120
type : 'string' ,
83
- format : 'ipv6 ' ,
121
+ format : 'date-time ' ,
84
122
} ) ;
85
123
} ) ;
86
124
@@ -144,68 +182,6 @@ describe('convertAction', () => {
144
182
) ;
145
183
} ) ;
146
184
147
- test ( 'should convert min length action for strings' , ( ) => {
148
- expect (
149
- convertAction (
150
- { type : 'string' } ,
151
- v . minLength < v . LengthInput , 3 > ( 3 ) ,
152
- undefined
153
- )
154
- ) . toStrictEqual ( {
155
- type : 'string' ,
156
- minLength : 3 ,
157
- } ) ;
158
- } ) ;
159
-
160
- test ( 'should convert min length action for arrays' , ( ) => {
161
- expect (
162
- convertAction (
163
- { type : 'array' } ,
164
- v . minLength < v . LengthInput , 3 > ( 3 ) ,
165
- undefined
166
- )
167
- ) . toStrictEqual ( {
168
- type : 'array' ,
169
- minItems : 3 ,
170
- } ) ;
171
- } ) ;
172
-
173
- test ( 'should throw error for min length action with invalid type' , ( ) => {
174
- const action = v . minLength < v . LengthInput , 3 > ( 3 ) ;
175
- const error1 =
176
- 'The "min_length" action is not supported on type "undefined".' ;
177
- expect ( ( ) => convertAction ( { } , action , undefined ) ) . toThrowError ( error1 ) ;
178
- expect ( ( ) =>
179
- convertAction ( { } , action , { errorMode : 'throw' } )
180
- ) . toThrowError ( error1 ) ;
181
- const error2 = 'The "min_length" action is not supported on type "object".' ;
182
- expect ( ( ) =>
183
- convertAction ( { type : 'object' } , action , undefined )
184
- ) . toThrowError ( error2 ) ;
185
- expect ( ( ) =>
186
- convertAction ( { type : 'object' } , action , { errorMode : 'throw' } )
187
- ) . toThrowError ( error2 ) ;
188
- } ) ;
189
-
190
- test ( 'should warn error for min length action with invalid type' , ( ) => {
191
- expect (
192
- convertAction ( { } , v . minLength < v . LengthInput , 3 > ( 3 ) , { errorMode : 'warn' } )
193
- ) . toStrictEqual ( {
194
- minLength : 3 ,
195
- } ) ;
196
- expect ( console . warn ) . toHaveBeenLastCalledWith (
197
- 'The "min_length" action is not supported on type "undefined".'
198
- ) ;
199
- expect (
200
- convertAction ( { type : 'object' } , v . minLength < v . LengthInput , 3 > ( 3 ) , {
201
- errorMode : 'warn' ,
202
- } )
203
- ) . toStrictEqual ( { type : 'object' , minLength : 3 } ) ;
204
- expect ( console . warn ) . toHaveBeenLastCalledWith (
205
- 'The "min_length" action is not supported on type "object".'
206
- ) ;
207
- } ) ;
208
-
209
185
test ( 'should convert max length action for strings' , ( ) => {
210
186
expect (
211
187
convertAction (
@@ -317,6 +293,68 @@ describe('convertAction', () => {
317
293
) ;
318
294
} ) ;
319
295
296
+ test ( 'should convert min length action for strings' , ( ) => {
297
+ expect (
298
+ convertAction (
299
+ { type : 'string' } ,
300
+ v . minLength < v . LengthInput , 3 > ( 3 ) ,
301
+ undefined
302
+ )
303
+ ) . toStrictEqual ( {
304
+ type : 'string' ,
305
+ minLength : 3 ,
306
+ } ) ;
307
+ } ) ;
308
+
309
+ test ( 'should convert min length action for arrays' , ( ) => {
310
+ expect (
311
+ convertAction (
312
+ { type : 'array' } ,
313
+ v . minLength < v . LengthInput , 3 > ( 3 ) ,
314
+ undefined
315
+ )
316
+ ) . toStrictEqual ( {
317
+ type : 'array' ,
318
+ minItems : 3 ,
319
+ } ) ;
320
+ } ) ;
321
+
322
+ test ( 'should throw error for min length action with invalid type' , ( ) => {
323
+ const action = v . minLength < v . LengthInput , 3 > ( 3 ) ;
324
+ const error1 =
325
+ 'The "min_length" action is not supported on type "undefined".' ;
326
+ expect ( ( ) => convertAction ( { } , action , undefined ) ) . toThrowError ( error1 ) ;
327
+ expect ( ( ) =>
328
+ convertAction ( { } , action , { errorMode : 'throw' } )
329
+ ) . toThrowError ( error1 ) ;
330
+ const error2 = 'The "min_length" action is not supported on type "object".' ;
331
+ expect ( ( ) =>
332
+ convertAction ( { type : 'object' } , action , undefined )
333
+ ) . toThrowError ( error2 ) ;
334
+ expect ( ( ) =>
335
+ convertAction ( { type : 'object' } , action , { errorMode : 'throw' } )
336
+ ) . toThrowError ( error2 ) ;
337
+ } ) ;
338
+
339
+ test ( 'should warn error for min length action with invalid type' , ( ) => {
340
+ expect (
341
+ convertAction ( { } , v . minLength < v . LengthInput , 3 > ( 3 ) , { errorMode : 'warn' } )
342
+ ) . toStrictEqual ( {
343
+ minLength : 3 ,
344
+ } ) ;
345
+ expect ( console . warn ) . toHaveBeenLastCalledWith (
346
+ 'The "min_length" action is not supported on type "undefined".'
347
+ ) ;
348
+ expect (
349
+ convertAction ( { type : 'object' } , v . minLength < v . LengthInput , 3 > ( 3 ) , {
350
+ errorMode : 'warn' ,
351
+ } )
352
+ ) . toStrictEqual ( { type : 'object' , minLength : 3 } ) ;
353
+ expect ( console . warn ) . toHaveBeenLastCalledWith (
354
+ 'The "min_length" action is not supported on type "object".'
355
+ ) ;
356
+ } ) ;
357
+
320
358
test ( 'should convert min value action for numbers' , ( ) => {
321
359
expect (
322
360
convertAction (
@@ -380,6 +418,60 @@ describe('convertAction', () => {
380
418
} ) ;
381
419
} ) ;
382
420
421
+ test ( 'should convert non empty action for strings' , ( ) => {
422
+ expect (
423
+ convertAction ( { type : 'string' } , v . nonEmpty ( ) , undefined )
424
+ ) . toStrictEqual ( {
425
+ type : 'string' ,
426
+ minLength : 1 ,
427
+ } ) ;
428
+ } ) ;
429
+
430
+ test ( 'should convert non empty action for arrays' , ( ) => {
431
+ expect (
432
+ convertAction ( { type : 'array' } , v . nonEmpty ( ) , undefined )
433
+ ) . toStrictEqual ( {
434
+ type : 'array' ,
435
+ minItems : 1 ,
436
+ } ) ;
437
+ } ) ;
438
+
439
+ test ( 'should throw error for non empty action with invalid type' , ( ) => {
440
+ const action = v . nonEmpty ( ) ;
441
+ const error1 =
442
+ 'The "non_empty" action is not supported on type "undefined".' ;
443
+ expect ( ( ) => convertAction ( { } , action , undefined ) ) . toThrowError ( error1 ) ;
444
+ expect ( ( ) =>
445
+ convertAction ( { } , action , { errorMode : 'throw' } )
446
+ ) . toThrowError ( error1 ) ;
447
+ const error2 = 'The "non_empty" action is not supported on type "object".' ;
448
+ expect ( ( ) =>
449
+ convertAction ( { type : 'object' } , action , undefined )
450
+ ) . toThrowError ( error2 ) ;
451
+ expect ( ( ) =>
452
+ convertAction ( { type : 'object' } , action , { errorMode : 'throw' } )
453
+ ) . toThrowError ( error2 ) ;
454
+ } ) ;
455
+
456
+ test ( 'should warn error for non empty action with invalid type' , ( ) => {
457
+ expect (
458
+ convertAction ( { } , v . nonEmpty ( ) , { errorMode : 'warn' } )
459
+ ) . toStrictEqual ( {
460
+ minLength : 1 ,
461
+ } ) ;
462
+ expect ( console . warn ) . toHaveBeenLastCalledWith (
463
+ 'The "non_empty" action is not supported on type "undefined".'
464
+ ) ;
465
+ expect (
466
+ convertAction ( { type : 'object' } , v . nonEmpty ( ) , {
467
+ errorMode : 'warn' ,
468
+ } )
469
+ ) . toStrictEqual ( { type : 'object' , minLength : 1 } ) ;
470
+ expect ( console . warn ) . toHaveBeenLastCalledWith (
471
+ 'The "non_empty" action is not supported on type "object".'
472
+ ) ;
473
+ } ) ;
474
+
383
475
test ( 'should convert supported regex action' , ( ) => {
384
476
expect (
385
477
convertAction ( { type : 'string' } , v . regex < string > ( / [ a - z A - Z ] / ) , undefined )
@@ -418,6 +510,18 @@ describe('convertAction', () => {
418
510
} ) ;
419
511
} ) ;
420
512
513
+ test ( 'should convert url action' , ( ) => {
514
+ expect ( convertAction ( { } , v . url < string > ( ) , undefined ) ) . toStrictEqual ( {
515
+ format : 'uri' ,
516
+ } ) ;
517
+ expect (
518
+ convertAction ( { type : 'string' } , v . url < string > ( ) , undefined )
519
+ ) . toStrictEqual ( {
520
+ type : 'string' ,
521
+ format : 'uri' ,
522
+ } ) ;
523
+ } ) ;
524
+
421
525
test ( 'should convert UUID action' , ( ) => {
422
526
expect ( convertAction ( { } , v . uuid < string > ( ) , undefined ) ) . toStrictEqual ( {
423
527
format : 'uuid' ,
0 commit comments