@@ -17,6 +17,54 @@ describe('convertAction', () => {
17
17
} ) ;
18
18
} ) ;
19
19
20
+ test ( 'should convert bic action' , ( ) => {
21
+ expect ( convertAction ( { } , v . bic < string > ( ) , undefined ) ) . toStrictEqual ( {
22
+ pattern : v . BIC_REGEX . source ,
23
+ } ) ;
24
+ expect (
25
+ convertAction ( { type : 'string' } , v . bic < string > ( ) , undefined )
26
+ ) . toStrictEqual ( {
27
+ type : 'string' ,
28
+ pattern : v . BIC_REGEX . source ,
29
+ } ) ;
30
+ } ) ;
31
+
32
+ test ( 'should convert cuid2 action' , ( ) => {
33
+ expect ( convertAction ( { } , v . cuid2 < string > ( ) , undefined ) ) . toStrictEqual ( {
34
+ pattern : v . CUID2_REGEX . source ,
35
+ } ) ;
36
+ expect (
37
+ convertAction ( { type : 'string' } , v . cuid2 < string > ( ) , undefined )
38
+ ) . toStrictEqual ( {
39
+ type : 'string' ,
40
+ pattern : v . CUID2_REGEX . source ,
41
+ } ) ;
42
+ } ) ;
43
+
44
+ test ( 'should convert decimal action' , ( ) => {
45
+ expect ( convertAction ( { } , v . decimal < string > ( ) , undefined ) ) . toStrictEqual ( {
46
+ pattern : v . DECIMAL_REGEX . source ,
47
+ } ) ;
48
+ expect (
49
+ convertAction ( { type : 'string' } , v . decimal < string > ( ) , undefined )
50
+ ) . toStrictEqual ( {
51
+ type : 'string' ,
52
+ pattern : v . DECIMAL_REGEX . source ,
53
+ } ) ;
54
+ } ) ;
55
+
56
+ test ( 'should convert digits action' , ( ) => {
57
+ expect ( convertAction ( { } , v . digits < string > ( ) , undefined ) ) . toStrictEqual ( {
58
+ pattern : v . DIGITS_REGEX . source ,
59
+ } ) ;
60
+ expect (
61
+ convertAction ( { type : 'string' } , v . digits < string > ( ) , undefined )
62
+ ) . toStrictEqual ( {
63
+ type : 'string' ,
64
+ pattern : v . DIGITS_REGEX . source ,
65
+ } ) ;
66
+ } ) ;
67
+
20
68
test ( 'should convert description action' , ( ) => {
21
69
expect ( convertAction ( { } , v . description ( 'test' ) , undefined ) ) . toStrictEqual ( {
22
70
description : 'test' ,
@@ -35,6 +83,95 @@ describe('convertAction', () => {
35
83
} ) ;
36
84
} ) ;
37
85
86
+ test ( 'should convert emoji action' , ( ) => {
87
+ expect ( convertAction ( { } , v . emoji < string > ( ) , undefined ) ) . toStrictEqual ( {
88
+ pattern : v . EMOJI_REGEX . source ,
89
+ } ) ;
90
+ expect (
91
+ convertAction ( { type : 'string' } , v . emoji < string > ( ) , undefined )
92
+ ) . toStrictEqual ( {
93
+ type : 'string' ,
94
+ pattern : v . EMOJI_REGEX . source ,
95
+ } ) ;
96
+ } ) ;
97
+
98
+ test ( 'should convert empty action for strings' , ( ) => {
99
+ expect (
100
+ convertAction ( { type : 'string' } , v . empty ( ) , undefined )
101
+ ) . toStrictEqual ( {
102
+ type : 'string' ,
103
+ maxLength : 0 ,
104
+ } ) ;
105
+ } ) ;
106
+
107
+ test ( 'should convert empty action for arrays' , ( ) => {
108
+ expect (
109
+ convertAction ( { type : 'array' } , v . empty ( ) , undefined )
110
+ ) . toStrictEqual ( {
111
+ type : 'array' ,
112
+ maxItems : 0 ,
113
+ } ) ;
114
+ } ) ;
115
+
116
+ test ( 'should throw error for empty action with invalid type' , ( ) => {
117
+ const action = v . empty ( ) ;
118
+ const error1 = 'The "empty" action is not supported on type "undefined".' ;
119
+ expect ( ( ) => convertAction ( { } , action , undefined ) ) . toThrowError ( error1 ) ;
120
+ expect ( ( ) =>
121
+ convertAction ( { } , action , { errorMode : 'throw' } )
122
+ ) . toThrowError ( error1 ) ;
123
+ const error2 = 'The "empty" action is not supported on type "object".' ;
124
+ expect ( ( ) =>
125
+ convertAction ( { type : 'object' } , action , undefined )
126
+ ) . toThrowError ( error2 ) ;
127
+ expect ( ( ) =>
128
+ convertAction ( { type : 'object' } , action , { errorMode : 'throw' } )
129
+ ) . toThrowError ( error2 ) ;
130
+ } ) ;
131
+
132
+ test ( 'should warn error for empty action with invalid type' , ( ) => {
133
+ expect ( convertAction ( { } , v . empty ( ) , { errorMode : 'warn' } ) ) . toStrictEqual ( {
134
+ maxLength : 0 ,
135
+ } ) ;
136
+ expect ( console . warn ) . toHaveBeenLastCalledWith (
137
+ 'The "empty" action is not supported on type "undefined".'
138
+ ) ;
139
+ expect (
140
+ convertAction ( { type : 'object' } , v . empty ( ) , {
141
+ errorMode : 'warn' ,
142
+ } )
143
+ ) . toStrictEqual ( { type : 'object' , maxLength : 0 } ) ;
144
+ expect ( console . warn ) . toHaveBeenLastCalledWith (
145
+ 'The "empty" action is not supported on type "object".'
146
+ ) ;
147
+ } ) ;
148
+
149
+ test ( 'should convert hexadecimal action' , ( ) => {
150
+ expect ( convertAction ( { } , v . hexadecimal < string > ( ) , undefined ) ) . toStrictEqual (
151
+ {
152
+ pattern : v . HEXADECIMAL_REGEX . source ,
153
+ }
154
+ ) ;
155
+ expect (
156
+ convertAction ( { type : 'string' } , v . hexadecimal < string > ( ) , undefined )
157
+ ) . toStrictEqual ( {
158
+ type : 'string' ,
159
+ pattern : v . HEXADECIMAL_REGEX . source ,
160
+ } ) ;
161
+ } ) ;
162
+
163
+ test ( 'should convert hex color action' , ( ) => {
164
+ expect ( convertAction ( { } , v . hexColor < string > ( ) , undefined ) ) . toStrictEqual ( {
165
+ pattern : v . HEX_COLOR_REGEX . source ,
166
+ } ) ;
167
+ expect (
168
+ convertAction ( { type : 'string' } , v . hexColor < string > ( ) , undefined )
169
+ ) . toStrictEqual ( {
170
+ type : 'string' ,
171
+ pattern : v . HEX_COLOR_REGEX . source ,
172
+ } ) ;
173
+ } ) ;
174
+
38
175
test ( 'should convert integer action' , ( ) => {
39
176
expect ( convertAction ( { } , v . integer < number > ( ) , undefined ) ) . toStrictEqual ( {
40
177
type : 'integer' ,
@@ -418,6 +555,18 @@ describe('convertAction', () => {
418
555
} ) ;
419
556
} ) ;
420
557
558
+ test ( 'should convert Nano ID action' , ( ) => {
559
+ expect ( convertAction ( { } , v . nanoid < string > ( ) , undefined ) ) . toStrictEqual ( {
560
+ pattern : v . NANO_ID_REGEX . source ,
561
+ } ) ;
562
+ expect (
563
+ convertAction ( { type : 'string' } , v . nanoid < string > ( ) , undefined )
564
+ ) . toStrictEqual ( {
565
+ type : 'string' ,
566
+ pattern : v . NANO_ID_REGEX . source ,
567
+ } ) ;
568
+ } ) ;
569
+
421
570
test ( 'should convert non empty action for strings' , ( ) => {
422
571
expect (
423
572
convertAction ( { type : 'string' } , v . nonEmpty ( ) , undefined )
@@ -472,6 +621,18 @@ describe('convertAction', () => {
472
621
) ;
473
622
} ) ;
474
623
624
+ test ( 'should convert octal action' , ( ) => {
625
+ expect ( convertAction ( { } , v . octal < string > ( ) , undefined ) ) . toStrictEqual ( {
626
+ pattern : v . OCTAL_REGEX . source ,
627
+ } ) ;
628
+ expect (
629
+ convertAction ( { type : 'string' } , v . octal < string > ( ) , undefined )
630
+ ) . toStrictEqual ( {
631
+ type : 'string' ,
632
+ pattern : v . OCTAL_REGEX . source ,
633
+ } ) ;
634
+ } ) ;
635
+
475
636
test ( 'should convert supported regex action' , ( ) => {
476
637
expect (
477
638
convertAction ( { type : 'string' } , v . regex < string > ( / [ a - z A - Z ] / ) , undefined )
@@ -510,6 +671,18 @@ describe('convertAction', () => {
510
671
} ) ;
511
672
} ) ;
512
673
674
+ test ( 'should convert ULID action' , ( ) => {
675
+ expect ( convertAction ( { } , v . ulid < string > ( ) , undefined ) ) . toStrictEqual ( {
676
+ pattern : v . ULID_REGEX . source ,
677
+ } ) ;
678
+ expect (
679
+ convertAction ( { type : 'string' } , v . ulid < string > ( ) , undefined )
680
+ ) . toStrictEqual ( {
681
+ type : 'string' ,
682
+ pattern : v . ULID_REGEX . source ,
683
+ } ) ;
684
+ } ) ;
685
+
513
686
test ( 'should convert url action' , ( ) => {
514
687
expect ( convertAction ( { } , v . url < string > ( ) , undefined ) ) . toStrictEqual ( {
515
688
format : 'uri' ,
0 commit comments