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,201 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _ = require("..");
|
|
4
|
-
|
|
5
|
-
describe('createValidation', () => {
|
|
6
|
-
it('supports not an array check', () => {
|
|
7
|
-
expect((0, _.createValidation)({
|
|
8
|
-
type: 'array',
|
|
9
|
-
itemRule: {
|
|
10
|
-
type: 'required'
|
|
11
|
-
}
|
|
12
|
-
})(undefined)).toEqual({
|
|
13
|
-
data: undefined,
|
|
14
|
-
errors: undefined
|
|
15
|
-
});
|
|
16
|
-
expect((0, _.createValidation)({
|
|
17
|
-
type: 'array',
|
|
18
|
-
itemRule: {
|
|
19
|
-
type: 'required'
|
|
20
|
-
}
|
|
21
|
-
})(null)).toEqual({
|
|
22
|
-
data: null,
|
|
23
|
-
errors: undefined
|
|
24
|
-
});
|
|
25
|
-
expect((0, _.createValidation)({
|
|
26
|
-
type: 'array',
|
|
27
|
-
itemRule: {
|
|
28
|
-
type: 'required'
|
|
29
|
-
}
|
|
30
|
-
})('')).toEqual({
|
|
31
|
-
data: undefined,
|
|
32
|
-
errors: ['Must be an array']
|
|
33
|
-
});
|
|
34
|
-
expect((0, _.createValidation)({
|
|
35
|
-
type: 'array',
|
|
36
|
-
itemRule: {
|
|
37
|
-
type: 'required'
|
|
38
|
-
}
|
|
39
|
-
})(1)).toEqual({
|
|
40
|
-
data: undefined,
|
|
41
|
-
errors: ['Must be an array']
|
|
42
|
-
});
|
|
43
|
-
expect((0, _.createValidation)({
|
|
44
|
-
type: 'array',
|
|
45
|
-
itemRule: {
|
|
46
|
-
type: 'required'
|
|
47
|
-
},
|
|
48
|
-
getMessage: obj => obj
|
|
49
|
-
})('test')).toEqual({
|
|
50
|
-
data: undefined,
|
|
51
|
-
errors: ['test']
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
it('check that array has some item', () => {
|
|
55
|
-
expect((0, _.createValidation)({
|
|
56
|
-
type: 'requiredArrayWithItem'
|
|
57
|
-
})(undefined)).toEqual({
|
|
58
|
-
data: undefined,
|
|
59
|
-
errors: ['Must be an array']
|
|
60
|
-
});
|
|
61
|
-
expect((0, _.createValidation)({
|
|
62
|
-
type: 'requiredArrayWithItem'
|
|
63
|
-
})([1])).toEqual({
|
|
64
|
-
data: [1],
|
|
65
|
-
errors: undefined
|
|
66
|
-
});
|
|
67
|
-
expect((0, _.createValidation)({
|
|
68
|
-
type: 'requiredArrayWithItem'
|
|
69
|
-
})([])).toEqual({
|
|
70
|
-
data: undefined,
|
|
71
|
-
errors: ['Required']
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
it('single invalid item creates error', () => {
|
|
75
|
-
const validatedObject = [{
|
|
76
|
-
login: ''
|
|
77
|
-
}];
|
|
78
|
-
const validationResult = (0, _.createValidation)({
|
|
79
|
-
type: 'array',
|
|
80
|
-
itemRule: {
|
|
81
|
-
type: 'object',
|
|
82
|
-
rules: {
|
|
83
|
-
login: {
|
|
84
|
-
type: 'required'
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
})(validatedObject);
|
|
89
|
-
expect(validationResult.errors).toEqual([{
|
|
90
|
-
login: ['Required']
|
|
91
|
-
}]);
|
|
92
|
-
expect(validationResult.data).toEqual([]);
|
|
93
|
-
});
|
|
94
|
-
it('list of numbers stays list of numbers', () => {
|
|
95
|
-
const validatedObject = [0, 1, 2];
|
|
96
|
-
const validationResult = (0, _.createValidation)({
|
|
97
|
-
type: 'array',
|
|
98
|
-
itemRule: {
|
|
99
|
-
type: 'all',
|
|
100
|
-
validators: [{
|
|
101
|
-
type: 'number'
|
|
102
|
-
}]
|
|
103
|
-
}
|
|
104
|
-
})(validatedObject);
|
|
105
|
-
expect(validationResult.errors).toEqual(undefined);
|
|
106
|
-
expect(validationResult.data).toEqual(validatedObject);
|
|
107
|
-
});
|
|
108
|
-
it('single valid item stays in data', () => {
|
|
109
|
-
const validatedObject = [{
|
|
110
|
-
login: 'hey'
|
|
111
|
-
}];
|
|
112
|
-
const validationResult = (0, _.createValidation)({
|
|
113
|
-
type: 'array',
|
|
114
|
-
itemRule: {
|
|
115
|
-
type: 'object',
|
|
116
|
-
rules: {
|
|
117
|
-
login: {
|
|
118
|
-
type: 'required'
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
})(validatedObject);
|
|
123
|
-
expect(validationResult.errors).toEqual(undefined);
|
|
124
|
-
expect(validationResult.data).toEqual(validatedObject);
|
|
125
|
-
});
|
|
126
|
-
it('single valid item stays in data and single invalid creates error', () => {
|
|
127
|
-
const validatedObject = [{
|
|
128
|
-
login: 'hey'
|
|
129
|
-
}, {
|
|
130
|
-
login: ''
|
|
131
|
-
}];
|
|
132
|
-
const validationResult = (0, _.createValidation)({
|
|
133
|
-
type: 'array',
|
|
134
|
-
itemRule: {
|
|
135
|
-
type: 'object',
|
|
136
|
-
rules: {
|
|
137
|
-
login: {
|
|
138
|
-
type: 'required'
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
})(validatedObject);
|
|
143
|
-
expect(validationResult.errors).toEqual([null, {
|
|
144
|
-
login: ['Required']
|
|
145
|
-
}]);
|
|
146
|
-
expect(validationResult.data).toEqual([validatedObject[0]]);
|
|
147
|
-
});
|
|
148
|
-
const arrayWithInnerObjectValidation = (0, _.createValidation)({
|
|
149
|
-
type: 'array',
|
|
150
|
-
itemRule: {
|
|
151
|
-
type: 'object',
|
|
152
|
-
rules: {
|
|
153
|
-
name: {
|
|
154
|
-
type: 'required'
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
it('supports inner objects inside array', () => {
|
|
160
|
-
const validatedObject = [{
|
|
161
|
-
name: '123'
|
|
162
|
-
}, {
|
|
163
|
-
name: '123'
|
|
164
|
-
}];
|
|
165
|
-
const validationResult = arrayWithInnerObjectValidation(validatedObject);
|
|
166
|
-
expect(validationResult.errors).toEqual(undefined);
|
|
167
|
-
expect(validationResult.data).toEqual(validatedObject);
|
|
168
|
-
});
|
|
169
|
-
it('supports errors + filtering of inner objects inside array', () => {
|
|
170
|
-
const validatedObject = [{
|
|
171
|
-
name: '123'
|
|
172
|
-
}, {
|
|
173
|
-
name: null
|
|
174
|
-
}, {
|
|
175
|
-
name: '123'
|
|
176
|
-
}];
|
|
177
|
-
const validationResult = arrayWithInnerObjectValidation(validatedObject);
|
|
178
|
-
expect(validationResult.errors).toEqual([null, {
|
|
179
|
-
name: ['Required']
|
|
180
|
-
}, null]);
|
|
181
|
-
expect(validationResult.data).toEqual([validatedObject[0], validatedObject[2]]);
|
|
182
|
-
});
|
|
183
|
-
const arrayWithInnerValuesValidation = (0, _.createValidation)({
|
|
184
|
-
type: 'array',
|
|
185
|
-
itemRule: {
|
|
186
|
-
type: 'required'
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
it('supports inner values inside array', () => {
|
|
190
|
-
const validatedObject = ['123', '456'];
|
|
191
|
-
const validationResult = arrayWithInnerValuesValidation(validatedObject);
|
|
192
|
-
expect(validationResult.errors).toEqual(undefined);
|
|
193
|
-
expect(validationResult.data).toEqual(validatedObject);
|
|
194
|
-
});
|
|
195
|
-
it('supports errors + filtering of inner values inside array', () => {
|
|
196
|
-
const validatedObject = ['123', null, '456'];
|
|
197
|
-
const validationResult = arrayWithInnerValuesValidation(validatedObject);
|
|
198
|
-
expect(validationResult.errors).toEqual([null, ['Required'], null]);
|
|
199
|
-
expect(validationResult.data).toEqual([validatedObject[0], validatedObject[2]]);
|
|
200
|
-
});
|
|
201
|
-
});
|