co.validation 1.0.0-RC.4 → 1.0.0-RC.7
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/__tests__/component.arrayValidation.js +14 -0
- package/lib/__tests__/component.valueValidation.js +13 -13
- package/lib/__tests__/integration.registrationForm.js +14 -2
- package/lib/createValidation.js +1 -1
- package/lib/operators.js +2 -0
- package/lib/validators.js +1 -1
- package/package.json +2 -2
|
@@ -71,6 +71,20 @@ describe('createValidation', () => {
|
|
|
71
71
|
}]);
|
|
72
72
|
expect(validationResult.data).toEqual([]);
|
|
73
73
|
});
|
|
74
|
+
it('list of numbers stays list of numbers', () => {
|
|
75
|
+
const validatedObject = [0, 1, 2];
|
|
76
|
+
const validationResult = (0, _.createValidation)({
|
|
77
|
+
type: 'array',
|
|
78
|
+
itemRule: {
|
|
79
|
+
type: 'all',
|
|
80
|
+
validators: [{
|
|
81
|
+
type: 'number'
|
|
82
|
+
}]
|
|
83
|
+
}
|
|
84
|
+
})(validatedObject);
|
|
85
|
+
expect(validationResult.errors).toEqual(undefined);
|
|
86
|
+
expect(validationResult.data).toEqual(validatedObject);
|
|
87
|
+
});
|
|
74
88
|
it('single valid item stays in data', () => {
|
|
75
89
|
const validatedObject = [{
|
|
76
90
|
login: 'hey'
|
|
@@ -563,8 +563,8 @@ describe('createValidation', () => {
|
|
|
563
563
|
expect((0, _.createValidation)({
|
|
564
564
|
type: 'all',
|
|
565
565
|
validators: [{
|
|
566
|
-
type: '
|
|
567
|
-
getMessage: () => '
|
|
566
|
+
type: 'email',
|
|
567
|
+
getMessage: () => 'Email'
|
|
568
568
|
}, {
|
|
569
569
|
type: 'maxLength',
|
|
570
570
|
max: 1,
|
|
@@ -572,7 +572,7 @@ describe('createValidation', () => {
|
|
|
572
572
|
}]
|
|
573
573
|
})('xz')).toEqual({
|
|
574
574
|
data: undefined,
|
|
575
|
-
errors: ['
|
|
575
|
+
errors: ['Email', 'MaxLength']
|
|
576
576
|
});
|
|
577
577
|
expect((0, _.createValidation)({
|
|
578
578
|
type: 'all',
|
|
@@ -580,19 +580,19 @@ describe('createValidation', () => {
|
|
|
580
580
|
type: 'number',
|
|
581
581
|
getMessage: () => 'Number'
|
|
582
582
|
}, {
|
|
583
|
-
type: '
|
|
584
|
-
max:
|
|
585
|
-
getMessage: () => '
|
|
583
|
+
type: 'maxValue',
|
|
584
|
+
max: 11,
|
|
585
|
+
getMessage: () => 'MaxValue'
|
|
586
586
|
}]
|
|
587
587
|
})('12')).toEqual({
|
|
588
588
|
data: undefined,
|
|
589
|
-
errors: ['
|
|
589
|
+
errors: ['MaxValue']
|
|
590
590
|
});
|
|
591
591
|
expect((0, _.createValidation)({
|
|
592
592
|
type: 'all',
|
|
593
593
|
validators: [{
|
|
594
|
-
type: '
|
|
595
|
-
getMessage: () => '
|
|
594
|
+
type: 'email',
|
|
595
|
+
getMessage: () => 'Email'
|
|
596
596
|
}, {
|
|
597
597
|
type: 'maxLength',
|
|
598
598
|
max: 1,
|
|
@@ -600,7 +600,7 @@ describe('createValidation', () => {
|
|
|
600
600
|
}]
|
|
601
601
|
})('x')).toEqual({
|
|
602
602
|
data: undefined,
|
|
603
|
-
errors: ['
|
|
603
|
+
errors: ['Email']
|
|
604
604
|
});
|
|
605
605
|
expect((0, _.createValidation)({
|
|
606
606
|
type: 'all',
|
|
@@ -608,12 +608,12 @@ describe('createValidation', () => {
|
|
|
608
608
|
type: 'number',
|
|
609
609
|
getMessage: () => 'Number'
|
|
610
610
|
}, {
|
|
611
|
-
type: '
|
|
611
|
+
type: 'maxValue',
|
|
612
612
|
max: 1,
|
|
613
|
-
getMessage: () => '
|
|
613
|
+
getMessage: () => 'MaxValue'
|
|
614
614
|
}]
|
|
615
615
|
})('1')).toEqual({
|
|
616
|
-
data:
|
|
616
|
+
data: 1,
|
|
617
617
|
errors: undefined
|
|
618
618
|
});
|
|
619
619
|
});
|
|
@@ -37,6 +37,14 @@ const registrationFormValidation = (0, _.createValidation)({
|
|
|
37
37
|
type: 'email'
|
|
38
38
|
}]
|
|
39
39
|
},
|
|
40
|
+
age: {
|
|
41
|
+
type: 'all',
|
|
42
|
+
validators: [{
|
|
43
|
+
type: 'required'
|
|
44
|
+
}, {
|
|
45
|
+
type: 'number'
|
|
46
|
+
}]
|
|
47
|
+
},
|
|
40
48
|
hobbies: {
|
|
41
49
|
type: 'array',
|
|
42
50
|
itemRule: {
|
|
@@ -82,7 +90,8 @@ describe('registrationFormValidation', () => {
|
|
|
82
90
|
expect(validationResult.errors).toEqual({
|
|
83
91
|
firstName: ['Required'],
|
|
84
92
|
lastName: ['Required'],
|
|
85
|
-
email: ['Required']
|
|
93
|
+
email: ['Required'],
|
|
94
|
+
age: ['Required']
|
|
86
95
|
});
|
|
87
96
|
expect(validationResult.data).toEqual(undefined);
|
|
88
97
|
});
|
|
@@ -94,7 +103,8 @@ describe('registrationFormValidation', () => {
|
|
|
94
103
|
expect(validationResult.errors).toEqual({
|
|
95
104
|
firstName: ['Required'],
|
|
96
105
|
lastName: ['Required'],
|
|
97
|
-
email: ['Required']
|
|
106
|
+
email: ['Required'],
|
|
107
|
+
age: ['Required']
|
|
98
108
|
});
|
|
99
109
|
expect(validationResult.data).toEqual(validatedObject);
|
|
100
110
|
});
|
|
@@ -125,6 +135,7 @@ describe('registrationFormValidation', () => {
|
|
|
125
135
|
firstName: 'firstName',
|
|
126
136
|
lastName: 'lastName',
|
|
127
137
|
email: 'test@mail.com',
|
|
138
|
+
age: '12',
|
|
128
139
|
hobbies: [1, {
|
|
129
140
|
title: 'title'
|
|
130
141
|
}, {
|
|
@@ -166,6 +177,7 @@ describe('registrationFormValidation', () => {
|
|
|
166
177
|
firstName: 'firstName',
|
|
167
178
|
lastName: 'lastName',
|
|
168
179
|
email: 'test@mail.com',
|
|
180
|
+
age: 12,
|
|
169
181
|
hobbies: [{
|
|
170
182
|
title: 'title'
|
|
171
183
|
}, {
|
package/lib/createValidation.js
CHANGED
package/lib/operators.js
CHANGED
package/lib/validators.js
CHANGED
|
@@ -59,7 +59,7 @@ const number = ({
|
|
|
59
59
|
}) => value => value && isNaN(Number(value)) ? {
|
|
60
60
|
errors: (0, _messageProcessor.default)(getMessage, 'Must be a number')
|
|
61
61
|
} : {
|
|
62
|
-
data: Number(value)
|
|
62
|
+
data: value === null || value === undefined ? value : Number(value)
|
|
63
63
|
};
|
|
64
64
|
|
|
65
65
|
exports.number = number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "co.validation",
|
|
3
|
-
"version": "1.0.0-RC.
|
|
3
|
+
"version": "1.0.0-RC.7",
|
|
4
4
|
"description": "JSON based fluent validation for browser, node.js, redux-form and anything javascript compatible.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"keywords": [
|
|
12
12
|
"validation"
|
|
13
13
|
],
|
|
14
|
-
"author": "
|
|
14
|
+
"author": "Collaboracia OÜ",
|
|
15
15
|
"license": "ISC",
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"@babel/cli": "^7.4.4",
|