co.validation 2.7.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/createValidation.d.ts +6 -0
- package/lib/createValidation.d.ts.map +1 -0
- package/lib/createValidation.js +153 -204
- package/lib/createValidation.js.map +1 -0
- package/lib/helpers.d.ts +2 -0
- package/lib/helpers.d.ts.map +1 -0
- package/lib/helpers.js +4 -8
- package/lib/helpers.js.map +1 -0
- package/lib/index.d.ts +7 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +18 -38
- package/lib/index.js.map +1 -0
- package/lib/messageProcessor.d.ts +7 -0
- package/lib/messageProcessor.d.ts.map +1 -0
- package/lib/messageProcessor.js +45 -51
- package/lib/messageProcessor.js.map +1 -0
- package/lib/operators.d.ts +4 -0
- package/lib/operators.d.ts.map +1 -0
- package/lib/operators.js +60 -71
- package/lib/operators.js.map +1 -0
- package/lib/types.d.ts +123 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +3 -0
- package/lib/types.js.map +1 -0
- package/lib/validators.d.ts +18 -0
- package/lib/validators.d.ts.map +1 -0
- package/lib/validators.js +164 -196
- package/lib/validators.js.map +1 -0
- package/package.json +13 -21
- package/tsconfig.json +32 -0
- package/lib/__tests__/component.arrayValidation.js +0 -201
- package/lib/__tests__/component.objectValidation.js +0 -556
- package/lib/__tests__/component.reduxFormValidation.js +0 -20
- package/lib/__tests__/component.valueValidation.js +0 -923
- package/lib/__tests__/integration.objectValidation.js +0 -64
- package/lib/__tests__/integration.registrationForm.js +0 -234
- package/lib/__tests__/integration.valueValidation.js +0 -448
- package/lib/__tests__/operators.js +0 -28
- package/lib/__tests__/unit.operators.js +0 -125
- package/lib/createObjectValidation.js +0 -34
- package/lib/createValueValidation.js +0 -71
|
@@ -1,448 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _ = require("..");
|
|
4
|
-
|
|
5
|
-
describe('createValueValidation', () => {
|
|
6
|
-
it('supports required', () => {
|
|
7
|
-
expect((0, _.createValueValidation)({
|
|
8
|
-
type: 'required'
|
|
9
|
-
})('')).toEqual(['Required']);
|
|
10
|
-
expect((0, _.createValueValidation)({
|
|
11
|
-
type: 'required',
|
|
12
|
-
getMessage: () => 'Required Field'
|
|
13
|
-
})('')).toEqual(['Required Field']);
|
|
14
|
-
expect((0, _.createValueValidation)({
|
|
15
|
-
type: 'required',
|
|
16
|
-
getMessage: () => 'Required'
|
|
17
|
-
})('a')).toEqual(undefined);
|
|
18
|
-
expect((0, _.createValueValidation)({
|
|
19
|
-
type: 'required',
|
|
20
|
-
getMessage: () => 'Required'
|
|
21
|
-
})(5)).toEqual(undefined);
|
|
22
|
-
expect((0, _.createValueValidation)({
|
|
23
|
-
type: 'required',
|
|
24
|
-
getMessage: () => 'Required'
|
|
25
|
-
})(0)).toEqual(undefined);
|
|
26
|
-
});
|
|
27
|
-
it('supports equals', () => {
|
|
28
|
-
expect((0, _.createValueValidation)({
|
|
29
|
-
type: 'equals',
|
|
30
|
-
to: '123'
|
|
31
|
-
})('1234')).toEqual(['Must be equal to 123']);
|
|
32
|
-
expect((0, _.createValueValidation)({
|
|
33
|
-
type: 'equals',
|
|
34
|
-
to: 123
|
|
35
|
-
})('123')).toEqual(['Must be equal to 123']);
|
|
36
|
-
expect((0, _.createValueValidation)({
|
|
37
|
-
type: 'equals',
|
|
38
|
-
to: true
|
|
39
|
-
})(1)).toEqual(['Must be equal to true']);
|
|
40
|
-
expect((0, _.createValueValidation)({
|
|
41
|
-
type: 'equals',
|
|
42
|
-
to: '123',
|
|
43
|
-
getMessage: to => to
|
|
44
|
-
})('1234')).toEqual(['123']);
|
|
45
|
-
expect((0, _.createValueValidation)({
|
|
46
|
-
type: 'equals',
|
|
47
|
-
to: '123'
|
|
48
|
-
})('123')).toEqual(undefined);
|
|
49
|
-
expect((0, _.createValueValidation)({
|
|
50
|
-
type: 'equals',
|
|
51
|
-
to: 123
|
|
52
|
-
})(123)).toEqual(undefined);
|
|
53
|
-
expect((0, _.createValueValidation)({
|
|
54
|
-
type: 'equals',
|
|
55
|
-
to: true
|
|
56
|
-
})(true)).toEqual(undefined);
|
|
57
|
-
expect((0, _.createValueValidation)({
|
|
58
|
-
type: 'equals',
|
|
59
|
-
to: false
|
|
60
|
-
})(false)).toEqual(undefined);
|
|
61
|
-
});
|
|
62
|
-
it('supports equalsToField', () => {
|
|
63
|
-
expect((0, _.createValueValidation)({
|
|
64
|
-
type: 'equalsToField',
|
|
65
|
-
field: 'otherField'
|
|
66
|
-
})('1234', {
|
|
67
|
-
otherField: '123'
|
|
68
|
-
})).toEqual(['Must be equal to otherField']);
|
|
69
|
-
expect((0, _.createValueValidation)({
|
|
70
|
-
type: 'equalsToField',
|
|
71
|
-
field: 'otherField'
|
|
72
|
-
})(null, {
|
|
73
|
-
otherField: '123'
|
|
74
|
-
})).toEqual(['Must be equal to otherField']);
|
|
75
|
-
expect((0, _.createValueValidation)({
|
|
76
|
-
type: 'equalsToField',
|
|
77
|
-
field: 'otherField'
|
|
78
|
-
})('123', {
|
|
79
|
-
otherField: 123
|
|
80
|
-
})).toEqual(['Must be equal to otherField']);
|
|
81
|
-
expect((0, _.createValueValidation)({
|
|
82
|
-
type: 'equalsToField',
|
|
83
|
-
field: 'otherField'
|
|
84
|
-
})(1, {
|
|
85
|
-
otherField: true
|
|
86
|
-
})).toEqual(['Must be equal to otherField']);
|
|
87
|
-
expect((0, _.createValueValidation)({
|
|
88
|
-
type: 'equalsToField',
|
|
89
|
-
field: 'otherField',
|
|
90
|
-
getMessage: to => to
|
|
91
|
-
})('1234', {
|
|
92
|
-
otherField: '123'
|
|
93
|
-
})).toEqual(['otherField']);
|
|
94
|
-
expect((0, _.createValueValidation)({
|
|
95
|
-
type: 'equalsToField',
|
|
96
|
-
field: 'otherField'
|
|
97
|
-
})('123', {
|
|
98
|
-
otherField: '123'
|
|
99
|
-
})).toEqual(undefined);
|
|
100
|
-
expect((0, _.createValueValidation)({
|
|
101
|
-
type: 'equalsToField',
|
|
102
|
-
field: 'otherField'
|
|
103
|
-
})(123, {
|
|
104
|
-
otherField: 123
|
|
105
|
-
})).toEqual(undefined);
|
|
106
|
-
expect((0, _.createValueValidation)({
|
|
107
|
-
type: 'equalsToField',
|
|
108
|
-
field: 'otherField'
|
|
109
|
-
})(true, {
|
|
110
|
-
otherField: true
|
|
111
|
-
})).toEqual(undefined);
|
|
112
|
-
expect((0, _.createValueValidation)({
|
|
113
|
-
type: 'equalsToField',
|
|
114
|
-
field: 'otherField'
|
|
115
|
-
})(false, {
|
|
116
|
-
otherField: false
|
|
117
|
-
})).toEqual(undefined);
|
|
118
|
-
});
|
|
119
|
-
it('supports regex', () => {
|
|
120
|
-
expect((0, _.createValueValidation)({
|
|
121
|
-
type: 'regex',
|
|
122
|
-
regex: /[^0-9]/i
|
|
123
|
-
})('1234a')).toEqual(['Invalid format']);
|
|
124
|
-
expect((0, _.createValueValidation)({
|
|
125
|
-
type: 'regex',
|
|
126
|
-
regex: /[^0-9]/i
|
|
127
|
-
})('123 ')).toEqual(['Invalid format']);
|
|
128
|
-
expect((0, _.createValueValidation)({
|
|
129
|
-
type: 'regex',
|
|
130
|
-
regex: /[^0-9]/i
|
|
131
|
-
})(1)).toEqual(undefined);
|
|
132
|
-
expect((0, _.createValueValidation)({
|
|
133
|
-
type: 'regex',
|
|
134
|
-
regex: /[^0-9]/i,
|
|
135
|
-
getMessage: to => 'test'
|
|
136
|
-
})('1234a')).toEqual(['test']);
|
|
137
|
-
expect((0, _.createValueValidation)({
|
|
138
|
-
type: 'regex',
|
|
139
|
-
regex: /[^0-9]/i
|
|
140
|
-
})('123')).toEqual(undefined);
|
|
141
|
-
});
|
|
142
|
-
it('supports maxLength', () => {
|
|
143
|
-
expect((0, _.createValueValidation)({
|
|
144
|
-
type: 'maxLength',
|
|
145
|
-
max: 3
|
|
146
|
-
})('1234')).toEqual(['Maximum number of characters - 3']);
|
|
147
|
-
expect((0, _.createValueValidation)({
|
|
148
|
-
type: 'maxLength',
|
|
149
|
-
max: 3,
|
|
150
|
-
getMessage: max => max
|
|
151
|
-
})('1234')).toEqual(['3']);
|
|
152
|
-
expect((0, _.createValueValidation)({
|
|
153
|
-
type: 'maxLength',
|
|
154
|
-
max: 3,
|
|
155
|
-
getMessage: max => max
|
|
156
|
-
})('123')).toEqual(undefined);
|
|
157
|
-
expect((0, _.createValueValidation)({
|
|
158
|
-
type: 'maxLength',
|
|
159
|
-
max: 3,
|
|
160
|
-
getMessage: max => max
|
|
161
|
-
})('12')).toEqual(undefined);
|
|
162
|
-
});
|
|
163
|
-
it('supports minLength', () => {
|
|
164
|
-
expect((0, _.createValueValidation)({
|
|
165
|
-
type: 'minLength',
|
|
166
|
-
min: 3,
|
|
167
|
-
getMessage: min => min
|
|
168
|
-
})('1234')).toEqual(undefined);
|
|
169
|
-
expect((0, _.createValueValidation)({
|
|
170
|
-
type: 'minLength',
|
|
171
|
-
min: 3,
|
|
172
|
-
getMessage: min => min
|
|
173
|
-
})('123')).toEqual(undefined);
|
|
174
|
-
expect((0, _.createValueValidation)({
|
|
175
|
-
type: 'minLength',
|
|
176
|
-
min: 3,
|
|
177
|
-
getMessage: min => min
|
|
178
|
-
})('12')).toEqual(['3']);
|
|
179
|
-
expect((0, _.createValueValidation)({
|
|
180
|
-
type: 'minLength',
|
|
181
|
-
min: 3
|
|
182
|
-
})('12')).toEqual(['Minimum number of characters - 3']);
|
|
183
|
-
});
|
|
184
|
-
it('supports number', () => {
|
|
185
|
-
expect((0, _.createValueValidation)({
|
|
186
|
-
type: 'number',
|
|
187
|
-
getMessage: () => 'Number'
|
|
188
|
-
})('1234')).toEqual(undefined);
|
|
189
|
-
expect((0, _.createValueValidation)({
|
|
190
|
-
type: 'number',
|
|
191
|
-
getMessage: () => 'Number'
|
|
192
|
-
})(123)).toEqual(undefined);
|
|
193
|
-
expect((0, _.createValueValidation)({
|
|
194
|
-
type: 'number',
|
|
195
|
-
getMessage: () => 'Number'
|
|
196
|
-
})('12x')).toEqual(['Number']);
|
|
197
|
-
expect((0, _.createValueValidation)({
|
|
198
|
-
type: 'number'
|
|
199
|
-
})('12x')).toEqual(['Must be a number']);
|
|
200
|
-
});
|
|
201
|
-
it('supports string', () => {
|
|
202
|
-
expect((0, _.createValueValidation)({
|
|
203
|
-
type: 'string',
|
|
204
|
-
getMessage: () => 'String'
|
|
205
|
-
})('1234')).toEqual(undefined);
|
|
206
|
-
expect((0, _.createValueValidation)({
|
|
207
|
-
type: 'string',
|
|
208
|
-
getMessage: () => 'String'
|
|
209
|
-
})('o ya !')).toEqual(undefined);
|
|
210
|
-
expect((0, _.createValueValidation)({
|
|
211
|
-
type: 'string',
|
|
212
|
-
getMessage: () => 'String'
|
|
213
|
-
})(12)).toEqual(['String']);
|
|
214
|
-
expect((0, _.createValueValidation)({
|
|
215
|
-
type: 'string'
|
|
216
|
-
})(true)).toEqual(['Must be a string']);
|
|
217
|
-
});
|
|
218
|
-
it('supports boolean', () => {
|
|
219
|
-
expect((0, _.createValueValidation)({
|
|
220
|
-
type: 'boolean',
|
|
221
|
-
getMessage: () => 'Boolean'
|
|
222
|
-
})(true)).toEqual(undefined);
|
|
223
|
-
expect((0, _.createValueValidation)({
|
|
224
|
-
type: 'boolean',
|
|
225
|
-
getMessage: () => 'Boolean'
|
|
226
|
-
})(false)).toEqual(undefined);
|
|
227
|
-
expect((0, _.createValueValidation)({
|
|
228
|
-
type: 'boolean',
|
|
229
|
-
getMessage: () => 'Boolean'
|
|
230
|
-
})('truec')).toEqual(['Boolean']);
|
|
231
|
-
expect((0, _.createValueValidation)({
|
|
232
|
-
type: 'boolean'
|
|
233
|
-
})('truec')).toEqual(['Must be a boolean']);
|
|
234
|
-
});
|
|
235
|
-
it('supports email', () => {
|
|
236
|
-
expect((0, _.createValueValidation)({
|
|
237
|
-
type: 'email',
|
|
238
|
-
getMessage: () => 'Wrong email'
|
|
239
|
-
})('test@test.com')).toEqual(undefined);
|
|
240
|
-
expect((0, _.createValueValidation)({
|
|
241
|
-
type: 'email',
|
|
242
|
-
getMessage: () => 'Wrong email'
|
|
243
|
-
})('email')).toEqual(['Wrong email']);
|
|
244
|
-
expect((0, _.createValueValidation)({
|
|
245
|
-
type: 'email',
|
|
246
|
-
getMessage: () => 'Wrong email'
|
|
247
|
-
})('email@')).toEqual(['Wrong email']);
|
|
248
|
-
expect((0, _.createValueValidation)({
|
|
249
|
-
type: 'email',
|
|
250
|
-
getMessage: () => 'Wrong email'
|
|
251
|
-
})('email@.com')).toEqual(['Wrong email']);
|
|
252
|
-
expect((0, _.createValueValidation)({
|
|
253
|
-
type: 'email'
|
|
254
|
-
})('email@.com')).toEqual(['Invalid email format']);
|
|
255
|
-
});
|
|
256
|
-
it('supports alphanumeric', () => {
|
|
257
|
-
expect((0, _.createValueValidation)({
|
|
258
|
-
type: 'alphanumeric',
|
|
259
|
-
getMessage: () => 'alphanumeric'
|
|
260
|
-
})('te123Aa')).toEqual(undefined);
|
|
261
|
-
expect((0, _.createValueValidation)({
|
|
262
|
-
type: 'alphanumeric',
|
|
263
|
-
getMessage: () => 'alphanumeric'
|
|
264
|
-
})('asd_')).toEqual(['alphanumeric']);
|
|
265
|
-
expect((0, _.createValueValidation)({
|
|
266
|
-
type: 'alphanumeric'
|
|
267
|
-
})('Aa 1')).toEqual(['Only alphanumeric characters']);
|
|
268
|
-
});
|
|
269
|
-
it('supports alphanumeric', () => {
|
|
270
|
-
expect((0, _.createValueValidation)({
|
|
271
|
-
type: 'alphanumeric',
|
|
272
|
-
getMessage: () => 'alphanumeric'
|
|
273
|
-
})('te123Aa')).toEqual(undefined);
|
|
274
|
-
expect((0, _.createValueValidation)({
|
|
275
|
-
type: 'alphanumeric',
|
|
276
|
-
getMessage: () => 'alphanumeric'
|
|
277
|
-
})('asd_')).toEqual(['alphanumeric']);
|
|
278
|
-
expect((0, _.createValueValidation)({
|
|
279
|
-
type: 'alphanumeric'
|
|
280
|
-
})('Aa 1')).toEqual(['Only alphanumeric characters']);
|
|
281
|
-
});
|
|
282
|
-
it('supports oneOf', () => {
|
|
283
|
-
expect((0, _.createValueValidation)({
|
|
284
|
-
type: 'oneOf',
|
|
285
|
-
validators: [{
|
|
286
|
-
type: 'equals',
|
|
287
|
-
to: 1,
|
|
288
|
-
getMessage: to => to
|
|
289
|
-
}, {
|
|
290
|
-
type: 'equals',
|
|
291
|
-
to: 2,
|
|
292
|
-
getMessage: to => to
|
|
293
|
-
}]
|
|
294
|
-
})('3')).toEqual(['1', '2']);
|
|
295
|
-
expect((0, _.createValueValidation)({
|
|
296
|
-
type: 'oneOf',
|
|
297
|
-
validators: [{
|
|
298
|
-
type: 'equals',
|
|
299
|
-
to: 1,
|
|
300
|
-
getMessage: to => to
|
|
301
|
-
}, {
|
|
302
|
-
type: 'equals',
|
|
303
|
-
to: 2,
|
|
304
|
-
getMessage: to => to
|
|
305
|
-
}]
|
|
306
|
-
})(1)).toEqual(undefined);
|
|
307
|
-
expect((0, _.createValueValidation)({
|
|
308
|
-
type: 'oneOf',
|
|
309
|
-
validators: [{
|
|
310
|
-
type: 'number',
|
|
311
|
-
getMessage: () => 'Number'
|
|
312
|
-
}, {
|
|
313
|
-
type: 'email',
|
|
314
|
-
getMessage: () => 'Email'
|
|
315
|
-
}]
|
|
316
|
-
})('xz')).toEqual(['Number', 'Email']);
|
|
317
|
-
expect((0, _.createValueValidation)({
|
|
318
|
-
type: 'oneOf',
|
|
319
|
-
validators: [{
|
|
320
|
-
type: 'number',
|
|
321
|
-
getMessage: () => 'Number'
|
|
322
|
-
}, {
|
|
323
|
-
type: 'email',
|
|
324
|
-
getMessage: () => 'Email'
|
|
325
|
-
}]
|
|
326
|
-
})('123')).toEqual(undefined);
|
|
327
|
-
expect((0, _.createValueValidation)({
|
|
328
|
-
type: 'oneOf',
|
|
329
|
-
validators: [{
|
|
330
|
-
type: 'number',
|
|
331
|
-
getMessage: () => 'Number'
|
|
332
|
-
}, {
|
|
333
|
-
type: 'email',
|
|
334
|
-
getMessage: () => 'Email'
|
|
335
|
-
}]
|
|
336
|
-
})('test@test.com')).toEqual(undefined);
|
|
337
|
-
});
|
|
338
|
-
it('supports all', () => {
|
|
339
|
-
expect((0, _.createValueValidation)({
|
|
340
|
-
type: 'all',
|
|
341
|
-
validators: [{
|
|
342
|
-
type: 'number',
|
|
343
|
-
getMessage: () => 'Number'
|
|
344
|
-
}, {
|
|
345
|
-
type: 'maxLength',
|
|
346
|
-
max: 1,
|
|
347
|
-
getMessage: () => 'MaxLength'
|
|
348
|
-
}]
|
|
349
|
-
})('xz')).toEqual(['Number', 'MaxLength']);
|
|
350
|
-
expect((0, _.createValueValidation)({
|
|
351
|
-
type: 'all',
|
|
352
|
-
validators: [{
|
|
353
|
-
type: 'number',
|
|
354
|
-
getMessage: () => 'Number'
|
|
355
|
-
}, {
|
|
356
|
-
type: 'maxLength',
|
|
357
|
-
max: 1,
|
|
358
|
-
getMessage: () => 'MaxLength'
|
|
359
|
-
}]
|
|
360
|
-
})('12')).toEqual(['MaxLength']);
|
|
361
|
-
expect((0, _.createValueValidation)({
|
|
362
|
-
type: 'all',
|
|
363
|
-
validators: [{
|
|
364
|
-
type: 'number',
|
|
365
|
-
getMessage: () => 'Number'
|
|
366
|
-
}, {
|
|
367
|
-
type: 'maxLength',
|
|
368
|
-
max: 1,
|
|
369
|
-
getMessage: () => 'MaxLength'
|
|
370
|
-
}]
|
|
371
|
-
})('x')).toEqual(['Number']);
|
|
372
|
-
expect((0, _.createValueValidation)({
|
|
373
|
-
type: 'all',
|
|
374
|
-
validators: [{
|
|
375
|
-
type: 'number',
|
|
376
|
-
getMessage: () => 'Number'
|
|
377
|
-
}, {
|
|
378
|
-
type: 'maxLength',
|
|
379
|
-
max: 1,
|
|
380
|
-
getMessage: () => 'MaxLength'
|
|
381
|
-
}]
|
|
382
|
-
})('1')).toEqual(undefined);
|
|
383
|
-
});
|
|
384
|
-
it('supports nesting of all/oneOf', () => {
|
|
385
|
-
expect((0, _.createValueValidation)({
|
|
386
|
-
type: 'all',
|
|
387
|
-
validators: [{
|
|
388
|
-
type: 'oneOf',
|
|
389
|
-
validators: [{
|
|
390
|
-
type: 'number',
|
|
391
|
-
getMessage: () => 'Number'
|
|
392
|
-
}, {
|
|
393
|
-
type: 'email',
|
|
394
|
-
getMessage: () => 'Email'
|
|
395
|
-
}]
|
|
396
|
-
}, {
|
|
397
|
-
type: 'maxLength',
|
|
398
|
-
max: 1,
|
|
399
|
-
getMessage: () => 'MaxLength'
|
|
400
|
-
}]
|
|
401
|
-
})('xz')).toEqual(['Number', 'Email', 'MaxLength']);
|
|
402
|
-
expect((0, _.createValueValidation)({
|
|
403
|
-
type: 'all',
|
|
404
|
-
validators: [{
|
|
405
|
-
type: 'oneOf',
|
|
406
|
-
validators: [{
|
|
407
|
-
type: 'number',
|
|
408
|
-
getMessage: () => 'Number'
|
|
409
|
-
}, {
|
|
410
|
-
type: 'email',
|
|
411
|
-
getMessage: () => 'Email'
|
|
412
|
-
}]
|
|
413
|
-
}, {
|
|
414
|
-
type: 'maxLength',
|
|
415
|
-
max: 15,
|
|
416
|
-
getMessage: () => 'MaxLength'
|
|
417
|
-
}]
|
|
418
|
-
})('test@test.com')).toEqual(undefined);
|
|
419
|
-
});
|
|
420
|
-
it('can handle login validation', () => {
|
|
421
|
-
const loginValidation = (0, _.createValueValidation)({
|
|
422
|
-
type: 'all',
|
|
423
|
-
validators: [{
|
|
424
|
-
type: 'required',
|
|
425
|
-
getMessage: () => 'Required'
|
|
426
|
-
}, {
|
|
427
|
-
type: 'oneOf',
|
|
428
|
-
validators: [{
|
|
429
|
-
type: 'all',
|
|
430
|
-
validators: [{
|
|
431
|
-
type: 'alphanumeric',
|
|
432
|
-
getMessage: () => 'AlphaNumeric'
|
|
433
|
-
}, {
|
|
434
|
-
type: 'minLength',
|
|
435
|
-
min: 3,
|
|
436
|
-
getMessage: () => '{min}'
|
|
437
|
-
}]
|
|
438
|
-
}, {
|
|
439
|
-
type: 'email',
|
|
440
|
-
getMessage: () => 'Email'
|
|
441
|
-
}]
|
|
442
|
-
}]
|
|
443
|
-
});
|
|
444
|
-
expect(loginValidation('')).toEqual(['Required']);
|
|
445
|
-
expect(loginValidation('aa')).toEqual(['3', 'Email']);
|
|
446
|
-
expect(loginValidation('aa3')).toEqual(undefined);
|
|
447
|
-
});
|
|
448
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _operators = require("../operators");
|
|
4
|
-
|
|
5
|
-
describe('oneOf', () => {
|
|
6
|
-
it('returns undefined for empty', () => {
|
|
7
|
-
expect((0, _operators.oneOf)()()).toEqual(undefined);
|
|
8
|
-
});
|
|
9
|
-
it('returns returns undefined when 1 is passed', () => {
|
|
10
|
-
expect((0, _operators.oneOf)(() => ['x'], () => undefined)()).toEqual(undefined);
|
|
11
|
-
expect((0, _operators.oneOf)(() => undefined, () => ['x'])()).toEqual(undefined);
|
|
12
|
-
expect((0, _operators.oneOf)(() => ['x'], () => undefined, () => ['x'])()).toEqual(undefined);
|
|
13
|
-
});
|
|
14
|
-
it('returns all errors when nothing passed', () => {
|
|
15
|
-
expect((0, _operators.oneOf)(() => ['x'], () => ['y'])()).toEqual(['x', 'y']);
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
describe('all', () => {
|
|
19
|
-
it('returns undefined for empty', () => {
|
|
20
|
-
expect((0, _operators.all)()()).toEqual(undefined);
|
|
21
|
-
});
|
|
22
|
-
it('returns all errors if something is not passed', () => {
|
|
23
|
-
expect((0, _operators.all)(() => 'x', () => undefined)()).toEqual(['x']);
|
|
24
|
-
expect((0, _operators.all)(() => undefined, () => 'x')()).toEqual(['x']);
|
|
25
|
-
expect((0, _operators.all)(() => 'x', () => undefined, () => 'x')()).toEqual(['x', 'x']);
|
|
26
|
-
expect((0, _operators.all)(() => 'x', () => 'x')()).toEqual(['x', 'x']);
|
|
27
|
-
});
|
|
28
|
-
});
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _operators = require("../operators");
|
|
4
|
-
|
|
5
|
-
describe('oneOf', () => {
|
|
6
|
-
it('throws error when no validators passed', () => {
|
|
7
|
-
expect(() => (0, _operators.oneOf)()()).toThrow(Error);
|
|
8
|
-
});
|
|
9
|
-
it('returns returns undefined when 1 is passed', () => {
|
|
10
|
-
expect((0, _operators.oneOf)(() => ({
|
|
11
|
-
data: undefined,
|
|
12
|
-
errors: ['x']
|
|
13
|
-
}), () => ({
|
|
14
|
-
data: 1,
|
|
15
|
-
errors: undefined
|
|
16
|
-
}))(1)).toEqual({
|
|
17
|
-
data: 1,
|
|
18
|
-
errors: undefined
|
|
19
|
-
});
|
|
20
|
-
expect((0, _operators.oneOf)(() => ({
|
|
21
|
-
data: 1,
|
|
22
|
-
errors: undefined
|
|
23
|
-
}), () => ({
|
|
24
|
-
data: undefined,
|
|
25
|
-
errors: ['x']
|
|
26
|
-
}))(1)).toEqual({
|
|
27
|
-
data: 1,
|
|
28
|
-
errors: undefined
|
|
29
|
-
});
|
|
30
|
-
expect((0, _operators.oneOf)(() => ({
|
|
31
|
-
data: undefined,
|
|
32
|
-
errors: ['x']
|
|
33
|
-
}), () => ({
|
|
34
|
-
data: 1,
|
|
35
|
-
errors: undefined
|
|
36
|
-
}), () => ({
|
|
37
|
-
data: undefined,
|
|
38
|
-
errors: ['x']
|
|
39
|
-
}))(1)).toEqual({
|
|
40
|
-
data: 1,
|
|
41
|
-
errors: undefined
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
it('returns all errors when nothing passed', () => {
|
|
45
|
-
expect((0, _operators.oneOf)(() => ({
|
|
46
|
-
data: undefined,
|
|
47
|
-
errors: ['x']
|
|
48
|
-
}), () => ({
|
|
49
|
-
data: undefined,
|
|
50
|
-
errors: ['y']
|
|
51
|
-
}))(1)).toEqual({
|
|
52
|
-
data: undefined,
|
|
53
|
-
errors: ['x', 'y']
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
describe('all', () => {
|
|
58
|
-
it('throws error when no validators passed', () => {
|
|
59
|
-
expect(() => (0, _operators.all)()()).toThrow(Error);
|
|
60
|
-
});
|
|
61
|
-
it('returns all errors if something is not passed', () => {
|
|
62
|
-
expect((0, _operators.all)(() => ({
|
|
63
|
-
data: undefined,
|
|
64
|
-
errors: ['x']
|
|
65
|
-
}), () => ({
|
|
66
|
-
data: 1,
|
|
67
|
-
errors: undefined
|
|
68
|
-
}))(1)).toEqual({
|
|
69
|
-
data: undefined,
|
|
70
|
-
errors: ['x']
|
|
71
|
-
});
|
|
72
|
-
expect((0, _operators.all)(() => ({
|
|
73
|
-
data: 1,
|
|
74
|
-
errors: undefined
|
|
75
|
-
}), () => ({
|
|
76
|
-
data: undefined,
|
|
77
|
-
errors: ['x']
|
|
78
|
-
}))(1)).toEqual({
|
|
79
|
-
data: undefined,
|
|
80
|
-
errors: ['x']
|
|
81
|
-
});
|
|
82
|
-
expect((0, _operators.all)(() => ({
|
|
83
|
-
data: undefined,
|
|
84
|
-
errors: ['x']
|
|
85
|
-
}), () => ({
|
|
86
|
-
data: 1,
|
|
87
|
-
errors: undefined
|
|
88
|
-
}), () => ({
|
|
89
|
-
data: undefined,
|
|
90
|
-
errors: ['x']
|
|
91
|
-
}))(1)).toEqual({
|
|
92
|
-
data: undefined,
|
|
93
|
-
errors: ['x', 'x']
|
|
94
|
-
});
|
|
95
|
-
expect((0, _operators.all)(() => ({
|
|
96
|
-
data: undefined,
|
|
97
|
-
errors: ['x']
|
|
98
|
-
}), () => ({
|
|
99
|
-
data: undefined,
|
|
100
|
-
errors: ['x']
|
|
101
|
-
}))(1)).toEqual({
|
|
102
|
-
data: undefined,
|
|
103
|
-
errors: ['x', 'x']
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
it('returns data if all valid', () => {
|
|
107
|
-
expect((0, _operators.all)(() => ({
|
|
108
|
-
data: 1,
|
|
109
|
-
errors: undefined
|
|
110
|
-
}))(1)).toEqual({
|
|
111
|
-
data: 1,
|
|
112
|
-
errors: undefined
|
|
113
|
-
});
|
|
114
|
-
expect((0, _operators.all)(() => ({
|
|
115
|
-
data: 1,
|
|
116
|
-
errors: undefined
|
|
117
|
-
}), () => ({
|
|
118
|
-
data: 1,
|
|
119
|
-
errors: undefined
|
|
120
|
-
}))(1)).toEqual({
|
|
121
|
-
data: 1,
|
|
122
|
-
errors: undefined
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
});
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _ = require(".");
|
|
9
|
-
|
|
10
|
-
var _default = rulesObject => {
|
|
11
|
-
const fieldValidations = Object.getOwnPropertyNames(rulesObject).map(ruleProp => ({
|
|
12
|
-
prop: ruleProp,
|
|
13
|
-
validation: (0, _.createValueValidation)(rulesObject[ruleProp])
|
|
14
|
-
}));
|
|
15
|
-
return object => {
|
|
16
|
-
const resultData = {};
|
|
17
|
-
const resultErrors = {};
|
|
18
|
-
fieldValidations.forEach(fv => {
|
|
19
|
-
const fieldValidationErrors = fv.validation(object[fv.prop], object);
|
|
20
|
-
|
|
21
|
-
if (fieldValidationErrors) {
|
|
22
|
-
resultErrors[fv.prop] = fieldValidationErrors;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
resultData[fv.prop] = object[fv.prop];
|
|
26
|
-
});
|
|
27
|
-
return {
|
|
28
|
-
data: resultData,
|
|
29
|
-
errors: Object.getOwnPropertyNames(resultErrors).length > 0 ? resultErrors : undefined
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
exports.default = _default;
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _validators = require("./validators");
|
|
9
|
-
|
|
10
|
-
var _operators = require("./operators");
|
|
11
|
-
|
|
12
|
-
const ruleProcessor = rule => {
|
|
13
|
-
switch (rule.type) {
|
|
14
|
-
case 'required':
|
|
15
|
-
return (0, _validators.required)(rule);
|
|
16
|
-
|
|
17
|
-
case 'equals':
|
|
18
|
-
return (0, _validators.equals)(rule);
|
|
19
|
-
|
|
20
|
-
case 'maxLength':
|
|
21
|
-
return (0, _validators.maxLength)(rule);
|
|
22
|
-
|
|
23
|
-
case 'minLength':
|
|
24
|
-
return (0, _validators.minLength)(rule);
|
|
25
|
-
|
|
26
|
-
case 'minValue':
|
|
27
|
-
return (0, _validators.minValue)(rule);
|
|
28
|
-
|
|
29
|
-
case 'maxValue':
|
|
30
|
-
return (0, _validators.maxValue)(rule);
|
|
31
|
-
|
|
32
|
-
case 'number':
|
|
33
|
-
return (0, _validators.number)(rule);
|
|
34
|
-
|
|
35
|
-
case 'boolean':
|
|
36
|
-
return (0, _validators.boolean)(rule);
|
|
37
|
-
|
|
38
|
-
case 'string':
|
|
39
|
-
return (0, _validators.string)(rule);
|
|
40
|
-
|
|
41
|
-
case 'email':
|
|
42
|
-
return (0, _validators.email)(rule);
|
|
43
|
-
|
|
44
|
-
case 'alphanumeric':
|
|
45
|
-
return (0, _validators.alphanumeric)(rule);
|
|
46
|
-
|
|
47
|
-
case 'equalsToField':
|
|
48
|
-
return (0, _validators.equalsToField)(rule);
|
|
49
|
-
|
|
50
|
-
case 'regex':
|
|
51
|
-
return (0, _validators.regex)(rule);
|
|
52
|
-
|
|
53
|
-
case 'oneOf':
|
|
54
|
-
return (0, _operators.oneOf)(...rule.validators.map(ruleProcessor));
|
|
55
|
-
|
|
56
|
-
case 'all':
|
|
57
|
-
return (0, _operators.all)(...rule.validators.map(ruleProcessor));
|
|
58
|
-
|
|
59
|
-
default:
|
|
60
|
-
throw new Error(`invalid validator type: {rule.type}`);
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
var _default = rule => {
|
|
65
|
-
const validator = ruleProcessor(rule);
|
|
66
|
-
return (value, allValues) => {
|
|
67
|
-
return validator(value, allValues);
|
|
68
|
-
};
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
exports.default = _default;
|