@e22m4u/js-repository 0.1.5 → 0.1.6
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/README.md +4 -4
- package/docs/assets/search.js +1 -1
- package/docs/classes/ModelDataValidator.html +2 -2
- package/docs/index.html +4 -4
- package/docs/types/PropertyValidateOptions.html +1 -1
- package/docs/types/PropertyValidator.html +2 -2
- package/docs/types/PropertyValidatorContext.html +2 -2
- package/package.json +1 -1
- package/src/adapter/decorator/data-validation-decorator.js +10 -18
- package/src/adapter/decorator/data-validation-decorator.spec.js +0 -40
- package/src/definition/model/model-data-validator.d.ts +1 -5
- package/src/definition/model/model-data-validator.js +42 -42
- package/src/definition/model/model-data-validator.spec.js +661 -709
- package/src/definition/model/properties/property-validator/property-validator.d.ts +1 -6
|
@@ -7,40 +7,36 @@ import {PropertyValidatorRegistry} from './properties/index.js';
|
|
|
7
7
|
|
|
8
8
|
describe('ModelDataValidator', function () {
|
|
9
9
|
describe('validate', function () {
|
|
10
|
-
it('does not throw an error if a model does not have a property of a given data',
|
|
10
|
+
it('does not throw an error if a model does not have a property of a given data', function () {
|
|
11
11
|
const schema = new Schema();
|
|
12
12
|
schema.defineModel({name: 'model'});
|
|
13
|
-
|
|
14
|
-
.getService(ModelDataValidator)
|
|
15
|
-
.validate('model', {foo: 'bar'});
|
|
13
|
+
schema.getService(ModelDataValidator).validate('model', {foo: 'bar'});
|
|
16
14
|
});
|
|
17
15
|
|
|
18
|
-
it('throws an error if a given data is not a pure object',
|
|
19
|
-
const throwable = modelData => {
|
|
16
|
+
it('throws an error if a given data is not a pure object', function () {
|
|
17
|
+
const throwable = modelData => () => {
|
|
20
18
|
const schema = new Schema();
|
|
21
19
|
schema.defineModel({
|
|
22
20
|
name: 'model',
|
|
23
21
|
datasource: 'datasource',
|
|
24
22
|
});
|
|
25
|
-
|
|
26
|
-
.getService(ModelDataValidator)
|
|
27
|
-
.validate('model', modelData);
|
|
23
|
+
schema.getService(ModelDataValidator).validate('model', modelData);
|
|
28
24
|
};
|
|
29
|
-
const error =
|
|
25
|
+
const error = v =>
|
|
30
26
|
format(
|
|
31
27
|
'The data of the model "model" should be an Object, but %s given.',
|
|
32
|
-
|
|
28
|
+
v,
|
|
33
29
|
);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
30
|
+
expect(throwable('str')).to.throw(error('"str"'));
|
|
31
|
+
expect(throwable(10)).to.throw(error('10'));
|
|
32
|
+
expect(throwable(true)).to.throw(error('true'));
|
|
33
|
+
expect(throwable(false)).to.throw(error('false'));
|
|
34
|
+
expect(throwable([])).to.throw(error('Array'));
|
|
35
|
+
expect(throwable(null)).to.throw(error('null'));
|
|
36
|
+
expect(throwable(undefined)).to.throw(error('undefined'));
|
|
41
37
|
});
|
|
42
38
|
|
|
43
|
-
it('uses a base model hierarchy to validate a given data',
|
|
39
|
+
it('uses a base model hierarchy to validate a given data', function () {
|
|
44
40
|
const schema = new Schema();
|
|
45
41
|
schema.defineModel({
|
|
46
42
|
name: 'modelA',
|
|
@@ -52,16 +48,15 @@ describe('ModelDataValidator', function () {
|
|
|
52
48
|
name: 'modelB',
|
|
53
49
|
base: 'modelA',
|
|
54
50
|
});
|
|
55
|
-
const
|
|
56
|
-
.getService(ModelDataValidator)
|
|
57
|
-
|
|
58
|
-
await expect(promise).to.be.rejectedWith(
|
|
51
|
+
const throwable = () =>
|
|
52
|
+
schema.getService(ModelDataValidator).validate('modelB', {foo: 10});
|
|
53
|
+
expect(throwable).to.throw(
|
|
59
54
|
'The property "foo" of the model "modelB" must ' +
|
|
60
55
|
'have a String, but Number given.',
|
|
61
56
|
);
|
|
62
57
|
});
|
|
63
58
|
|
|
64
|
-
it('throws an error if a given data does not have a required property',
|
|
59
|
+
it('throws an error if a given data does not have a required property', function () {
|
|
65
60
|
const schema = new Schema();
|
|
66
61
|
schema.defineModel({
|
|
67
62
|
name: 'model',
|
|
@@ -72,16 +67,15 @@ describe('ModelDataValidator', function () {
|
|
|
72
67
|
},
|
|
73
68
|
},
|
|
74
69
|
});
|
|
75
|
-
const
|
|
76
|
-
.getService(ModelDataValidator)
|
|
77
|
-
|
|
78
|
-
await expect(promise).to.be.rejectedWith(
|
|
70
|
+
const throwable = () =>
|
|
71
|
+
schema.getService(ModelDataValidator).validate('model', {});
|
|
72
|
+
expect(throwable).to.throw(
|
|
79
73
|
'The property "foo" of the model "model" ' +
|
|
80
74
|
'is required, but undefined given.',
|
|
81
75
|
);
|
|
82
76
|
});
|
|
83
77
|
|
|
84
|
-
it('throws an error if a required property is undefined',
|
|
78
|
+
it('throws an error if a required property is undefined', function () {
|
|
85
79
|
const schema = new Schema();
|
|
86
80
|
schema.defineModel({
|
|
87
81
|
name: 'model',
|
|
@@ -92,15 +86,16 @@ describe('ModelDataValidator', function () {
|
|
|
92
86
|
},
|
|
93
87
|
},
|
|
94
88
|
});
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
89
|
+
const throwable = () =>
|
|
90
|
+
schema
|
|
91
|
+
.getService(ModelDataValidator)
|
|
92
|
+
.validate('model', {foo: undefined});
|
|
93
|
+
expect(throwable).to.throw(
|
|
99
94
|
'The property "foo" of the model "model" is required, but undefined given.',
|
|
100
95
|
);
|
|
101
96
|
});
|
|
102
97
|
|
|
103
|
-
it('throws an error if a required property is null',
|
|
98
|
+
it('throws an error if a required property is null', function () {
|
|
104
99
|
const schema = new Schema();
|
|
105
100
|
schema.defineModel({
|
|
106
101
|
name: 'model',
|
|
@@ -111,16 +106,15 @@ describe('ModelDataValidator', function () {
|
|
|
111
106
|
},
|
|
112
107
|
},
|
|
113
108
|
});
|
|
114
|
-
const
|
|
115
|
-
.getService(ModelDataValidator)
|
|
116
|
-
|
|
117
|
-
await expect(promise).to.be.rejectedWith(
|
|
109
|
+
const throwable = () =>
|
|
110
|
+
schema.getService(ModelDataValidator).validate('model', {foo: null});
|
|
111
|
+
expect(throwable).to.throw(
|
|
118
112
|
'The property "foo" of the model "model" is required, but null given.',
|
|
119
113
|
);
|
|
120
114
|
});
|
|
121
115
|
|
|
122
116
|
describe('an option "isPartial" is true', function () {
|
|
123
|
-
it('does not throw an error if a given data does not have a required property',
|
|
117
|
+
it('does not throw an error if a given data does not have a required property', function () {
|
|
124
118
|
const schema = new Schema();
|
|
125
119
|
schema.defineModel({
|
|
126
120
|
name: 'model',
|
|
@@ -131,10 +125,10 @@ describe('ModelDataValidator', function () {
|
|
|
131
125
|
},
|
|
132
126
|
},
|
|
133
127
|
});
|
|
134
|
-
|
|
128
|
+
schema.getService(ModelDataValidator).validate('model', {}, true);
|
|
135
129
|
});
|
|
136
130
|
|
|
137
|
-
it('throws an error if a required property is undefined',
|
|
131
|
+
it('throws an error if a required property is undefined', function () {
|
|
138
132
|
const schema = new Schema();
|
|
139
133
|
schema.defineModel({
|
|
140
134
|
name: 'model',
|
|
@@ -145,16 +139,17 @@ describe('ModelDataValidator', function () {
|
|
|
145
139
|
},
|
|
146
140
|
},
|
|
147
141
|
});
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
142
|
+
const throwable = () =>
|
|
143
|
+
schema
|
|
144
|
+
.getService(ModelDataValidator)
|
|
145
|
+
.validate('model', {foo: undefined}, true);
|
|
146
|
+
expect(throwable).to.throw(
|
|
152
147
|
'The property "foo" of the model "model" ' +
|
|
153
148
|
'is required, but undefined given.',
|
|
154
149
|
);
|
|
155
150
|
});
|
|
156
151
|
|
|
157
|
-
it('throws an error if a required property is null',
|
|
152
|
+
it('throws an error if a required property is null', function () {
|
|
158
153
|
const schema = new Schema();
|
|
159
154
|
schema.defineModel({
|
|
160
155
|
name: 'model',
|
|
@@ -165,10 +160,11 @@ describe('ModelDataValidator', function () {
|
|
|
165
160
|
},
|
|
166
161
|
},
|
|
167
162
|
});
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
163
|
+
const throwable = () =>
|
|
164
|
+
schema
|
|
165
|
+
.getService(ModelDataValidator)
|
|
166
|
+
.validate('model', {foo: null}, true);
|
|
167
|
+
expect(throwable).to.throw(
|
|
172
168
|
'The property "foo" of the model "model" is required, but null given.',
|
|
173
169
|
);
|
|
174
170
|
});
|
|
@@ -177,7 +173,7 @@ describe('ModelDataValidator', function () {
|
|
|
177
173
|
describe('validate by property type', function () {
|
|
178
174
|
describe('DataType.ANY', function () {
|
|
179
175
|
describe('ShortPropertyDefinition', function () {
|
|
180
|
-
it('does not throw an error if an undefined given',
|
|
176
|
+
it('does not throw an error if an undefined given', function () {
|
|
181
177
|
const S = new Schema();
|
|
182
178
|
S.defineModel({
|
|
183
179
|
name: 'model',
|
|
@@ -186,12 +182,12 @@ describe('ModelDataValidator', function () {
|
|
|
186
182
|
foo: DataType.ANY,
|
|
187
183
|
},
|
|
188
184
|
});
|
|
189
|
-
|
|
185
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
190
186
|
foo: undefined,
|
|
191
187
|
});
|
|
192
188
|
});
|
|
193
189
|
|
|
194
|
-
it('does not throw an error if a null given',
|
|
190
|
+
it('does not throw an error if a null given', function () {
|
|
195
191
|
const S = new Schema();
|
|
196
192
|
S.defineModel({
|
|
197
193
|
name: 'model',
|
|
@@ -200,12 +196,12 @@ describe('ModelDataValidator', function () {
|
|
|
200
196
|
foo: DataType.ANY,
|
|
201
197
|
},
|
|
202
198
|
});
|
|
203
|
-
|
|
199
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
204
200
|
foo: null,
|
|
205
201
|
});
|
|
206
202
|
});
|
|
207
203
|
|
|
208
|
-
it('does not throw an error if a string given',
|
|
204
|
+
it('does not throw an error if a string given', function () {
|
|
209
205
|
const S = new Schema();
|
|
210
206
|
S.defineModel({
|
|
211
207
|
name: 'model',
|
|
@@ -214,12 +210,12 @@ describe('ModelDataValidator', function () {
|
|
|
214
210
|
foo: DataType.ANY,
|
|
215
211
|
},
|
|
216
212
|
});
|
|
217
|
-
|
|
213
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
218
214
|
foo: 'bar',
|
|
219
215
|
});
|
|
220
216
|
});
|
|
221
217
|
|
|
222
|
-
it('does not throw an error if a number given',
|
|
218
|
+
it('does not throw an error if a number given', function () {
|
|
223
219
|
const S = new Schema();
|
|
224
220
|
S.defineModel({
|
|
225
221
|
name: 'model',
|
|
@@ -228,12 +224,12 @@ describe('ModelDataValidator', function () {
|
|
|
228
224
|
foo: DataType.ANY,
|
|
229
225
|
},
|
|
230
226
|
});
|
|
231
|
-
|
|
227
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
232
228
|
foo: 10,
|
|
233
229
|
});
|
|
234
230
|
});
|
|
235
231
|
|
|
236
|
-
it('does not throw an error if true given',
|
|
232
|
+
it('does not throw an error if true given', function () {
|
|
237
233
|
const S = new Schema();
|
|
238
234
|
S.defineModel({
|
|
239
235
|
name: 'model',
|
|
@@ -242,12 +238,12 @@ describe('ModelDataValidator', function () {
|
|
|
242
238
|
foo: DataType.ANY,
|
|
243
239
|
},
|
|
244
240
|
});
|
|
245
|
-
|
|
241
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
246
242
|
foo: true,
|
|
247
243
|
});
|
|
248
244
|
});
|
|
249
245
|
|
|
250
|
-
it('does not throw an error if false given',
|
|
246
|
+
it('does not throw an error if false given', function () {
|
|
251
247
|
const S = new Schema();
|
|
252
248
|
S.defineModel({
|
|
253
249
|
name: 'model',
|
|
@@ -256,12 +252,12 @@ describe('ModelDataValidator', function () {
|
|
|
256
252
|
foo: DataType.ANY,
|
|
257
253
|
},
|
|
258
254
|
});
|
|
259
|
-
|
|
255
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
260
256
|
foo: false,
|
|
261
257
|
});
|
|
262
258
|
});
|
|
263
259
|
|
|
264
|
-
it('does not throw an error if an array given',
|
|
260
|
+
it('does not throw an error if an array given', function () {
|
|
265
261
|
const S = new Schema();
|
|
266
262
|
S.defineModel({
|
|
267
263
|
name: 'model',
|
|
@@ -270,12 +266,12 @@ describe('ModelDataValidator', function () {
|
|
|
270
266
|
foo: DataType.ANY,
|
|
271
267
|
},
|
|
272
268
|
});
|
|
273
|
-
|
|
269
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
274
270
|
foo: [],
|
|
275
271
|
});
|
|
276
272
|
});
|
|
277
273
|
|
|
278
|
-
it('does not throw an error if an object given',
|
|
274
|
+
it('does not throw an error if an object given', function () {
|
|
279
275
|
const S = new Schema();
|
|
280
276
|
S.defineModel({
|
|
281
277
|
name: 'model',
|
|
@@ -284,14 +280,14 @@ describe('ModelDataValidator', function () {
|
|
|
284
280
|
foo: DataType.ANY,
|
|
285
281
|
},
|
|
286
282
|
});
|
|
287
|
-
|
|
283
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
288
284
|
foo: {},
|
|
289
285
|
});
|
|
290
286
|
});
|
|
291
287
|
});
|
|
292
288
|
|
|
293
289
|
describe('FullPropertyDefinition', function () {
|
|
294
|
-
it('does not throw an error if an undefined given',
|
|
290
|
+
it('does not throw an error if an undefined given', function () {
|
|
295
291
|
const S = new Schema();
|
|
296
292
|
S.defineModel({
|
|
297
293
|
name: 'model',
|
|
@@ -302,12 +298,12 @@ describe('ModelDataValidator', function () {
|
|
|
302
298
|
},
|
|
303
299
|
},
|
|
304
300
|
});
|
|
305
|
-
|
|
301
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
306
302
|
foo: undefined,
|
|
307
303
|
});
|
|
308
304
|
});
|
|
309
305
|
|
|
310
|
-
it('does not throw an error if a null given',
|
|
306
|
+
it('does not throw an error if a null given', function () {
|
|
311
307
|
const S = new Schema();
|
|
312
308
|
S.defineModel({
|
|
313
309
|
name: 'model',
|
|
@@ -318,12 +314,12 @@ describe('ModelDataValidator', function () {
|
|
|
318
314
|
},
|
|
319
315
|
},
|
|
320
316
|
});
|
|
321
|
-
|
|
317
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
322
318
|
foo: null,
|
|
323
319
|
});
|
|
324
320
|
});
|
|
325
321
|
|
|
326
|
-
it('does not throw an error if a string given',
|
|
322
|
+
it('does not throw an error if a string given', function () {
|
|
327
323
|
const S = new Schema();
|
|
328
324
|
S.defineModel({
|
|
329
325
|
name: 'model',
|
|
@@ -334,12 +330,12 @@ describe('ModelDataValidator', function () {
|
|
|
334
330
|
},
|
|
335
331
|
},
|
|
336
332
|
});
|
|
337
|
-
|
|
333
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
338
334
|
foo: 'bar',
|
|
339
335
|
});
|
|
340
336
|
});
|
|
341
337
|
|
|
342
|
-
it('does not throw an error if a number given',
|
|
338
|
+
it('does not throw an error if a number given', function () {
|
|
343
339
|
const S = new Schema();
|
|
344
340
|
S.defineModel({
|
|
345
341
|
name: 'model',
|
|
@@ -350,12 +346,12 @@ describe('ModelDataValidator', function () {
|
|
|
350
346
|
},
|
|
351
347
|
},
|
|
352
348
|
});
|
|
353
|
-
|
|
349
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
354
350
|
foo: 10,
|
|
355
351
|
});
|
|
356
352
|
});
|
|
357
353
|
|
|
358
|
-
it('does not throw an error if true given',
|
|
354
|
+
it('does not throw an error if true given', function () {
|
|
359
355
|
const S = new Schema();
|
|
360
356
|
S.defineModel({
|
|
361
357
|
name: 'model',
|
|
@@ -366,12 +362,12 @@ describe('ModelDataValidator', function () {
|
|
|
366
362
|
},
|
|
367
363
|
},
|
|
368
364
|
});
|
|
369
|
-
|
|
365
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
370
366
|
foo: true,
|
|
371
367
|
});
|
|
372
368
|
});
|
|
373
369
|
|
|
374
|
-
it('does not throw an error if false given',
|
|
370
|
+
it('does not throw an error if false given', function () {
|
|
375
371
|
const S = new Schema();
|
|
376
372
|
S.defineModel({
|
|
377
373
|
name: 'model',
|
|
@@ -382,12 +378,12 @@ describe('ModelDataValidator', function () {
|
|
|
382
378
|
},
|
|
383
379
|
},
|
|
384
380
|
});
|
|
385
|
-
|
|
381
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
386
382
|
foo: false,
|
|
387
383
|
});
|
|
388
384
|
});
|
|
389
385
|
|
|
390
|
-
it('does not throw an error if an array given',
|
|
386
|
+
it('does not throw an error if an array given', function () {
|
|
391
387
|
const S = new Schema();
|
|
392
388
|
S.defineModel({
|
|
393
389
|
name: 'model',
|
|
@@ -398,12 +394,12 @@ describe('ModelDataValidator', function () {
|
|
|
398
394
|
},
|
|
399
395
|
},
|
|
400
396
|
});
|
|
401
|
-
|
|
397
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
402
398
|
foo: [],
|
|
403
399
|
});
|
|
404
400
|
});
|
|
405
401
|
|
|
406
|
-
it('does not throw an error if an object given',
|
|
402
|
+
it('does not throw an error if an object given', function () {
|
|
407
403
|
const S = new Schema();
|
|
408
404
|
S.defineModel({
|
|
409
405
|
name: 'model',
|
|
@@ -414,7 +410,7 @@ describe('ModelDataValidator', function () {
|
|
|
414
410
|
},
|
|
415
411
|
},
|
|
416
412
|
});
|
|
417
|
-
|
|
413
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
418
414
|
foo: {},
|
|
419
415
|
});
|
|
420
416
|
});
|
|
@@ -423,7 +419,7 @@ describe('ModelDataValidator', function () {
|
|
|
423
419
|
|
|
424
420
|
describe('DataType.STRING', function () {
|
|
425
421
|
describe('ShortPropertyDefinition', function () {
|
|
426
|
-
it('does not throw an error if an undefined given',
|
|
422
|
+
it('does not throw an error if an undefined given', function () {
|
|
427
423
|
const S = new Schema();
|
|
428
424
|
S.defineModel({
|
|
429
425
|
name: 'model',
|
|
@@ -432,12 +428,12 @@ describe('ModelDataValidator', function () {
|
|
|
432
428
|
foo: DataType.STRING,
|
|
433
429
|
},
|
|
434
430
|
});
|
|
435
|
-
|
|
431
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
436
432
|
foo: undefined,
|
|
437
433
|
});
|
|
438
434
|
});
|
|
439
435
|
|
|
440
|
-
it('does not throw an error if a null given',
|
|
436
|
+
it('does not throw an error if a null given', function () {
|
|
441
437
|
const S = new Schema();
|
|
442
438
|
S.defineModel({
|
|
443
439
|
name: 'model',
|
|
@@ -446,12 +442,12 @@ describe('ModelDataValidator', function () {
|
|
|
446
442
|
foo: DataType.STRING,
|
|
447
443
|
},
|
|
448
444
|
});
|
|
449
|
-
|
|
445
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
450
446
|
foo: null,
|
|
451
447
|
});
|
|
452
448
|
});
|
|
453
449
|
|
|
454
|
-
it('does not throw an error if a string given',
|
|
450
|
+
it('does not throw an error if a string given', function () {
|
|
455
451
|
const S = new Schema();
|
|
456
452
|
S.defineModel({
|
|
457
453
|
name: 'model',
|
|
@@ -460,12 +456,12 @@ describe('ModelDataValidator', function () {
|
|
|
460
456
|
foo: DataType.STRING,
|
|
461
457
|
},
|
|
462
458
|
});
|
|
463
|
-
|
|
459
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
464
460
|
foo: 'bar',
|
|
465
461
|
});
|
|
466
462
|
});
|
|
467
463
|
|
|
468
|
-
it('throws an error if a number given',
|
|
464
|
+
it('throws an error if a number given', function () {
|
|
469
465
|
const S = new Schema();
|
|
470
466
|
S.defineModel({
|
|
471
467
|
name: 'model',
|
|
@@ -474,16 +470,17 @@ describe('ModelDataValidator', function () {
|
|
|
474
470
|
foo: DataType.STRING,
|
|
475
471
|
},
|
|
476
472
|
});
|
|
477
|
-
const
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
473
|
+
const throwable = () =>
|
|
474
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
475
|
+
foo: 10,
|
|
476
|
+
});
|
|
477
|
+
expect(throwable).to.throw(
|
|
481
478
|
'The property "foo" of the model "model" must have ' +
|
|
482
479
|
'a String, but Number given.',
|
|
483
480
|
);
|
|
484
481
|
});
|
|
485
482
|
|
|
486
|
-
it('throws an error if true given',
|
|
483
|
+
it('throws an error if true given', function () {
|
|
487
484
|
const S = new Schema();
|
|
488
485
|
S.defineModel({
|
|
489
486
|
name: 'model',
|
|
@@ -492,16 +489,17 @@ describe('ModelDataValidator', function () {
|
|
|
492
489
|
foo: DataType.STRING,
|
|
493
490
|
},
|
|
494
491
|
});
|
|
495
|
-
const
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
492
|
+
const throwable = () =>
|
|
493
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
494
|
+
foo: true,
|
|
495
|
+
});
|
|
496
|
+
expect(throwable).to.throw(
|
|
499
497
|
'The property "foo" of the model "model" must have ' +
|
|
500
498
|
'a String, but Boolean given.',
|
|
501
499
|
);
|
|
502
500
|
});
|
|
503
501
|
|
|
504
|
-
it('throws an error if false given',
|
|
502
|
+
it('throws an error if false given', function () {
|
|
505
503
|
const S = new Schema();
|
|
506
504
|
S.defineModel({
|
|
507
505
|
name: 'model',
|
|
@@ -510,16 +508,17 @@ describe('ModelDataValidator', function () {
|
|
|
510
508
|
foo: DataType.STRING,
|
|
511
509
|
},
|
|
512
510
|
});
|
|
513
|
-
const
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
511
|
+
const throwable = () =>
|
|
512
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
513
|
+
foo: false,
|
|
514
|
+
});
|
|
515
|
+
expect(throwable).to.throw(
|
|
517
516
|
'The property "foo" of the model "model" must have ' +
|
|
518
517
|
'a String, but Boolean given.',
|
|
519
518
|
);
|
|
520
519
|
});
|
|
521
520
|
|
|
522
|
-
it('throws an error if an array given',
|
|
521
|
+
it('throws an error if an array given', function () {
|
|
523
522
|
const S = new Schema();
|
|
524
523
|
S.defineModel({
|
|
525
524
|
name: 'model',
|
|
@@ -528,16 +527,17 @@ describe('ModelDataValidator', function () {
|
|
|
528
527
|
foo: DataType.STRING,
|
|
529
528
|
},
|
|
530
529
|
});
|
|
531
|
-
const
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
530
|
+
const throwable = () =>
|
|
531
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
532
|
+
foo: [],
|
|
533
|
+
});
|
|
534
|
+
expect(throwable).to.throw(
|
|
535
535
|
'The property "foo" of the model "model" must have ' +
|
|
536
536
|
'a String, but Array given.',
|
|
537
537
|
);
|
|
538
538
|
});
|
|
539
539
|
|
|
540
|
-
it('throws an error if an object given',
|
|
540
|
+
it('throws an error if an object given', function () {
|
|
541
541
|
const S = new Schema();
|
|
542
542
|
S.defineModel({
|
|
543
543
|
name: 'model',
|
|
@@ -546,10 +546,11 @@ describe('ModelDataValidator', function () {
|
|
|
546
546
|
foo: DataType.STRING,
|
|
547
547
|
},
|
|
548
548
|
});
|
|
549
|
-
const
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
549
|
+
const throwable = () =>
|
|
550
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
551
|
+
foo: {},
|
|
552
|
+
});
|
|
553
|
+
expect(throwable).to.throw(
|
|
553
554
|
'The property "foo" of the model "model" must have ' +
|
|
554
555
|
'a String, but Object given.',
|
|
555
556
|
);
|
|
@@ -557,7 +558,7 @@ describe('ModelDataValidator', function () {
|
|
|
557
558
|
});
|
|
558
559
|
|
|
559
560
|
describe('FullPropertyDefinition', function () {
|
|
560
|
-
it('does not throw an error if an undefined given',
|
|
561
|
+
it('does not throw an error if an undefined given', function () {
|
|
561
562
|
const S = new Schema();
|
|
562
563
|
S.defineModel({
|
|
563
564
|
name: 'model',
|
|
@@ -568,12 +569,12 @@ describe('ModelDataValidator', function () {
|
|
|
568
569
|
},
|
|
569
570
|
},
|
|
570
571
|
});
|
|
571
|
-
|
|
572
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
572
573
|
foo: undefined,
|
|
573
574
|
});
|
|
574
575
|
});
|
|
575
576
|
|
|
576
|
-
it('does not throw an error if a null given',
|
|
577
|
+
it('does not throw an error if a null given', function () {
|
|
577
578
|
const S = new Schema();
|
|
578
579
|
S.defineModel({
|
|
579
580
|
name: 'model',
|
|
@@ -584,12 +585,12 @@ describe('ModelDataValidator', function () {
|
|
|
584
585
|
},
|
|
585
586
|
},
|
|
586
587
|
});
|
|
587
|
-
|
|
588
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
588
589
|
foo: null,
|
|
589
590
|
});
|
|
590
591
|
});
|
|
591
592
|
|
|
592
|
-
it('does not throw an error if a string given',
|
|
593
|
+
it('does not throw an error if a string given', function () {
|
|
593
594
|
const S = new Schema();
|
|
594
595
|
S.defineModel({
|
|
595
596
|
name: 'model',
|
|
@@ -600,12 +601,12 @@ describe('ModelDataValidator', function () {
|
|
|
600
601
|
},
|
|
601
602
|
},
|
|
602
603
|
});
|
|
603
|
-
|
|
604
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
604
605
|
foo: 'bar',
|
|
605
606
|
});
|
|
606
607
|
});
|
|
607
608
|
|
|
608
|
-
it('throws an error if a number given',
|
|
609
|
+
it('throws an error if a number given', function () {
|
|
609
610
|
const S = new Schema();
|
|
610
611
|
S.defineModel({
|
|
611
612
|
name: 'model',
|
|
@@ -616,16 +617,17 @@ describe('ModelDataValidator', function () {
|
|
|
616
617
|
},
|
|
617
618
|
},
|
|
618
619
|
});
|
|
619
|
-
const
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
620
|
+
const throwable = () =>
|
|
621
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
622
|
+
foo: 10,
|
|
623
|
+
});
|
|
624
|
+
expect(throwable).to.throw(
|
|
623
625
|
'The property "foo" of the model "model" must have ' +
|
|
624
626
|
'a String, but Number given.',
|
|
625
627
|
);
|
|
626
628
|
});
|
|
627
629
|
|
|
628
|
-
it('throws an error if true given',
|
|
630
|
+
it('throws an error if true given', function () {
|
|
629
631
|
const S = new Schema();
|
|
630
632
|
S.defineModel({
|
|
631
633
|
name: 'model',
|
|
@@ -636,16 +638,17 @@ describe('ModelDataValidator', function () {
|
|
|
636
638
|
},
|
|
637
639
|
},
|
|
638
640
|
});
|
|
639
|
-
const
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
641
|
+
const throwable = () =>
|
|
642
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
643
|
+
foo: true,
|
|
644
|
+
});
|
|
645
|
+
expect(throwable).to.throw(
|
|
643
646
|
'The property "foo" of the model "model" must have ' +
|
|
644
647
|
'a String, but Boolean given.',
|
|
645
648
|
);
|
|
646
649
|
});
|
|
647
650
|
|
|
648
|
-
it('throws an error if false given',
|
|
651
|
+
it('throws an error if false given', function () {
|
|
649
652
|
const S = new Schema();
|
|
650
653
|
S.defineModel({
|
|
651
654
|
name: 'model',
|
|
@@ -656,16 +659,17 @@ describe('ModelDataValidator', function () {
|
|
|
656
659
|
},
|
|
657
660
|
},
|
|
658
661
|
});
|
|
659
|
-
const
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
662
|
+
const throwable = () =>
|
|
663
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
664
|
+
foo: false,
|
|
665
|
+
});
|
|
666
|
+
expect(throwable).to.throw(
|
|
663
667
|
'The property "foo" of the model "model" must have ' +
|
|
664
668
|
'a String, but Boolean given.',
|
|
665
669
|
);
|
|
666
670
|
});
|
|
667
671
|
|
|
668
|
-
it('throws an error if an array given',
|
|
672
|
+
it('throws an error if an array given', function () {
|
|
669
673
|
const S = new Schema();
|
|
670
674
|
S.defineModel({
|
|
671
675
|
name: 'model',
|
|
@@ -676,16 +680,17 @@ describe('ModelDataValidator', function () {
|
|
|
676
680
|
},
|
|
677
681
|
},
|
|
678
682
|
});
|
|
679
|
-
const
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
+
const throwable = () =>
|
|
684
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
685
|
+
foo: [],
|
|
686
|
+
});
|
|
687
|
+
expect(throwable).to.throw(
|
|
683
688
|
'The property "foo" of the model "model" must have ' +
|
|
684
689
|
'a String, but Array given.',
|
|
685
690
|
);
|
|
686
691
|
});
|
|
687
692
|
|
|
688
|
-
it('throws an error if an object given',
|
|
693
|
+
it('throws an error if an object given', function () {
|
|
689
694
|
const S = new Schema();
|
|
690
695
|
S.defineModel({
|
|
691
696
|
name: 'model',
|
|
@@ -696,10 +701,11 @@ describe('ModelDataValidator', function () {
|
|
|
696
701
|
},
|
|
697
702
|
},
|
|
698
703
|
});
|
|
699
|
-
const
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
704
|
+
const throwable = () =>
|
|
705
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
706
|
+
foo: {},
|
|
707
|
+
});
|
|
708
|
+
expect(throwable).to.throw(
|
|
703
709
|
'The property "foo" of the model "model" must have ' +
|
|
704
710
|
'a String, but Object given.',
|
|
705
711
|
);
|
|
@@ -709,7 +715,7 @@ describe('ModelDataValidator', function () {
|
|
|
709
715
|
|
|
710
716
|
describe('DataType.NUMBER', function () {
|
|
711
717
|
describe('ShortPropertyDefinition', function () {
|
|
712
|
-
it('does not throw an error if an undefined given',
|
|
718
|
+
it('does not throw an error if an undefined given', function () {
|
|
713
719
|
const S = new Schema();
|
|
714
720
|
S.defineModel({
|
|
715
721
|
name: 'model',
|
|
@@ -718,12 +724,12 @@ describe('ModelDataValidator', function () {
|
|
|
718
724
|
foo: DataType.NUMBER,
|
|
719
725
|
},
|
|
720
726
|
});
|
|
721
|
-
|
|
727
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
722
728
|
foo: undefined,
|
|
723
729
|
});
|
|
724
730
|
});
|
|
725
731
|
|
|
726
|
-
it('does not throw an error if a null given',
|
|
732
|
+
it('does not throw an error if a null given', function () {
|
|
727
733
|
const S = new Schema();
|
|
728
734
|
S.defineModel({
|
|
729
735
|
name: 'model',
|
|
@@ -732,12 +738,12 @@ describe('ModelDataValidator', function () {
|
|
|
732
738
|
foo: DataType.NUMBER,
|
|
733
739
|
},
|
|
734
740
|
});
|
|
735
|
-
|
|
741
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
736
742
|
foo: null,
|
|
737
743
|
});
|
|
738
744
|
});
|
|
739
745
|
|
|
740
|
-
it('throws an error if a string given',
|
|
746
|
+
it('throws an error if a string given', function () {
|
|
741
747
|
const S = new Schema();
|
|
742
748
|
S.defineModel({
|
|
743
749
|
name: 'model',
|
|
@@ -746,16 +752,17 @@ describe('ModelDataValidator', function () {
|
|
|
746
752
|
foo: DataType.NUMBER,
|
|
747
753
|
},
|
|
748
754
|
});
|
|
749
|
-
const
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
755
|
+
const throwable = () =>
|
|
756
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
757
|
+
foo: 'bar',
|
|
758
|
+
});
|
|
759
|
+
expect(throwable).to.throw(
|
|
753
760
|
'The property "foo" of the model "model" must have ' +
|
|
754
761
|
'a Number, but String given.',
|
|
755
762
|
);
|
|
756
763
|
});
|
|
757
764
|
|
|
758
|
-
it('does not throw an error if a number given',
|
|
765
|
+
it('does not throw an error if a number given', function () {
|
|
759
766
|
const S = new Schema();
|
|
760
767
|
S.defineModel({
|
|
761
768
|
name: 'model',
|
|
@@ -764,12 +771,12 @@ describe('ModelDataValidator', function () {
|
|
|
764
771
|
foo: DataType.NUMBER,
|
|
765
772
|
},
|
|
766
773
|
});
|
|
767
|
-
|
|
774
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
768
775
|
foo: 10,
|
|
769
776
|
});
|
|
770
777
|
});
|
|
771
778
|
|
|
772
|
-
it('throws an error if true given',
|
|
779
|
+
it('throws an error if true given', function () {
|
|
773
780
|
const S = new Schema();
|
|
774
781
|
S.defineModel({
|
|
775
782
|
name: 'model',
|
|
@@ -778,16 +785,17 @@ describe('ModelDataValidator', function () {
|
|
|
778
785
|
foo: DataType.NUMBER,
|
|
779
786
|
},
|
|
780
787
|
});
|
|
781
|
-
const
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
788
|
+
const throwable = () =>
|
|
789
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
790
|
+
foo: true,
|
|
791
|
+
});
|
|
792
|
+
expect(throwable).to.throw(
|
|
785
793
|
'The property "foo" of the model "model" must have ' +
|
|
786
794
|
'a Number, but Boolean given.',
|
|
787
795
|
);
|
|
788
796
|
});
|
|
789
797
|
|
|
790
|
-
it('throws an error if false given',
|
|
798
|
+
it('throws an error if false given', function () {
|
|
791
799
|
const S = new Schema();
|
|
792
800
|
S.defineModel({
|
|
793
801
|
name: 'model',
|
|
@@ -796,16 +804,17 @@ describe('ModelDataValidator', function () {
|
|
|
796
804
|
foo: DataType.NUMBER,
|
|
797
805
|
},
|
|
798
806
|
});
|
|
799
|
-
const
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
807
|
+
const throwable = () =>
|
|
808
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
809
|
+
foo: false,
|
|
810
|
+
});
|
|
811
|
+
expect(throwable).to.throw(
|
|
803
812
|
'The property "foo" of the model "model" must have ' +
|
|
804
813
|
'a Number, but Boolean given.',
|
|
805
814
|
);
|
|
806
815
|
});
|
|
807
816
|
|
|
808
|
-
it('throws an error if an array given',
|
|
817
|
+
it('throws an error if an array given', function () {
|
|
809
818
|
const S = new Schema();
|
|
810
819
|
S.defineModel({
|
|
811
820
|
name: 'model',
|
|
@@ -814,16 +823,17 @@ describe('ModelDataValidator', function () {
|
|
|
814
823
|
foo: DataType.NUMBER,
|
|
815
824
|
},
|
|
816
825
|
});
|
|
817
|
-
const
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
826
|
+
const throwable = () =>
|
|
827
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
828
|
+
foo: [],
|
|
829
|
+
});
|
|
830
|
+
expect(throwable).to.throw(
|
|
821
831
|
'The property "foo" of the model "model" must have ' +
|
|
822
832
|
'a Number, but Array given.',
|
|
823
833
|
);
|
|
824
834
|
});
|
|
825
835
|
|
|
826
|
-
it('throws an error if an object given',
|
|
836
|
+
it('throws an error if an object given', function () {
|
|
827
837
|
const S = new Schema();
|
|
828
838
|
S.defineModel({
|
|
829
839
|
name: 'model',
|
|
@@ -832,10 +842,11 @@ describe('ModelDataValidator', function () {
|
|
|
832
842
|
foo: DataType.NUMBER,
|
|
833
843
|
},
|
|
834
844
|
});
|
|
835
|
-
const
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
845
|
+
const throwable = () =>
|
|
846
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
847
|
+
foo: {},
|
|
848
|
+
});
|
|
849
|
+
expect(throwable).to.throw(
|
|
839
850
|
'The property "foo" of the model "model" must have ' +
|
|
840
851
|
'a Number, but Object given.',
|
|
841
852
|
);
|
|
@@ -843,7 +854,7 @@ describe('ModelDataValidator', function () {
|
|
|
843
854
|
});
|
|
844
855
|
|
|
845
856
|
describe('FullPropertyDefinition', function () {
|
|
846
|
-
it('does not throw an error if an undefined given',
|
|
857
|
+
it('does not throw an error if an undefined given', function () {
|
|
847
858
|
const S = new Schema();
|
|
848
859
|
S.defineModel({
|
|
849
860
|
name: 'model',
|
|
@@ -854,12 +865,12 @@ describe('ModelDataValidator', function () {
|
|
|
854
865
|
},
|
|
855
866
|
},
|
|
856
867
|
});
|
|
857
|
-
|
|
868
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
858
869
|
foo: undefined,
|
|
859
870
|
});
|
|
860
871
|
});
|
|
861
872
|
|
|
862
|
-
it('does not throw an error if a null given',
|
|
873
|
+
it('does not throw an error if a null given', function () {
|
|
863
874
|
const S = new Schema();
|
|
864
875
|
S.defineModel({
|
|
865
876
|
name: 'model',
|
|
@@ -870,12 +881,12 @@ describe('ModelDataValidator', function () {
|
|
|
870
881
|
},
|
|
871
882
|
},
|
|
872
883
|
});
|
|
873
|
-
|
|
884
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
874
885
|
foo: null,
|
|
875
886
|
});
|
|
876
887
|
});
|
|
877
888
|
|
|
878
|
-
it('throws an error if a string given',
|
|
889
|
+
it('throws an error if a string given', function () {
|
|
879
890
|
const S = new Schema();
|
|
880
891
|
S.defineModel({
|
|
881
892
|
name: 'model',
|
|
@@ -886,16 +897,17 @@ describe('ModelDataValidator', function () {
|
|
|
886
897
|
},
|
|
887
898
|
},
|
|
888
899
|
});
|
|
889
|
-
const
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
900
|
+
const throwable = () =>
|
|
901
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
902
|
+
foo: 'bar',
|
|
903
|
+
});
|
|
904
|
+
expect(throwable).to.throw(
|
|
893
905
|
'The property "foo" of the model "model" must have ' +
|
|
894
906
|
'a Number, but String given.',
|
|
895
907
|
);
|
|
896
908
|
});
|
|
897
909
|
|
|
898
|
-
it('does not throw an error if a number given',
|
|
910
|
+
it('does not throw an error if a number given', function () {
|
|
899
911
|
const S = new Schema();
|
|
900
912
|
S.defineModel({
|
|
901
913
|
name: 'model',
|
|
@@ -906,12 +918,12 @@ describe('ModelDataValidator', function () {
|
|
|
906
918
|
},
|
|
907
919
|
},
|
|
908
920
|
});
|
|
909
|
-
|
|
921
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
910
922
|
foo: 10,
|
|
911
923
|
});
|
|
912
924
|
});
|
|
913
925
|
|
|
914
|
-
it('throws an error if true given',
|
|
926
|
+
it('throws an error if true given', function () {
|
|
915
927
|
const S = new Schema();
|
|
916
928
|
S.defineModel({
|
|
917
929
|
name: 'model',
|
|
@@ -922,16 +934,17 @@ describe('ModelDataValidator', function () {
|
|
|
922
934
|
},
|
|
923
935
|
},
|
|
924
936
|
});
|
|
925
|
-
const
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
937
|
+
const throwable = () =>
|
|
938
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
939
|
+
foo: true,
|
|
940
|
+
});
|
|
941
|
+
expect(throwable).to.throw(
|
|
929
942
|
'The property "foo" of the model "model" must have ' +
|
|
930
943
|
'a Number, but Boolean given.',
|
|
931
944
|
);
|
|
932
945
|
});
|
|
933
946
|
|
|
934
|
-
it('throws an error if false given',
|
|
947
|
+
it('throws an error if false given', function () {
|
|
935
948
|
const S = new Schema();
|
|
936
949
|
S.defineModel({
|
|
937
950
|
name: 'model',
|
|
@@ -942,16 +955,17 @@ describe('ModelDataValidator', function () {
|
|
|
942
955
|
},
|
|
943
956
|
},
|
|
944
957
|
});
|
|
945
|
-
const
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
958
|
+
const throwable = () =>
|
|
959
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
960
|
+
foo: false,
|
|
961
|
+
});
|
|
962
|
+
expect(throwable).to.throw(
|
|
949
963
|
'The property "foo" of the model "model" must have ' +
|
|
950
964
|
'a Number, but Boolean given.',
|
|
951
965
|
);
|
|
952
966
|
});
|
|
953
967
|
|
|
954
|
-
it('throws an error if an array given',
|
|
968
|
+
it('throws an error if an array given', function () {
|
|
955
969
|
const S = new Schema();
|
|
956
970
|
S.defineModel({
|
|
957
971
|
name: 'model',
|
|
@@ -962,16 +976,17 @@ describe('ModelDataValidator', function () {
|
|
|
962
976
|
},
|
|
963
977
|
},
|
|
964
978
|
});
|
|
965
|
-
const
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
979
|
+
const throwable = () =>
|
|
980
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
981
|
+
foo: [],
|
|
982
|
+
});
|
|
983
|
+
expect(throwable).to.throw(
|
|
969
984
|
'The property "foo" of the model "model" must have ' +
|
|
970
985
|
'a Number, but Array given.',
|
|
971
986
|
);
|
|
972
987
|
});
|
|
973
988
|
|
|
974
|
-
it('throws an error if an object given',
|
|
989
|
+
it('throws an error if an object given', function () {
|
|
975
990
|
const S = new Schema();
|
|
976
991
|
S.defineModel({
|
|
977
992
|
name: 'model',
|
|
@@ -982,10 +997,11 @@ describe('ModelDataValidator', function () {
|
|
|
982
997
|
},
|
|
983
998
|
},
|
|
984
999
|
});
|
|
985
|
-
const
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
1000
|
+
const throwable = () =>
|
|
1001
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1002
|
+
foo: {},
|
|
1003
|
+
});
|
|
1004
|
+
expect(throwable).to.throw(
|
|
989
1005
|
'The property "foo" of the model "model" must have ' +
|
|
990
1006
|
'a Number, but Object given.',
|
|
991
1007
|
);
|
|
@@ -995,7 +1011,7 @@ describe('ModelDataValidator', function () {
|
|
|
995
1011
|
|
|
996
1012
|
describe('DataType.BOOLEAN', function () {
|
|
997
1013
|
describe('ShortPropertyDefinition', function () {
|
|
998
|
-
it('does not throw an error if an undefined given',
|
|
1014
|
+
it('does not throw an error if an undefined given', function () {
|
|
999
1015
|
const S = new Schema();
|
|
1000
1016
|
S.defineModel({
|
|
1001
1017
|
name: 'model',
|
|
@@ -1004,12 +1020,12 @@ describe('ModelDataValidator', function () {
|
|
|
1004
1020
|
foo: DataType.BOOLEAN,
|
|
1005
1021
|
},
|
|
1006
1022
|
});
|
|
1007
|
-
|
|
1023
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1008
1024
|
foo: undefined,
|
|
1009
1025
|
});
|
|
1010
1026
|
});
|
|
1011
1027
|
|
|
1012
|
-
it('does not throw an error if a null given',
|
|
1028
|
+
it('does not throw an error if a null given', function () {
|
|
1013
1029
|
const S = new Schema();
|
|
1014
1030
|
S.defineModel({
|
|
1015
1031
|
name: 'model',
|
|
@@ -1018,12 +1034,12 @@ describe('ModelDataValidator', function () {
|
|
|
1018
1034
|
foo: DataType.BOOLEAN,
|
|
1019
1035
|
},
|
|
1020
1036
|
});
|
|
1021
|
-
|
|
1037
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1022
1038
|
foo: null,
|
|
1023
1039
|
});
|
|
1024
1040
|
});
|
|
1025
1041
|
|
|
1026
|
-
it('throws an error if a string given',
|
|
1042
|
+
it('throws an error if a string given', function () {
|
|
1027
1043
|
const S = new Schema();
|
|
1028
1044
|
S.defineModel({
|
|
1029
1045
|
name: 'model',
|
|
@@ -1032,16 +1048,17 @@ describe('ModelDataValidator', function () {
|
|
|
1032
1048
|
foo: DataType.BOOLEAN,
|
|
1033
1049
|
},
|
|
1034
1050
|
});
|
|
1035
|
-
const
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1051
|
+
const throwable = () =>
|
|
1052
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1053
|
+
foo: 'bar',
|
|
1054
|
+
});
|
|
1055
|
+
expect(throwable).to.throw(
|
|
1039
1056
|
'The property "foo" of the model "model" must have ' +
|
|
1040
1057
|
'a Boolean, but String given.',
|
|
1041
1058
|
);
|
|
1042
1059
|
});
|
|
1043
1060
|
|
|
1044
|
-
it('throws an error if a number given',
|
|
1061
|
+
it('throws an error if a number given', function () {
|
|
1045
1062
|
const S = new Schema();
|
|
1046
1063
|
S.defineModel({
|
|
1047
1064
|
name: 'model',
|
|
@@ -1050,16 +1067,17 @@ describe('ModelDataValidator', function () {
|
|
|
1050
1067
|
foo: DataType.BOOLEAN,
|
|
1051
1068
|
},
|
|
1052
1069
|
});
|
|
1053
|
-
const
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1070
|
+
const throwable = () =>
|
|
1071
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1072
|
+
foo: 10,
|
|
1073
|
+
});
|
|
1074
|
+
expect(throwable).to.throw(
|
|
1057
1075
|
'The property "foo" of the model "model" must have ' +
|
|
1058
1076
|
'a Boolean, but Number given.',
|
|
1059
1077
|
);
|
|
1060
1078
|
});
|
|
1061
1079
|
|
|
1062
|
-
it('does not throw an error if true given',
|
|
1080
|
+
it('does not throw an error if true given', function () {
|
|
1063
1081
|
const S = new Schema();
|
|
1064
1082
|
S.defineModel({
|
|
1065
1083
|
name: 'model',
|
|
@@ -1068,12 +1086,12 @@ describe('ModelDataValidator', function () {
|
|
|
1068
1086
|
foo: DataType.BOOLEAN,
|
|
1069
1087
|
},
|
|
1070
1088
|
});
|
|
1071
|
-
|
|
1089
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1072
1090
|
foo: true,
|
|
1073
1091
|
});
|
|
1074
1092
|
});
|
|
1075
1093
|
|
|
1076
|
-
it('does not throw an error if false given',
|
|
1094
|
+
it('does not throw an error if false given', function () {
|
|
1077
1095
|
const S = new Schema();
|
|
1078
1096
|
S.defineModel({
|
|
1079
1097
|
name: 'model',
|
|
@@ -1082,12 +1100,12 @@ describe('ModelDataValidator', function () {
|
|
|
1082
1100
|
foo: DataType.BOOLEAN,
|
|
1083
1101
|
},
|
|
1084
1102
|
});
|
|
1085
|
-
|
|
1103
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1086
1104
|
foo: false,
|
|
1087
1105
|
});
|
|
1088
1106
|
});
|
|
1089
1107
|
|
|
1090
|
-
it('throws an error if an array given',
|
|
1108
|
+
it('throws an error if an array given', function () {
|
|
1091
1109
|
const S = new Schema();
|
|
1092
1110
|
S.defineModel({
|
|
1093
1111
|
name: 'model',
|
|
@@ -1096,16 +1114,17 @@ describe('ModelDataValidator', function () {
|
|
|
1096
1114
|
foo: DataType.BOOLEAN,
|
|
1097
1115
|
},
|
|
1098
1116
|
});
|
|
1099
|
-
const
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1117
|
+
const throwable = () =>
|
|
1118
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1119
|
+
foo: [],
|
|
1120
|
+
});
|
|
1121
|
+
expect(throwable).to.throw(
|
|
1103
1122
|
'The property "foo" of the model "model" must have ' +
|
|
1104
1123
|
'a Boolean, but Array given.',
|
|
1105
1124
|
);
|
|
1106
1125
|
});
|
|
1107
1126
|
|
|
1108
|
-
it('throws an error if an object given',
|
|
1127
|
+
it('throws an error if an object given', function () {
|
|
1109
1128
|
const S = new Schema();
|
|
1110
1129
|
S.defineModel({
|
|
1111
1130
|
name: 'model',
|
|
@@ -1114,10 +1133,11 @@ describe('ModelDataValidator', function () {
|
|
|
1114
1133
|
foo: DataType.BOOLEAN,
|
|
1115
1134
|
},
|
|
1116
1135
|
});
|
|
1117
|
-
const
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1136
|
+
const throwable = () =>
|
|
1137
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1138
|
+
foo: {},
|
|
1139
|
+
});
|
|
1140
|
+
expect(throwable).to.throw(
|
|
1121
1141
|
'The property "foo" of the model "model" must have ' +
|
|
1122
1142
|
'a Boolean, but Object given.',
|
|
1123
1143
|
);
|
|
@@ -1125,7 +1145,7 @@ describe('ModelDataValidator', function () {
|
|
|
1125
1145
|
});
|
|
1126
1146
|
|
|
1127
1147
|
describe('FullPropertyDefinition', function () {
|
|
1128
|
-
it('does not throw an error if an undefined given',
|
|
1148
|
+
it('does not throw an error if an undefined given', function () {
|
|
1129
1149
|
const S = new Schema();
|
|
1130
1150
|
S.defineModel({
|
|
1131
1151
|
name: 'model',
|
|
@@ -1136,12 +1156,12 @@ describe('ModelDataValidator', function () {
|
|
|
1136
1156
|
},
|
|
1137
1157
|
},
|
|
1138
1158
|
});
|
|
1139
|
-
|
|
1159
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1140
1160
|
foo: undefined,
|
|
1141
1161
|
});
|
|
1142
1162
|
});
|
|
1143
1163
|
|
|
1144
|
-
it('does not throw an error if a null given',
|
|
1164
|
+
it('does not throw an error if a null given', function () {
|
|
1145
1165
|
const S = new Schema();
|
|
1146
1166
|
S.defineModel({
|
|
1147
1167
|
name: 'model',
|
|
@@ -1152,12 +1172,12 @@ describe('ModelDataValidator', function () {
|
|
|
1152
1172
|
},
|
|
1153
1173
|
},
|
|
1154
1174
|
});
|
|
1155
|
-
|
|
1175
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1156
1176
|
foo: null,
|
|
1157
1177
|
});
|
|
1158
1178
|
});
|
|
1159
1179
|
|
|
1160
|
-
it('throws an error if a string given',
|
|
1180
|
+
it('throws an error if a string given', function () {
|
|
1161
1181
|
const S = new Schema();
|
|
1162
1182
|
S.defineModel({
|
|
1163
1183
|
name: 'model',
|
|
@@ -1168,16 +1188,17 @@ describe('ModelDataValidator', function () {
|
|
|
1168
1188
|
},
|
|
1169
1189
|
},
|
|
1170
1190
|
});
|
|
1171
|
-
const
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1191
|
+
const throwable = () =>
|
|
1192
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1193
|
+
foo: 'bar',
|
|
1194
|
+
});
|
|
1195
|
+
expect(throwable).to.throw(
|
|
1175
1196
|
'The property "foo" of the model "model" must have ' +
|
|
1176
1197
|
'a Boolean, but String given.',
|
|
1177
1198
|
);
|
|
1178
1199
|
});
|
|
1179
1200
|
|
|
1180
|
-
it('throws an error if a number given',
|
|
1201
|
+
it('throws an error if a number given', function () {
|
|
1181
1202
|
const S = new Schema();
|
|
1182
1203
|
S.defineModel({
|
|
1183
1204
|
name: 'model',
|
|
@@ -1188,16 +1209,17 @@ describe('ModelDataValidator', function () {
|
|
|
1188
1209
|
},
|
|
1189
1210
|
},
|
|
1190
1211
|
});
|
|
1191
|
-
const
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1212
|
+
const throwable = () =>
|
|
1213
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1214
|
+
foo: 10,
|
|
1215
|
+
});
|
|
1216
|
+
expect(throwable).to.throw(
|
|
1195
1217
|
'The property "foo" of the model "model" must have ' +
|
|
1196
1218
|
'a Boolean, but Number given.',
|
|
1197
1219
|
);
|
|
1198
1220
|
});
|
|
1199
1221
|
|
|
1200
|
-
it('does not throw an error if true given',
|
|
1222
|
+
it('does not throw an error if true given', function () {
|
|
1201
1223
|
const S = new Schema();
|
|
1202
1224
|
S.defineModel({
|
|
1203
1225
|
name: 'model',
|
|
@@ -1208,12 +1230,12 @@ describe('ModelDataValidator', function () {
|
|
|
1208
1230
|
},
|
|
1209
1231
|
},
|
|
1210
1232
|
});
|
|
1211
|
-
|
|
1233
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1212
1234
|
foo: true,
|
|
1213
1235
|
});
|
|
1214
1236
|
});
|
|
1215
1237
|
|
|
1216
|
-
it('does not throw an error if false given',
|
|
1238
|
+
it('does not throw an error if false given', function () {
|
|
1217
1239
|
const S = new Schema();
|
|
1218
1240
|
S.defineModel({
|
|
1219
1241
|
name: 'model',
|
|
@@ -1224,12 +1246,12 @@ describe('ModelDataValidator', function () {
|
|
|
1224
1246
|
},
|
|
1225
1247
|
},
|
|
1226
1248
|
});
|
|
1227
|
-
|
|
1249
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1228
1250
|
foo: false,
|
|
1229
1251
|
});
|
|
1230
1252
|
});
|
|
1231
1253
|
|
|
1232
|
-
it('throws an error if an array given',
|
|
1254
|
+
it('throws an error if an array given', function () {
|
|
1233
1255
|
const S = new Schema();
|
|
1234
1256
|
S.defineModel({
|
|
1235
1257
|
name: 'model',
|
|
@@ -1240,16 +1262,17 @@ describe('ModelDataValidator', function () {
|
|
|
1240
1262
|
},
|
|
1241
1263
|
},
|
|
1242
1264
|
});
|
|
1243
|
-
const
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1265
|
+
const throwable = () =>
|
|
1266
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1267
|
+
foo: [],
|
|
1268
|
+
});
|
|
1269
|
+
expect(throwable).to.throw(
|
|
1247
1270
|
'The property "foo" of the model "model" must have ' +
|
|
1248
1271
|
'a Boolean, but Array given.',
|
|
1249
1272
|
);
|
|
1250
1273
|
});
|
|
1251
1274
|
|
|
1252
|
-
it('throws an error if an object given',
|
|
1275
|
+
it('throws an error if an object given', function () {
|
|
1253
1276
|
const S = new Schema();
|
|
1254
1277
|
S.defineModel({
|
|
1255
1278
|
name: 'model',
|
|
@@ -1260,10 +1283,11 @@ describe('ModelDataValidator', function () {
|
|
|
1260
1283
|
},
|
|
1261
1284
|
},
|
|
1262
1285
|
});
|
|
1263
|
-
const
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1286
|
+
const throwable = () =>
|
|
1287
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1288
|
+
foo: {},
|
|
1289
|
+
});
|
|
1290
|
+
expect(throwable).to.throw(
|
|
1267
1291
|
'The property "foo" of the model "model" must have ' +
|
|
1268
1292
|
'a Boolean, but Object given.',
|
|
1269
1293
|
);
|
|
@@ -1273,7 +1297,7 @@ describe('ModelDataValidator', function () {
|
|
|
1273
1297
|
|
|
1274
1298
|
describe('DataType.ARRAY', function () {
|
|
1275
1299
|
describe('ShortPropertyDefinition', function () {
|
|
1276
|
-
it('does not throw an error if an undefined given',
|
|
1300
|
+
it('does not throw an error if an undefined given', function () {
|
|
1277
1301
|
const S = new Schema();
|
|
1278
1302
|
S.defineModel({
|
|
1279
1303
|
name: 'model',
|
|
@@ -1282,12 +1306,12 @@ describe('ModelDataValidator', function () {
|
|
|
1282
1306
|
foo: DataType.ARRAY,
|
|
1283
1307
|
},
|
|
1284
1308
|
});
|
|
1285
|
-
|
|
1309
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1286
1310
|
foo: undefined,
|
|
1287
1311
|
});
|
|
1288
1312
|
});
|
|
1289
1313
|
|
|
1290
|
-
it('does not throw an error if a null given',
|
|
1314
|
+
it('does not throw an error if a null given', function () {
|
|
1291
1315
|
const S = new Schema();
|
|
1292
1316
|
S.defineModel({
|
|
1293
1317
|
name: 'model',
|
|
@@ -1296,12 +1320,12 @@ describe('ModelDataValidator', function () {
|
|
|
1296
1320
|
foo: DataType.ARRAY,
|
|
1297
1321
|
},
|
|
1298
1322
|
});
|
|
1299
|
-
|
|
1323
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1300
1324
|
foo: null,
|
|
1301
1325
|
});
|
|
1302
1326
|
});
|
|
1303
1327
|
|
|
1304
|
-
it('throws an error if a string given',
|
|
1328
|
+
it('throws an error if a string given', function () {
|
|
1305
1329
|
const S = new Schema();
|
|
1306
1330
|
S.defineModel({
|
|
1307
1331
|
name: 'model',
|
|
@@ -1310,16 +1334,17 @@ describe('ModelDataValidator', function () {
|
|
|
1310
1334
|
foo: DataType.ARRAY,
|
|
1311
1335
|
},
|
|
1312
1336
|
});
|
|
1313
|
-
const
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1337
|
+
const throwable = () =>
|
|
1338
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1339
|
+
foo: 'bar',
|
|
1340
|
+
});
|
|
1341
|
+
expect(throwable).to.throw(
|
|
1317
1342
|
'The property "foo" of the model "model" must have ' +
|
|
1318
1343
|
'an Array, but String given.',
|
|
1319
1344
|
);
|
|
1320
1345
|
});
|
|
1321
1346
|
|
|
1322
|
-
it('throws an error if a number given',
|
|
1347
|
+
it('throws an error if a number given', function () {
|
|
1323
1348
|
const S = new Schema();
|
|
1324
1349
|
S.defineModel({
|
|
1325
1350
|
name: 'model',
|
|
@@ -1328,16 +1353,17 @@ describe('ModelDataValidator', function () {
|
|
|
1328
1353
|
foo: DataType.ARRAY,
|
|
1329
1354
|
},
|
|
1330
1355
|
});
|
|
1331
|
-
const
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1356
|
+
const throwable = () =>
|
|
1357
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1358
|
+
foo: 10,
|
|
1359
|
+
});
|
|
1360
|
+
expect(throwable).to.throw(
|
|
1335
1361
|
'The property "foo" of the model "model" must have ' +
|
|
1336
1362
|
'an Array, but Number given.',
|
|
1337
1363
|
);
|
|
1338
1364
|
});
|
|
1339
1365
|
|
|
1340
|
-
it('throws an error if true given',
|
|
1366
|
+
it('throws an error if true given', function () {
|
|
1341
1367
|
const S = new Schema();
|
|
1342
1368
|
S.defineModel({
|
|
1343
1369
|
name: 'model',
|
|
@@ -1346,16 +1372,17 @@ describe('ModelDataValidator', function () {
|
|
|
1346
1372
|
foo: DataType.ARRAY,
|
|
1347
1373
|
},
|
|
1348
1374
|
});
|
|
1349
|
-
const
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1375
|
+
const throwable = () =>
|
|
1376
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1377
|
+
foo: true,
|
|
1378
|
+
});
|
|
1379
|
+
expect(throwable).to.throw(
|
|
1353
1380
|
'The property "foo" of the model "model" must have ' +
|
|
1354
1381
|
'an Array, but Boolean given.',
|
|
1355
1382
|
);
|
|
1356
1383
|
});
|
|
1357
1384
|
|
|
1358
|
-
it('throws an error if false given',
|
|
1385
|
+
it('throws an error if false given', function () {
|
|
1359
1386
|
const S = new Schema();
|
|
1360
1387
|
S.defineModel({
|
|
1361
1388
|
name: 'model',
|
|
@@ -1364,16 +1391,17 @@ describe('ModelDataValidator', function () {
|
|
|
1364
1391
|
foo: DataType.ARRAY,
|
|
1365
1392
|
},
|
|
1366
1393
|
});
|
|
1367
|
-
const
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1394
|
+
const throwable = () =>
|
|
1395
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1396
|
+
foo: false,
|
|
1397
|
+
});
|
|
1398
|
+
expect(throwable).to.throw(
|
|
1371
1399
|
'The property "foo" of the model "model" must have ' +
|
|
1372
1400
|
'an Array, but Boolean given.',
|
|
1373
1401
|
);
|
|
1374
1402
|
});
|
|
1375
1403
|
|
|
1376
|
-
it('does not throw an error if an array given',
|
|
1404
|
+
it('does not throw an error if an array given', function () {
|
|
1377
1405
|
const S = new Schema();
|
|
1378
1406
|
S.defineModel({
|
|
1379
1407
|
name: 'model',
|
|
@@ -1382,12 +1410,12 @@ describe('ModelDataValidator', function () {
|
|
|
1382
1410
|
foo: DataType.ARRAY,
|
|
1383
1411
|
},
|
|
1384
1412
|
});
|
|
1385
|
-
|
|
1413
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1386
1414
|
foo: [],
|
|
1387
1415
|
});
|
|
1388
1416
|
});
|
|
1389
1417
|
|
|
1390
|
-
it('throws an error if an object given',
|
|
1418
|
+
it('throws an error if an object given', function () {
|
|
1391
1419
|
const S = new Schema();
|
|
1392
1420
|
S.defineModel({
|
|
1393
1421
|
name: 'model',
|
|
@@ -1396,10 +1424,11 @@ describe('ModelDataValidator', function () {
|
|
|
1396
1424
|
foo: DataType.ARRAY,
|
|
1397
1425
|
},
|
|
1398
1426
|
});
|
|
1399
|
-
const
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1427
|
+
const throwable = () =>
|
|
1428
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1429
|
+
foo: {},
|
|
1430
|
+
});
|
|
1431
|
+
expect(throwable).to.throw(
|
|
1403
1432
|
'The property "foo" of the model "model" must have ' +
|
|
1404
1433
|
'an Array, but Object given.',
|
|
1405
1434
|
);
|
|
@@ -1407,7 +1436,7 @@ describe('ModelDataValidator', function () {
|
|
|
1407
1436
|
});
|
|
1408
1437
|
|
|
1409
1438
|
describe('FullPropertyDefinition', function () {
|
|
1410
|
-
it('does not throw an error if an undefined given',
|
|
1439
|
+
it('does not throw an error if an undefined given', function () {
|
|
1411
1440
|
const S = new Schema();
|
|
1412
1441
|
S.defineModel({
|
|
1413
1442
|
name: 'model',
|
|
@@ -1418,12 +1447,12 @@ describe('ModelDataValidator', function () {
|
|
|
1418
1447
|
},
|
|
1419
1448
|
},
|
|
1420
1449
|
});
|
|
1421
|
-
|
|
1450
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1422
1451
|
foo: undefined,
|
|
1423
1452
|
});
|
|
1424
1453
|
});
|
|
1425
1454
|
|
|
1426
|
-
it('does not throw an error if a null given',
|
|
1455
|
+
it('does not throw an error if a null given', function () {
|
|
1427
1456
|
const S = new Schema();
|
|
1428
1457
|
S.defineModel({
|
|
1429
1458
|
name: 'model',
|
|
@@ -1434,12 +1463,12 @@ describe('ModelDataValidator', function () {
|
|
|
1434
1463
|
},
|
|
1435
1464
|
},
|
|
1436
1465
|
});
|
|
1437
|
-
|
|
1466
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1438
1467
|
foo: null,
|
|
1439
1468
|
});
|
|
1440
1469
|
});
|
|
1441
1470
|
|
|
1442
|
-
it('throws an error if a string given',
|
|
1471
|
+
it('throws an error if a string given', function () {
|
|
1443
1472
|
const S = new Schema();
|
|
1444
1473
|
S.defineModel({
|
|
1445
1474
|
name: 'model',
|
|
@@ -1450,16 +1479,17 @@ describe('ModelDataValidator', function () {
|
|
|
1450
1479
|
},
|
|
1451
1480
|
},
|
|
1452
1481
|
});
|
|
1453
|
-
const
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1482
|
+
const throwable = () =>
|
|
1483
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1484
|
+
foo: 'bar',
|
|
1485
|
+
});
|
|
1486
|
+
expect(throwable).to.throw(
|
|
1457
1487
|
'The property "foo" of the model "model" must have ' +
|
|
1458
1488
|
'an Array, but String given.',
|
|
1459
1489
|
);
|
|
1460
1490
|
});
|
|
1461
1491
|
|
|
1462
|
-
it('throws an error if a number given',
|
|
1492
|
+
it('throws an error if a number given', function () {
|
|
1463
1493
|
const S = new Schema();
|
|
1464
1494
|
S.defineModel({
|
|
1465
1495
|
name: 'model',
|
|
@@ -1470,16 +1500,17 @@ describe('ModelDataValidator', function () {
|
|
|
1470
1500
|
},
|
|
1471
1501
|
},
|
|
1472
1502
|
});
|
|
1473
|
-
const
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1503
|
+
const throwable = () =>
|
|
1504
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1505
|
+
foo: 10,
|
|
1506
|
+
});
|
|
1507
|
+
expect(throwable).to.throw(
|
|
1477
1508
|
'The property "foo" of the model "model" must have ' +
|
|
1478
1509
|
'an Array, but Number given.',
|
|
1479
1510
|
);
|
|
1480
1511
|
});
|
|
1481
1512
|
|
|
1482
|
-
it('throws an error if true given',
|
|
1513
|
+
it('throws an error if true given', function () {
|
|
1483
1514
|
const S = new Schema();
|
|
1484
1515
|
S.defineModel({
|
|
1485
1516
|
name: 'model',
|
|
@@ -1490,16 +1521,17 @@ describe('ModelDataValidator', function () {
|
|
|
1490
1521
|
},
|
|
1491
1522
|
},
|
|
1492
1523
|
});
|
|
1493
|
-
const
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1524
|
+
const throwable = () =>
|
|
1525
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1526
|
+
foo: true,
|
|
1527
|
+
});
|
|
1528
|
+
expect(throwable).to.throw(
|
|
1497
1529
|
'The property "foo" of the model "model" must have ' +
|
|
1498
1530
|
'an Array, but Boolean given.',
|
|
1499
1531
|
);
|
|
1500
1532
|
});
|
|
1501
1533
|
|
|
1502
|
-
it('throws an error if false given',
|
|
1534
|
+
it('throws an error if false given', function () {
|
|
1503
1535
|
const S = new Schema();
|
|
1504
1536
|
S.defineModel({
|
|
1505
1537
|
name: 'model',
|
|
@@ -1510,16 +1542,17 @@ describe('ModelDataValidator', function () {
|
|
|
1510
1542
|
},
|
|
1511
1543
|
},
|
|
1512
1544
|
});
|
|
1513
|
-
const
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1545
|
+
const throwable = () =>
|
|
1546
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1547
|
+
foo: false,
|
|
1548
|
+
});
|
|
1549
|
+
expect(throwable).to.throw(
|
|
1517
1550
|
'The property "foo" of the model "model" must have ' +
|
|
1518
1551
|
'an Array, but Boolean given.',
|
|
1519
1552
|
);
|
|
1520
1553
|
});
|
|
1521
1554
|
|
|
1522
|
-
it('does not throw an error if an array given',
|
|
1555
|
+
it('does not throw an error if an array given', function () {
|
|
1523
1556
|
const S = new Schema();
|
|
1524
1557
|
S.defineModel({
|
|
1525
1558
|
name: 'model',
|
|
@@ -1530,12 +1563,12 @@ describe('ModelDataValidator', function () {
|
|
|
1530
1563
|
},
|
|
1531
1564
|
},
|
|
1532
1565
|
});
|
|
1533
|
-
|
|
1566
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1534
1567
|
foo: [],
|
|
1535
1568
|
});
|
|
1536
1569
|
});
|
|
1537
1570
|
|
|
1538
|
-
it('throws an error if an object given',
|
|
1571
|
+
it('throws an error if an object given', function () {
|
|
1539
1572
|
const S = new Schema();
|
|
1540
1573
|
S.defineModel({
|
|
1541
1574
|
name: 'model',
|
|
@@ -1546,17 +1579,18 @@ describe('ModelDataValidator', function () {
|
|
|
1546
1579
|
},
|
|
1547
1580
|
},
|
|
1548
1581
|
});
|
|
1549
|
-
const
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1582
|
+
const throwable = () =>
|
|
1583
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1584
|
+
foo: {},
|
|
1585
|
+
});
|
|
1586
|
+
expect(throwable).to.throw(
|
|
1553
1587
|
'The property "foo" of the model "model" must have ' +
|
|
1554
1588
|
'an Array, but Object given.',
|
|
1555
1589
|
);
|
|
1556
1590
|
});
|
|
1557
1591
|
|
|
1558
1592
|
describe('the "model" option', function () {
|
|
1559
|
-
it('throws an error when the given object element has an invalid model',
|
|
1593
|
+
it('throws an error when the given object element has an invalid model', function () {
|
|
1560
1594
|
const S = new Schema();
|
|
1561
1595
|
S.defineModel({
|
|
1562
1596
|
name: 'modelA',
|
|
@@ -1575,19 +1609,17 @@ describe('ModelDataValidator', function () {
|
|
|
1575
1609
|
},
|
|
1576
1610
|
},
|
|
1577
1611
|
});
|
|
1578
|
-
const
|
|
1579
|
-
'modelB',
|
|
1580
|
-
{
|
|
1612
|
+
const throwable = () =>
|
|
1613
|
+
S.getService(ModelDataValidator).validate('modelB', {
|
|
1581
1614
|
bar: [{foo: 10}],
|
|
1582
|
-
}
|
|
1583
|
-
)
|
|
1584
|
-
await expect(promise).to.be.rejectedWith(
|
|
1615
|
+
});
|
|
1616
|
+
expect(throwable).to.throw(
|
|
1585
1617
|
'The property "foo" of the model "modelA" must have ' +
|
|
1586
1618
|
'a String, but Number given.',
|
|
1587
1619
|
);
|
|
1588
1620
|
});
|
|
1589
1621
|
|
|
1590
|
-
it('does not throw an error when the given object element has a valid model',
|
|
1622
|
+
it('does not throw an error when the given object element has a valid model', function () {
|
|
1591
1623
|
const S = new Schema();
|
|
1592
1624
|
S.defineModel({
|
|
1593
1625
|
name: 'modelA',
|
|
@@ -1606,7 +1638,7 @@ describe('ModelDataValidator', function () {
|
|
|
1606
1638
|
},
|
|
1607
1639
|
},
|
|
1608
1640
|
});
|
|
1609
|
-
|
|
1641
|
+
S.getService(ModelDataValidator).validate('modelB', {
|
|
1610
1642
|
bar: [{foo: '10'}],
|
|
1611
1643
|
});
|
|
1612
1644
|
});
|
|
@@ -1616,7 +1648,7 @@ describe('ModelDataValidator', function () {
|
|
|
1616
1648
|
|
|
1617
1649
|
describe('DataType.OBJECT', function () {
|
|
1618
1650
|
describe('ShortPropertyDefinition', function () {
|
|
1619
|
-
it('does not throw an error if an undefined given',
|
|
1651
|
+
it('does not throw an error if an undefined given', function () {
|
|
1620
1652
|
const S = new Schema();
|
|
1621
1653
|
S.defineModel({
|
|
1622
1654
|
name: 'model',
|
|
@@ -1625,12 +1657,12 @@ describe('ModelDataValidator', function () {
|
|
|
1625
1657
|
foo: DataType.OBJECT,
|
|
1626
1658
|
},
|
|
1627
1659
|
});
|
|
1628
|
-
|
|
1660
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1629
1661
|
foo: undefined,
|
|
1630
1662
|
});
|
|
1631
1663
|
});
|
|
1632
1664
|
|
|
1633
|
-
it('does not throw an error if a null given',
|
|
1665
|
+
it('does not throw an error if a null given', function () {
|
|
1634
1666
|
const S = new Schema();
|
|
1635
1667
|
S.defineModel({
|
|
1636
1668
|
name: 'model',
|
|
@@ -1639,12 +1671,12 @@ describe('ModelDataValidator', function () {
|
|
|
1639
1671
|
foo: DataType.OBJECT,
|
|
1640
1672
|
},
|
|
1641
1673
|
});
|
|
1642
|
-
|
|
1674
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1643
1675
|
foo: null,
|
|
1644
1676
|
});
|
|
1645
1677
|
});
|
|
1646
1678
|
|
|
1647
|
-
it('throws an error if a string given',
|
|
1679
|
+
it('throws an error if a string given', function () {
|
|
1648
1680
|
const S = new Schema();
|
|
1649
1681
|
S.defineModel({
|
|
1650
1682
|
name: 'model',
|
|
@@ -1653,16 +1685,17 @@ describe('ModelDataValidator', function () {
|
|
|
1653
1685
|
foo: DataType.OBJECT,
|
|
1654
1686
|
},
|
|
1655
1687
|
});
|
|
1656
|
-
const
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1688
|
+
const throwable = () =>
|
|
1689
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1690
|
+
foo: 'bar',
|
|
1691
|
+
});
|
|
1692
|
+
expect(throwable).to.throw(
|
|
1660
1693
|
'The property "foo" of the model "model" must have ' +
|
|
1661
1694
|
'an Object, but String given.',
|
|
1662
1695
|
);
|
|
1663
1696
|
});
|
|
1664
1697
|
|
|
1665
|
-
it('throws an error if a number given',
|
|
1698
|
+
it('throws an error if a number given', function () {
|
|
1666
1699
|
const S = new Schema();
|
|
1667
1700
|
S.defineModel({
|
|
1668
1701
|
name: 'model',
|
|
@@ -1671,16 +1704,17 @@ describe('ModelDataValidator', function () {
|
|
|
1671
1704
|
foo: DataType.OBJECT,
|
|
1672
1705
|
},
|
|
1673
1706
|
});
|
|
1674
|
-
const
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1707
|
+
const throwable = () =>
|
|
1708
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1709
|
+
foo: 10,
|
|
1710
|
+
});
|
|
1711
|
+
expect(throwable).to.throw(
|
|
1678
1712
|
'The property "foo" of the model "model" must have ' +
|
|
1679
1713
|
'an Object, but Number given.',
|
|
1680
1714
|
);
|
|
1681
1715
|
});
|
|
1682
1716
|
|
|
1683
|
-
it('throws an error if true given',
|
|
1717
|
+
it('throws an error if true given', function () {
|
|
1684
1718
|
const S = new Schema();
|
|
1685
1719
|
S.defineModel({
|
|
1686
1720
|
name: 'model',
|
|
@@ -1689,16 +1723,17 @@ describe('ModelDataValidator', function () {
|
|
|
1689
1723
|
foo: DataType.OBJECT,
|
|
1690
1724
|
},
|
|
1691
1725
|
});
|
|
1692
|
-
const
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1726
|
+
const throwable = () =>
|
|
1727
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1728
|
+
foo: true,
|
|
1729
|
+
});
|
|
1730
|
+
expect(throwable).to.throw(
|
|
1696
1731
|
'The property "foo" of the model "model" must have ' +
|
|
1697
1732
|
'an Object, but Boolean given.',
|
|
1698
1733
|
);
|
|
1699
1734
|
});
|
|
1700
1735
|
|
|
1701
|
-
it('throws an error if false given',
|
|
1736
|
+
it('throws an error if false given', function () {
|
|
1702
1737
|
const S = new Schema();
|
|
1703
1738
|
S.defineModel({
|
|
1704
1739
|
name: 'model',
|
|
@@ -1707,16 +1742,17 @@ describe('ModelDataValidator', function () {
|
|
|
1707
1742
|
foo: DataType.OBJECT,
|
|
1708
1743
|
},
|
|
1709
1744
|
});
|
|
1710
|
-
const
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1745
|
+
const throwable = () =>
|
|
1746
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1747
|
+
foo: false,
|
|
1748
|
+
});
|
|
1749
|
+
expect(throwable).to.throw(
|
|
1714
1750
|
'The property "foo" of the model "model" must have ' +
|
|
1715
1751
|
'an Object, but Boolean given.',
|
|
1716
1752
|
);
|
|
1717
1753
|
});
|
|
1718
1754
|
|
|
1719
|
-
it('throws an error if an array given',
|
|
1755
|
+
it('throws an error if an array given', function () {
|
|
1720
1756
|
const S = new Schema();
|
|
1721
1757
|
S.defineModel({
|
|
1722
1758
|
name: 'model',
|
|
@@ -1725,16 +1761,17 @@ describe('ModelDataValidator', function () {
|
|
|
1725
1761
|
foo: DataType.OBJECT,
|
|
1726
1762
|
},
|
|
1727
1763
|
});
|
|
1728
|
-
const
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1764
|
+
const throwable = () =>
|
|
1765
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1766
|
+
foo: [],
|
|
1767
|
+
});
|
|
1768
|
+
expect(throwable).to.throw(
|
|
1732
1769
|
'The property "foo" of the model "model" must have ' +
|
|
1733
1770
|
'an Object, but Array given.',
|
|
1734
1771
|
);
|
|
1735
1772
|
});
|
|
1736
1773
|
|
|
1737
|
-
it('does not throw an error if an object given',
|
|
1774
|
+
it('does not throw an error if an object given', function () {
|
|
1738
1775
|
const S = new Schema();
|
|
1739
1776
|
S.defineModel({
|
|
1740
1777
|
name: 'model',
|
|
@@ -1743,14 +1780,14 @@ describe('ModelDataValidator', function () {
|
|
|
1743
1780
|
foo: DataType.OBJECT,
|
|
1744
1781
|
},
|
|
1745
1782
|
});
|
|
1746
|
-
|
|
1783
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1747
1784
|
foo: {},
|
|
1748
1785
|
});
|
|
1749
1786
|
});
|
|
1750
1787
|
});
|
|
1751
1788
|
|
|
1752
1789
|
describe('FullPropertyDefinition', function () {
|
|
1753
|
-
it('does not throw an error if an undefined given',
|
|
1790
|
+
it('does not throw an error if an undefined given', function () {
|
|
1754
1791
|
const S = new Schema();
|
|
1755
1792
|
S.defineModel({
|
|
1756
1793
|
name: 'model',
|
|
@@ -1761,12 +1798,12 @@ describe('ModelDataValidator', function () {
|
|
|
1761
1798
|
},
|
|
1762
1799
|
},
|
|
1763
1800
|
});
|
|
1764
|
-
|
|
1801
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1765
1802
|
foo: undefined,
|
|
1766
1803
|
});
|
|
1767
1804
|
});
|
|
1768
1805
|
|
|
1769
|
-
it('does not throw an error if a null given',
|
|
1806
|
+
it('does not throw an error if a null given', function () {
|
|
1770
1807
|
const S = new Schema();
|
|
1771
1808
|
S.defineModel({
|
|
1772
1809
|
name: 'model',
|
|
@@ -1777,12 +1814,12 @@ describe('ModelDataValidator', function () {
|
|
|
1777
1814
|
},
|
|
1778
1815
|
},
|
|
1779
1816
|
});
|
|
1780
|
-
|
|
1817
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1781
1818
|
foo: null,
|
|
1782
1819
|
});
|
|
1783
1820
|
});
|
|
1784
1821
|
|
|
1785
|
-
it('throws an error if a string given',
|
|
1822
|
+
it('throws an error if a string given', function () {
|
|
1786
1823
|
const S = new Schema();
|
|
1787
1824
|
S.defineModel({
|
|
1788
1825
|
name: 'model',
|
|
@@ -1793,16 +1830,17 @@ describe('ModelDataValidator', function () {
|
|
|
1793
1830
|
},
|
|
1794
1831
|
},
|
|
1795
1832
|
});
|
|
1796
|
-
const
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1833
|
+
const throwable = () =>
|
|
1834
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1835
|
+
foo: 'bar',
|
|
1836
|
+
});
|
|
1837
|
+
expect(throwable).to.throw(
|
|
1800
1838
|
'The property "foo" of the model "model" must have ' +
|
|
1801
1839
|
'an Object, but String given.',
|
|
1802
1840
|
);
|
|
1803
1841
|
});
|
|
1804
1842
|
|
|
1805
|
-
it('throws an error if a number given',
|
|
1843
|
+
it('throws an error if a number given', function () {
|
|
1806
1844
|
const S = new Schema();
|
|
1807
1845
|
S.defineModel({
|
|
1808
1846
|
name: 'model',
|
|
@@ -1813,16 +1851,17 @@ describe('ModelDataValidator', function () {
|
|
|
1813
1851
|
},
|
|
1814
1852
|
},
|
|
1815
1853
|
});
|
|
1816
|
-
const
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1854
|
+
const throwable = () =>
|
|
1855
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1856
|
+
foo: 10,
|
|
1857
|
+
});
|
|
1858
|
+
expect(throwable).to.throw(
|
|
1820
1859
|
'The property "foo" of the model "model" must have ' +
|
|
1821
1860
|
'an Object, but Number given.',
|
|
1822
1861
|
);
|
|
1823
1862
|
});
|
|
1824
1863
|
|
|
1825
|
-
it('throws an error if true given',
|
|
1864
|
+
it('throws an error if true given', function () {
|
|
1826
1865
|
const S = new Schema();
|
|
1827
1866
|
S.defineModel({
|
|
1828
1867
|
name: 'model',
|
|
@@ -1833,16 +1872,17 @@ describe('ModelDataValidator', function () {
|
|
|
1833
1872
|
},
|
|
1834
1873
|
},
|
|
1835
1874
|
});
|
|
1836
|
-
const
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1875
|
+
const throwable = () =>
|
|
1876
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1877
|
+
foo: true,
|
|
1878
|
+
});
|
|
1879
|
+
expect(throwable).to.throw(
|
|
1840
1880
|
'The property "foo" of the model "model" must have ' +
|
|
1841
1881
|
'an Object, but Boolean given.',
|
|
1842
1882
|
);
|
|
1843
1883
|
});
|
|
1844
1884
|
|
|
1845
|
-
it('throws an error if false given',
|
|
1885
|
+
it('throws an error if false given', function () {
|
|
1846
1886
|
const S = new Schema();
|
|
1847
1887
|
S.defineModel({
|
|
1848
1888
|
name: 'model',
|
|
@@ -1853,16 +1893,17 @@ describe('ModelDataValidator', function () {
|
|
|
1853
1893
|
},
|
|
1854
1894
|
},
|
|
1855
1895
|
});
|
|
1856
|
-
const
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1896
|
+
const throwable = () =>
|
|
1897
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1898
|
+
foo: false,
|
|
1899
|
+
});
|
|
1900
|
+
expect(throwable).to.throw(
|
|
1860
1901
|
'The property "foo" of the model "model" must have ' +
|
|
1861
1902
|
'an Object, but Boolean given.',
|
|
1862
1903
|
);
|
|
1863
1904
|
});
|
|
1864
1905
|
|
|
1865
|
-
it('throws an error if an array given',
|
|
1906
|
+
it('throws an error if an array given', function () {
|
|
1866
1907
|
const S = new Schema();
|
|
1867
1908
|
S.defineModel({
|
|
1868
1909
|
name: 'model',
|
|
@@ -1873,16 +1914,17 @@ describe('ModelDataValidator', function () {
|
|
|
1873
1914
|
},
|
|
1874
1915
|
},
|
|
1875
1916
|
});
|
|
1876
|
-
const
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1917
|
+
const throwable = () =>
|
|
1918
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1919
|
+
foo: [],
|
|
1920
|
+
});
|
|
1921
|
+
expect(throwable).to.throw(
|
|
1880
1922
|
'The property "foo" of the model "model" must have ' +
|
|
1881
1923
|
'an Object, but Array given.',
|
|
1882
1924
|
);
|
|
1883
1925
|
});
|
|
1884
1926
|
|
|
1885
|
-
it('does not throw an error if an object given',
|
|
1927
|
+
it('does not throw an error if an object given', function () {
|
|
1886
1928
|
const S = new Schema();
|
|
1887
1929
|
S.defineModel({
|
|
1888
1930
|
name: 'model',
|
|
@@ -1893,13 +1935,13 @@ describe('ModelDataValidator', function () {
|
|
|
1893
1935
|
},
|
|
1894
1936
|
},
|
|
1895
1937
|
});
|
|
1896
|
-
|
|
1938
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1897
1939
|
foo: {},
|
|
1898
1940
|
});
|
|
1899
1941
|
});
|
|
1900
1942
|
|
|
1901
1943
|
describe('the "model" option', function () {
|
|
1902
|
-
it('throws an error when the given object has an invalid model',
|
|
1944
|
+
it('throws an error when the given object has an invalid model', function () {
|
|
1903
1945
|
const S = new Schema();
|
|
1904
1946
|
S.defineModel({
|
|
1905
1947
|
name: 'modelA',
|
|
@@ -1917,19 +1959,17 @@ describe('ModelDataValidator', function () {
|
|
|
1917
1959
|
},
|
|
1918
1960
|
},
|
|
1919
1961
|
});
|
|
1920
|
-
const
|
|
1921
|
-
'modelB',
|
|
1922
|
-
{
|
|
1962
|
+
const throwable = () =>
|
|
1963
|
+
S.getService(ModelDataValidator).validate('modelB', {
|
|
1923
1964
|
bar: {foo: 10},
|
|
1924
|
-
}
|
|
1925
|
-
)
|
|
1926
|
-
await expect(promise).to.be.rejectedWith(
|
|
1965
|
+
});
|
|
1966
|
+
expect(throwable).to.throw(
|
|
1927
1967
|
'The property "foo" of the model "modelA" must have ' +
|
|
1928
1968
|
'a String, but Number given.',
|
|
1929
1969
|
);
|
|
1930
1970
|
});
|
|
1931
1971
|
|
|
1932
|
-
it('does not throw an error when the given object has a valid model',
|
|
1972
|
+
it('does not throw an error when the given object has a valid model', function () {
|
|
1933
1973
|
const S = new Schema();
|
|
1934
1974
|
S.defineModel({
|
|
1935
1975
|
name: 'modelA',
|
|
@@ -1947,7 +1987,7 @@ describe('ModelDataValidator', function () {
|
|
|
1947
1987
|
},
|
|
1948
1988
|
},
|
|
1949
1989
|
});
|
|
1950
|
-
|
|
1990
|
+
S.getService(ModelDataValidator).validate('modelB', {
|
|
1951
1991
|
bar: {foo: '10'},
|
|
1952
1992
|
});
|
|
1953
1993
|
});
|
|
@@ -1958,10 +1998,10 @@ describe('ModelDataValidator', function () {
|
|
|
1958
1998
|
|
|
1959
1999
|
describe('validate by property validators', function () {
|
|
1960
2000
|
describe('the option "validate" with the string value', function () {
|
|
1961
|
-
it('do not validate null and undefined values',
|
|
2001
|
+
it('do not validate null and undefined values', function () {
|
|
1962
2002
|
const S = new Schema();
|
|
1963
2003
|
S.getService(PropertyValidatorRegistry).addValidator(
|
|
1964
|
-
'
|
|
2004
|
+
'myValidator',
|
|
1965
2005
|
() => false,
|
|
1966
2006
|
);
|
|
1967
2007
|
S.defineModel({
|
|
@@ -1969,52 +2009,53 @@ describe('ModelDataValidator', function () {
|
|
|
1969
2009
|
properties: {
|
|
1970
2010
|
foo: {
|
|
1971
2011
|
type: DataType.ANY,
|
|
1972
|
-
validate: '
|
|
2012
|
+
validate: 'myValidator',
|
|
1973
2013
|
},
|
|
1974
2014
|
bar: {
|
|
1975
2015
|
type: DataType.ANY,
|
|
1976
|
-
validate: '
|
|
2016
|
+
validate: 'myValidator',
|
|
1977
2017
|
},
|
|
1978
2018
|
baz: {
|
|
1979
2019
|
type: DataType.ANY,
|
|
1980
|
-
validate: '
|
|
2020
|
+
validate: 'myValidator',
|
|
1981
2021
|
},
|
|
1982
2022
|
},
|
|
1983
2023
|
});
|
|
1984
|
-
|
|
2024
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
1985
2025
|
foo: null,
|
|
1986
2026
|
bar: undefined,
|
|
1987
2027
|
});
|
|
1988
2028
|
});
|
|
1989
2029
|
|
|
1990
|
-
it('throws an error from the validator',
|
|
1991
|
-
const
|
|
2030
|
+
it('throws an error from the validator', function () {
|
|
2031
|
+
const myValidator = function () {
|
|
1992
2032
|
throw Error('My error');
|
|
1993
2033
|
};
|
|
1994
2034
|
const S = new Schema();
|
|
1995
2035
|
S.getService(PropertyValidatorRegistry).addValidator(
|
|
1996
|
-
'
|
|
1997
|
-
|
|
2036
|
+
'myValidator',
|
|
2037
|
+
myValidator,
|
|
1998
2038
|
);
|
|
1999
2039
|
S.defineModel({
|
|
2000
2040
|
name: 'model',
|
|
2001
2041
|
properties: {
|
|
2002
2042
|
foo: {
|
|
2003
2043
|
type: DataType.ANY,
|
|
2004
|
-
validate: '
|
|
2044
|
+
validate: 'myValidator',
|
|
2005
2045
|
},
|
|
2006
2046
|
},
|
|
2007
2047
|
});
|
|
2008
|
-
const
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2048
|
+
const throwable = () =>
|
|
2049
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
2050
|
+
foo: 'test',
|
|
2051
|
+
});
|
|
2052
|
+
expect(throwable).to.throw('My error');
|
|
2012
2053
|
});
|
|
2013
2054
|
|
|
2014
|
-
it('allows the given value if the validator returns true',
|
|
2055
|
+
it('allows the given value if the validator returns true', function () {
|
|
2015
2056
|
const S = new Schema();
|
|
2016
2057
|
S.getService(PropertyValidatorRegistry).addValidator(
|
|
2017
|
-
'
|
|
2058
|
+
'myValidator',
|
|
2018
2059
|
() => true,
|
|
2019
2060
|
);
|
|
2020
2061
|
S.defineModel({
|
|
@@ -2022,19 +2063,19 @@ describe('ModelDataValidator', function () {
|
|
|
2022
2063
|
properties: {
|
|
2023
2064
|
foo: {
|
|
2024
2065
|
type: DataType.ANY,
|
|
2025
|
-
validate: '
|
|
2066
|
+
validate: 'myValidator',
|
|
2026
2067
|
},
|
|
2027
2068
|
},
|
|
2028
2069
|
});
|
|
2029
|
-
|
|
2070
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
2030
2071
|
foo: 'test',
|
|
2031
2072
|
});
|
|
2032
2073
|
});
|
|
2033
2074
|
|
|
2034
|
-
it('
|
|
2075
|
+
it('throws an error if the validator returns a promise', function () {
|
|
2035
2076
|
const S = new Schema();
|
|
2036
2077
|
S.getService(PropertyValidatorRegistry).addValidator(
|
|
2037
|
-
'
|
|
2078
|
+
'myValidator',
|
|
2038
2079
|
() => Promise.resolve(true),
|
|
2039
2080
|
);
|
|
2040
2081
|
S.defineModel({
|
|
@@ -2042,20 +2083,25 @@ describe('ModelDataValidator', function () {
|
|
|
2042
2083
|
properties: {
|
|
2043
2084
|
foo: {
|
|
2044
2085
|
type: DataType.ANY,
|
|
2045
|
-
validate: '
|
|
2086
|
+
validate: 'myValidator',
|
|
2046
2087
|
},
|
|
2047
2088
|
},
|
|
2048
2089
|
});
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2090
|
+
const throwable = () =>
|
|
2091
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
2092
|
+
foo: 'test',
|
|
2093
|
+
});
|
|
2094
|
+
expect(throwable).to.throw(
|
|
2095
|
+
'Asynchronous property validators are not supported, ' +
|
|
2096
|
+
'but the property validator "myValidator" returns a Promise.',
|
|
2097
|
+
);
|
|
2052
2098
|
});
|
|
2053
2099
|
|
|
2054
|
-
it('throws an error for non-true result from the validator',
|
|
2055
|
-
const testFn =
|
|
2100
|
+
it('throws an error for non-true result from the validator', function () {
|
|
2101
|
+
const testFn = v => {
|
|
2056
2102
|
const S = new Schema();
|
|
2057
2103
|
S.getService(PropertyValidatorRegistry).addValidator(
|
|
2058
|
-
'
|
|
2104
|
+
'myValidator',
|
|
2059
2105
|
() => v,
|
|
2060
2106
|
);
|
|
2061
2107
|
S.defineModel({
|
|
@@ -2063,124 +2109,93 @@ describe('ModelDataValidator', function () {
|
|
|
2063
2109
|
properties: {
|
|
2064
2110
|
foo: {
|
|
2065
2111
|
type: DataType.ANY,
|
|
2066
|
-
validate: '
|
|
2112
|
+
validate: 'myValidator',
|
|
2067
2113
|
},
|
|
2068
2114
|
},
|
|
2069
2115
|
});
|
|
2070
|
-
const
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2116
|
+
const throwable = () =>
|
|
2117
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
2118
|
+
foo: 'test',
|
|
2119
|
+
});
|
|
2120
|
+
expect(throwable).to.throw(
|
|
2074
2121
|
'The property "foo" of the model "model" has an invalid value "test" ' +
|
|
2075
|
-
'that caught by the validator "
|
|
2122
|
+
'that caught by the validator "myValidator".',
|
|
2076
2123
|
);
|
|
2077
2124
|
};
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2125
|
+
testFn('str');
|
|
2126
|
+
testFn('');
|
|
2127
|
+
testFn(10);
|
|
2128
|
+
testFn(0);
|
|
2129
|
+
testFn(false);
|
|
2130
|
+
testFn(undefined);
|
|
2131
|
+
testFn(null);
|
|
2132
|
+
testFn({});
|
|
2133
|
+
testFn([]);
|
|
2134
|
+
testFn(() => undefined);
|
|
2088
2135
|
});
|
|
2089
2136
|
|
|
2090
|
-
it('passes arguments to the validator',
|
|
2137
|
+
it('passes arguments to the validator', function () {
|
|
2091
2138
|
let validated = false;
|
|
2092
2139
|
const S = new Schema();
|
|
2093
|
-
const
|
|
2140
|
+
const myValidator = function (value, options, context) {
|
|
2094
2141
|
expect(value).to.be.eq('test');
|
|
2095
2142
|
expect(options).to.be.undefined;
|
|
2096
2143
|
expect(context).to.be.eql({
|
|
2097
|
-
validatorName: '
|
|
2144
|
+
validatorName: 'myValidator',
|
|
2098
2145
|
modelName: 'model',
|
|
2099
2146
|
propName: 'foo',
|
|
2100
|
-
propDef: {
|
|
2101
|
-
type: DataType.ANY,
|
|
2102
|
-
validate: 'validator',
|
|
2103
|
-
},
|
|
2104
|
-
container: S.container,
|
|
2105
2147
|
});
|
|
2106
2148
|
validated = true;
|
|
2107
2149
|
return true;
|
|
2108
2150
|
};
|
|
2109
2151
|
S.getService(PropertyValidatorRegistry).addValidator(
|
|
2110
|
-
'
|
|
2111
|
-
|
|
2152
|
+
'myValidator',
|
|
2153
|
+
myValidator,
|
|
2112
2154
|
);
|
|
2113
2155
|
S.defineModel({
|
|
2114
2156
|
name: 'model',
|
|
2115
2157
|
properties: {
|
|
2116
2158
|
foo: {
|
|
2117
2159
|
type: DataType.ANY,
|
|
2118
|
-
validate: '
|
|
2160
|
+
validate: 'myValidator',
|
|
2119
2161
|
},
|
|
2120
2162
|
},
|
|
2121
2163
|
});
|
|
2122
|
-
|
|
2164
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
2123
2165
|
foo: 'test',
|
|
2124
2166
|
});
|
|
2125
2167
|
expect(validated).to.be.true;
|
|
2126
2168
|
});
|
|
2127
2169
|
|
|
2128
|
-
it('invokes the validator only once per value',
|
|
2170
|
+
it('invokes the validator only once per value', function () {
|
|
2129
2171
|
let invoked = 0;
|
|
2130
|
-
const
|
|
2172
|
+
const myValidator = function () {
|
|
2131
2173
|
invoked++;
|
|
2132
2174
|
return true;
|
|
2133
2175
|
};
|
|
2134
2176
|
const S = new Schema();
|
|
2135
2177
|
S.getService(PropertyValidatorRegistry).addValidator(
|
|
2136
|
-
'
|
|
2137
|
-
|
|
2178
|
+
'myValidator',
|
|
2179
|
+
myValidator,
|
|
2138
2180
|
);
|
|
2139
2181
|
S.defineModel({
|
|
2140
2182
|
name: 'model',
|
|
2141
2183
|
properties: {
|
|
2142
2184
|
foo: {
|
|
2143
2185
|
type: DataType.ANY,
|
|
2144
|
-
validate: '
|
|
2186
|
+
validate: 'myValidator',
|
|
2145
2187
|
},
|
|
2146
2188
|
},
|
|
2147
2189
|
});
|
|
2148
|
-
|
|
2190
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
2149
2191
|
foo: 'test',
|
|
2150
2192
|
});
|
|
2151
2193
|
expect(invoked).to.be.eq(1);
|
|
2152
2194
|
});
|
|
2153
|
-
|
|
2154
|
-
it('waits rejection from an async validator', async function () {
|
|
2155
|
-
const error = new Error('My error');
|
|
2156
|
-
const validator = function () {
|
|
2157
|
-
return new Promise((resolve, reject) => {
|
|
2158
|
-
setTimeout(() => reject(error), 5);
|
|
2159
|
-
});
|
|
2160
|
-
};
|
|
2161
|
-
const S = new Schema();
|
|
2162
|
-
S.getService(PropertyValidatorRegistry).addValidator(
|
|
2163
|
-
'validator',
|
|
2164
|
-
validator,
|
|
2165
|
-
);
|
|
2166
|
-
S.defineModel({
|
|
2167
|
-
name: 'model',
|
|
2168
|
-
properties: {
|
|
2169
|
-
foo: {
|
|
2170
|
-
type: DataType.ANY,
|
|
2171
|
-
validate: 'validator',
|
|
2172
|
-
},
|
|
2173
|
-
},
|
|
2174
|
-
});
|
|
2175
|
-
const promise = S.getService(ModelDataValidator).validate('model', {
|
|
2176
|
-
foo: 'test',
|
|
2177
|
-
});
|
|
2178
|
-
await expect(promise).to.be.rejectedWith(error);
|
|
2179
|
-
});
|
|
2180
2195
|
});
|
|
2181
2196
|
|
|
2182
2197
|
describe('the option "validate" with an array value', function () {
|
|
2183
|
-
it('does nothing for an empty array validators',
|
|
2198
|
+
it('does nothing for an empty array validators', function () {
|
|
2184
2199
|
const S = new Schema();
|
|
2185
2200
|
S.defineModel({
|
|
2186
2201
|
name: 'model',
|
|
@@ -2191,15 +2206,15 @@ describe('ModelDataValidator', function () {
|
|
|
2191
2206
|
},
|
|
2192
2207
|
},
|
|
2193
2208
|
});
|
|
2194
|
-
|
|
2209
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
2195
2210
|
foo: 'test',
|
|
2196
2211
|
});
|
|
2197
2212
|
});
|
|
2198
2213
|
|
|
2199
|
-
it('do not validate null and undefined values',
|
|
2214
|
+
it('do not validate null and undefined values', function () {
|
|
2200
2215
|
const S = new Schema();
|
|
2201
2216
|
S.getService(PropertyValidatorRegistry).addValidator(
|
|
2202
|
-
'
|
|
2217
|
+
'myValidator',
|
|
2203
2218
|
() => false,
|
|
2204
2219
|
);
|
|
2205
2220
|
S.defineModel({
|
|
@@ -2207,221 +2222,194 @@ describe('ModelDataValidator', function () {
|
|
|
2207
2222
|
properties: {
|
|
2208
2223
|
foo: {
|
|
2209
2224
|
type: DataType.ANY,
|
|
2210
|
-
validate: ['
|
|
2225
|
+
validate: ['myValidator'],
|
|
2211
2226
|
},
|
|
2212
2227
|
bar: {
|
|
2213
2228
|
type: DataType.ANY,
|
|
2214
|
-
validate: ['
|
|
2229
|
+
validate: ['myValidator'],
|
|
2215
2230
|
},
|
|
2216
2231
|
baz: {
|
|
2217
2232
|
type: DataType.ANY,
|
|
2218
|
-
validate: ['
|
|
2233
|
+
validate: ['myValidator'],
|
|
2219
2234
|
},
|
|
2220
2235
|
},
|
|
2221
2236
|
});
|
|
2222
|
-
|
|
2237
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
2223
2238
|
foo: null,
|
|
2224
2239
|
bar: undefined,
|
|
2225
2240
|
});
|
|
2226
2241
|
});
|
|
2227
2242
|
|
|
2228
|
-
it('throws an error from the validator',
|
|
2229
|
-
const
|
|
2243
|
+
it('throws an error from the validator', function () {
|
|
2244
|
+
const myValidator = function () {
|
|
2230
2245
|
throw Error('My error');
|
|
2231
2246
|
};
|
|
2232
2247
|
const S = new Schema();
|
|
2233
2248
|
S.getService(PropertyValidatorRegistry).addValidator(
|
|
2234
|
-
'
|
|
2235
|
-
|
|
2249
|
+
'myValidator',
|
|
2250
|
+
myValidator,
|
|
2236
2251
|
);
|
|
2237
2252
|
S.defineModel({
|
|
2238
2253
|
name: 'model',
|
|
2239
2254
|
properties: {
|
|
2240
2255
|
foo: {
|
|
2241
2256
|
type: DataType.ANY,
|
|
2242
|
-
validate: ['
|
|
2257
|
+
validate: ['myValidator'],
|
|
2243
2258
|
},
|
|
2244
2259
|
},
|
|
2245
2260
|
});
|
|
2246
|
-
const
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2261
|
+
const throwable = () =>
|
|
2262
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
2263
|
+
foo: 'test',
|
|
2264
|
+
});
|
|
2265
|
+
expect(throwable).to.throw('My error');
|
|
2250
2266
|
});
|
|
2251
2267
|
|
|
2252
|
-
it('allows the given value if validators returns true',
|
|
2268
|
+
it('allows the given value if validators returns true', function () {
|
|
2253
2269
|
const S = new Schema();
|
|
2254
2270
|
S.getService(PropertyValidatorRegistry)
|
|
2255
|
-
.addValidator('
|
|
2256
|
-
.addValidator('
|
|
2271
|
+
.addValidator('myValidator1', () => true)
|
|
2272
|
+
.addValidator('myValidator2', () => true);
|
|
2257
2273
|
S.defineModel({
|
|
2258
2274
|
name: 'model',
|
|
2259
2275
|
properties: {
|
|
2260
2276
|
foo: {
|
|
2261
2277
|
type: DataType.ANY,
|
|
2262
|
-
validate: ['
|
|
2278
|
+
validate: ['myValidator1', 'myValidator2'],
|
|
2263
2279
|
},
|
|
2264
2280
|
},
|
|
2265
2281
|
});
|
|
2266
|
-
|
|
2282
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
2267
2283
|
foo: 'test',
|
|
2268
2284
|
});
|
|
2269
2285
|
});
|
|
2270
2286
|
|
|
2271
|
-
it('
|
|
2287
|
+
it('throws an error if the validator returns a promise', function () {
|
|
2272
2288
|
const S = new Schema();
|
|
2273
|
-
S.getService(PropertyValidatorRegistry)
|
|
2274
|
-
|
|
2275
|
-
|
|
2289
|
+
S.getService(PropertyValidatorRegistry).addValidator(
|
|
2290
|
+
'myValidator',
|
|
2291
|
+
() => Promise.resolve(true),
|
|
2292
|
+
);
|
|
2276
2293
|
S.defineModel({
|
|
2277
2294
|
name: 'model',
|
|
2278
2295
|
properties: {
|
|
2279
2296
|
foo: {
|
|
2280
2297
|
type: DataType.ANY,
|
|
2281
|
-
validate: ['
|
|
2298
|
+
validate: ['myValidator'],
|
|
2282
2299
|
},
|
|
2283
2300
|
},
|
|
2284
2301
|
});
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2302
|
+
const throwable = () =>
|
|
2303
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
2304
|
+
foo: 'test',
|
|
2305
|
+
});
|
|
2306
|
+
expect(throwable).to.throw(
|
|
2307
|
+
'Asynchronous property validators are not supported, ' +
|
|
2308
|
+
'but the property validator "myValidator" returns a Promise.',
|
|
2309
|
+
);
|
|
2288
2310
|
});
|
|
2289
2311
|
|
|
2290
|
-
it('throws an error by non-true result from one of validators',
|
|
2312
|
+
it('throws an error by non-true result from one of validators', function () {
|
|
2291
2313
|
const testFn = v => {
|
|
2292
2314
|
const S = new Schema();
|
|
2293
2315
|
S.getService(PropertyValidatorRegistry)
|
|
2294
|
-
.addValidator('
|
|
2295
|
-
.addValidator('
|
|
2316
|
+
.addValidator('myValidator1', () => true)
|
|
2317
|
+
.addValidator('myValidator2', () => v);
|
|
2296
2318
|
S.defineModel({
|
|
2297
2319
|
name: 'model',
|
|
2298
2320
|
properties: {
|
|
2299
2321
|
foo: {
|
|
2300
2322
|
type: DataType.ANY,
|
|
2301
|
-
validate: ['
|
|
2323
|
+
validate: ['myValidator1', 'myValidator2'],
|
|
2302
2324
|
},
|
|
2303
2325
|
},
|
|
2304
2326
|
});
|
|
2305
|
-
const
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2327
|
+
const throwable = () =>
|
|
2328
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
2329
|
+
foo: 'test',
|
|
2330
|
+
});
|
|
2331
|
+
expect(throwable).to.throw(
|
|
2309
2332
|
'The property "foo" of the model "model" has an invalid value "test" ' +
|
|
2310
|
-
'that caught by the validator "
|
|
2333
|
+
'that caught by the validator "myValidator2".',
|
|
2311
2334
|
);
|
|
2312
2335
|
};
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2336
|
+
testFn('str');
|
|
2337
|
+
testFn('');
|
|
2338
|
+
testFn(10);
|
|
2339
|
+
testFn(0);
|
|
2340
|
+
testFn(false);
|
|
2341
|
+
testFn(undefined);
|
|
2342
|
+
testFn(null);
|
|
2343
|
+
testFn({});
|
|
2344
|
+
testFn([]);
|
|
2345
|
+
testFn(() => undefined);
|
|
2323
2346
|
});
|
|
2324
2347
|
|
|
2325
|
-
it('passes arguments to the validator',
|
|
2348
|
+
it('passes arguments to the validator', function () {
|
|
2326
2349
|
let validated = false;
|
|
2327
2350
|
const S = new Schema();
|
|
2328
|
-
const
|
|
2351
|
+
const myValidator = function (value, options, context) {
|
|
2329
2352
|
expect(value).to.be.eq('test');
|
|
2330
2353
|
expect(options).to.be.undefined;
|
|
2331
2354
|
expect(context).to.be.eql({
|
|
2332
|
-
validatorName: '
|
|
2355
|
+
validatorName: 'myValidator',
|
|
2333
2356
|
modelName: 'model',
|
|
2334
2357
|
propName: 'foo',
|
|
2335
|
-
propDef: {
|
|
2336
|
-
type: DataType.ANY,
|
|
2337
|
-
validate: ['validator'],
|
|
2338
|
-
},
|
|
2339
|
-
container: S.container,
|
|
2340
2358
|
});
|
|
2341
2359
|
validated = true;
|
|
2342
2360
|
return true;
|
|
2343
2361
|
};
|
|
2344
2362
|
S.getService(PropertyValidatorRegistry).addValidator(
|
|
2345
|
-
'
|
|
2346
|
-
|
|
2363
|
+
'myValidator',
|
|
2364
|
+
myValidator,
|
|
2347
2365
|
);
|
|
2348
2366
|
S.defineModel({
|
|
2349
2367
|
name: 'model',
|
|
2350
2368
|
properties: {
|
|
2351
2369
|
foo: {
|
|
2352
2370
|
type: DataType.ANY,
|
|
2353
|
-
validate: ['
|
|
2371
|
+
validate: ['myValidator'],
|
|
2354
2372
|
},
|
|
2355
2373
|
},
|
|
2356
2374
|
});
|
|
2357
|
-
|
|
2375
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
2358
2376
|
foo: 'test',
|
|
2359
2377
|
});
|
|
2360
2378
|
expect(validated).to.be.true;
|
|
2361
2379
|
});
|
|
2362
2380
|
|
|
2363
|
-
it('invokes validators by the given order',
|
|
2381
|
+
it('invokes validators by the given order', function () {
|
|
2364
2382
|
const invocation = [];
|
|
2365
2383
|
const validator1 = function () {
|
|
2366
|
-
invocation.push('
|
|
2384
|
+
invocation.push('myValidator1');
|
|
2367
2385
|
return true;
|
|
2368
2386
|
};
|
|
2369
2387
|
const validator2 = function () {
|
|
2370
|
-
invocation.push('
|
|
2388
|
+
invocation.push('myValidator2');
|
|
2371
2389
|
return true;
|
|
2372
2390
|
};
|
|
2373
2391
|
const S = new Schema();
|
|
2374
2392
|
S.getService(PropertyValidatorRegistry)
|
|
2375
|
-
.addValidator('
|
|
2376
|
-
.addValidator('
|
|
2377
|
-
S.defineModel({
|
|
2378
|
-
name: 'model',
|
|
2379
|
-
properties: {
|
|
2380
|
-
foo: {
|
|
2381
|
-
type: DataType.ANY,
|
|
2382
|
-
validate: ['validator1', 'validator2'],
|
|
2383
|
-
},
|
|
2384
|
-
},
|
|
2385
|
-
});
|
|
2386
|
-
await S.getService(ModelDataValidator).validate('model', {
|
|
2387
|
-
foo: 'test',
|
|
2388
|
-
});
|
|
2389
|
-
expect(invocation).to.be.eql(['validator1', 'validator2']);
|
|
2390
|
-
});
|
|
2391
|
-
|
|
2392
|
-
it('waits rejection from one of async validators', async function () {
|
|
2393
|
-
const error1 = new Error('Occurs after 15 ms');
|
|
2394
|
-
const error2 = new Error('Occurs after 5 ms');
|
|
2395
|
-
const validator1 = () =>
|
|
2396
|
-
new Promise((res, rej) => {
|
|
2397
|
-
setTimeout(() => rej(error1), 15);
|
|
2398
|
-
});
|
|
2399
|
-
const validator2 = () =>
|
|
2400
|
-
new Promise((res, rej) => {
|
|
2401
|
-
setTimeout(() => rej(error2), 5);
|
|
2402
|
-
});
|
|
2403
|
-
const S = new Schema();
|
|
2404
|
-
S.getService(PropertyValidatorRegistry)
|
|
2405
|
-
.addValidator('validator1', validator1)
|
|
2406
|
-
.addValidator('validator2', validator2);
|
|
2393
|
+
.addValidator('myValidator1', validator1)
|
|
2394
|
+
.addValidator('myValidator2', validator2);
|
|
2407
2395
|
S.defineModel({
|
|
2408
2396
|
name: 'model',
|
|
2409
2397
|
properties: {
|
|
2410
2398
|
foo: {
|
|
2411
2399
|
type: DataType.ANY,
|
|
2412
|
-
validate: ['
|
|
2400
|
+
validate: ['myValidator1', 'myValidator2'],
|
|
2413
2401
|
},
|
|
2414
2402
|
},
|
|
2415
2403
|
});
|
|
2416
|
-
|
|
2404
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
2417
2405
|
foo: 'test',
|
|
2418
2406
|
});
|
|
2419
|
-
|
|
2407
|
+
expect(invocation).to.be.eql(['myValidator1', 'myValidator2']);
|
|
2420
2408
|
});
|
|
2421
2409
|
});
|
|
2422
2410
|
|
|
2423
2411
|
describe('the option "validate" with an object value', function () {
|
|
2424
|
-
it('does nothing for an empty validators object',
|
|
2412
|
+
it('does nothing for an empty validators object', function () {
|
|
2425
2413
|
const S = new Schema();
|
|
2426
2414
|
S.defineModel({
|
|
2427
2415
|
name: 'model',
|
|
@@ -2432,15 +2420,15 @@ describe('ModelDataValidator', function () {
|
|
|
2432
2420
|
},
|
|
2433
2421
|
},
|
|
2434
2422
|
});
|
|
2435
|
-
|
|
2423
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
2436
2424
|
foo: 'test',
|
|
2437
2425
|
});
|
|
2438
2426
|
});
|
|
2439
2427
|
|
|
2440
|
-
it('do not validate null and undefined values',
|
|
2428
|
+
it('do not validate null and undefined values', function () {
|
|
2441
2429
|
const S = new Schema();
|
|
2442
2430
|
S.getService(PropertyValidatorRegistry).addValidator(
|
|
2443
|
-
'
|
|
2431
|
+
'myValidator',
|
|
2444
2432
|
() => false,
|
|
2445
2433
|
);
|
|
2446
2434
|
S.defineModel({
|
|
@@ -2449,37 +2437,37 @@ describe('ModelDataValidator', function () {
|
|
|
2449
2437
|
foo: {
|
|
2450
2438
|
type: DataType.ANY,
|
|
2451
2439
|
validate: {
|
|
2452
|
-
|
|
2440
|
+
myValidator: true,
|
|
2453
2441
|
},
|
|
2454
2442
|
},
|
|
2455
2443
|
bar: {
|
|
2456
2444
|
type: DataType.ANY,
|
|
2457
2445
|
validate: {
|
|
2458
|
-
|
|
2446
|
+
myValidator: true,
|
|
2459
2447
|
},
|
|
2460
2448
|
},
|
|
2461
2449
|
baz: {
|
|
2462
2450
|
type: DataType.ANY,
|
|
2463
2451
|
validate: {
|
|
2464
|
-
|
|
2452
|
+
myValidator: true,
|
|
2465
2453
|
},
|
|
2466
2454
|
},
|
|
2467
2455
|
},
|
|
2468
2456
|
});
|
|
2469
|
-
|
|
2457
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
2470
2458
|
foo: null,
|
|
2471
2459
|
bar: undefined,
|
|
2472
2460
|
});
|
|
2473
2461
|
});
|
|
2474
2462
|
|
|
2475
|
-
it('throws an error from the validator',
|
|
2476
|
-
const
|
|
2463
|
+
it('throws an error from the validator', function () {
|
|
2464
|
+
const myValidator = function () {
|
|
2477
2465
|
throw Error('My error');
|
|
2478
2466
|
};
|
|
2479
2467
|
const S = new Schema();
|
|
2480
2468
|
S.getService(PropertyValidatorRegistry).addValidator(
|
|
2481
|
-
'
|
|
2482
|
-
|
|
2469
|
+
'myValidator',
|
|
2470
|
+
myValidator,
|
|
2483
2471
|
);
|
|
2484
2472
|
S.defineModel({
|
|
2485
2473
|
name: 'model',
|
|
@@ -2487,129 +2475,126 @@ describe('ModelDataValidator', function () {
|
|
|
2487
2475
|
foo: {
|
|
2488
2476
|
type: DataType.ANY,
|
|
2489
2477
|
validate: {
|
|
2490
|
-
|
|
2478
|
+
myValidator: true,
|
|
2491
2479
|
},
|
|
2492
2480
|
},
|
|
2493
2481
|
},
|
|
2494
2482
|
});
|
|
2495
|
-
const
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2483
|
+
const throwable = () =>
|
|
2484
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
2485
|
+
foo: 'test',
|
|
2486
|
+
});
|
|
2487
|
+
expect(throwable).to.throw('My error');
|
|
2499
2488
|
});
|
|
2500
2489
|
|
|
2501
|
-
it('allows the given value if validators returns true',
|
|
2490
|
+
it('allows the given value if validators returns true', function () {
|
|
2502
2491
|
const S = new Schema();
|
|
2503
2492
|
S.getService(PropertyValidatorRegistry)
|
|
2504
|
-
.addValidator('
|
|
2505
|
-
.addValidator('
|
|
2493
|
+
.addValidator('myValidator1', () => true)
|
|
2494
|
+
.addValidator('myValidator2', () => true);
|
|
2506
2495
|
S.defineModel({
|
|
2507
2496
|
name: 'model',
|
|
2508
2497
|
properties: {
|
|
2509
2498
|
foo: {
|
|
2510
2499
|
type: DataType.ANY,
|
|
2511
2500
|
validate: {
|
|
2512
|
-
|
|
2513
|
-
|
|
2501
|
+
myValidator1: true,
|
|
2502
|
+
myValidator2: true,
|
|
2514
2503
|
},
|
|
2515
2504
|
},
|
|
2516
2505
|
},
|
|
2517
2506
|
});
|
|
2518
|
-
|
|
2507
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
2519
2508
|
foo: 'test',
|
|
2520
2509
|
});
|
|
2521
2510
|
});
|
|
2522
2511
|
|
|
2523
|
-
it('
|
|
2512
|
+
it('throws an error if the validator returns a promise', function () {
|
|
2524
2513
|
const S = new Schema();
|
|
2525
|
-
S.getService(PropertyValidatorRegistry)
|
|
2526
|
-
|
|
2527
|
-
|
|
2514
|
+
S.getService(PropertyValidatorRegistry).addValidator(
|
|
2515
|
+
'myValidator',
|
|
2516
|
+
() => Promise.resolve(true),
|
|
2517
|
+
);
|
|
2528
2518
|
S.defineModel({
|
|
2529
2519
|
name: 'model',
|
|
2530
2520
|
properties: {
|
|
2531
2521
|
foo: {
|
|
2532
2522
|
type: DataType.ANY,
|
|
2533
2523
|
validate: {
|
|
2534
|
-
|
|
2535
|
-
validator2: true,
|
|
2524
|
+
myValidator: true,
|
|
2536
2525
|
},
|
|
2537
2526
|
},
|
|
2538
2527
|
},
|
|
2539
2528
|
});
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2529
|
+
const throwable = () =>
|
|
2530
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
2531
|
+
foo: 'test',
|
|
2532
|
+
});
|
|
2533
|
+
expect(throwable).to.throw(
|
|
2534
|
+
'Asynchronous property validators are not supported, ' +
|
|
2535
|
+
'but the property validator "myValidator" returns a Promise.',
|
|
2536
|
+
);
|
|
2543
2537
|
});
|
|
2544
2538
|
|
|
2545
|
-
it('throws an error by non-true result from one of validators',
|
|
2539
|
+
it('throws an error by non-true result from one of validators', function () {
|
|
2546
2540
|
const testFn = v => {
|
|
2547
2541
|
const S = new Schema();
|
|
2548
2542
|
S.getService(PropertyValidatorRegistry)
|
|
2549
|
-
.addValidator('
|
|
2550
|
-
.addValidator('
|
|
2543
|
+
.addValidator('myValidator1', () => true)
|
|
2544
|
+
.addValidator('myValidator2', () => v);
|
|
2551
2545
|
S.defineModel({
|
|
2552
2546
|
name: 'model',
|
|
2553
2547
|
properties: {
|
|
2554
2548
|
foo: {
|
|
2555
2549
|
type: DataType.ANY,
|
|
2556
2550
|
validate: {
|
|
2557
|
-
|
|
2558
|
-
|
|
2551
|
+
myValidator1: true,
|
|
2552
|
+
myValidator2: true,
|
|
2559
2553
|
},
|
|
2560
2554
|
},
|
|
2561
2555
|
},
|
|
2562
2556
|
});
|
|
2563
|
-
const
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2557
|
+
const throwable = () =>
|
|
2558
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
2559
|
+
foo: 'test',
|
|
2560
|
+
});
|
|
2561
|
+
expect(throwable).to.throw(
|
|
2567
2562
|
'The property "foo" of the model "model" has an invalid value "test" ' +
|
|
2568
|
-
'that caught by the validator "
|
|
2563
|
+
'that caught by the validator "myValidator2".',
|
|
2569
2564
|
);
|
|
2570
2565
|
};
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2566
|
+
testFn('str');
|
|
2567
|
+
testFn('');
|
|
2568
|
+
testFn(10);
|
|
2569
|
+
testFn(0);
|
|
2570
|
+
testFn(false);
|
|
2571
|
+
testFn(undefined);
|
|
2572
|
+
testFn(null);
|
|
2573
|
+
testFn({});
|
|
2574
|
+
testFn([]);
|
|
2575
|
+
testFn(() => undefined);
|
|
2581
2576
|
});
|
|
2582
2577
|
|
|
2583
|
-
it('passes arguments to the validator',
|
|
2578
|
+
it('passes arguments to the validator', function () {
|
|
2584
2579
|
let validated = false;
|
|
2585
2580
|
const S = new Schema();
|
|
2586
|
-
const
|
|
2581
|
+
const myValidator = function (value, options, context) {
|
|
2587
2582
|
expect(value).to.be.eq('test');
|
|
2588
2583
|
expect(options).to.be.eql({
|
|
2589
2584
|
option1: 'value1',
|
|
2590
2585
|
option2: 'value2',
|
|
2591
2586
|
});
|
|
2592
2587
|
expect(context).to.be.eql({
|
|
2593
|
-
validatorName: '
|
|
2588
|
+
validatorName: 'myValidator',
|
|
2594
2589
|
modelName: 'model',
|
|
2595
2590
|
propName: 'foo',
|
|
2596
|
-
propDef: {
|
|
2597
|
-
type: DataType.ANY,
|
|
2598
|
-
validate: {
|
|
2599
|
-
validator: {
|
|
2600
|
-
option1: 'value1',
|
|
2601
|
-
option2: 'value2',
|
|
2602
|
-
},
|
|
2603
|
-
},
|
|
2604
|
-
},
|
|
2605
|
-
container: S.container,
|
|
2606
2591
|
});
|
|
2607
2592
|
validated = true;
|
|
2608
2593
|
return true;
|
|
2609
2594
|
};
|
|
2610
2595
|
S.getService(PropertyValidatorRegistry).addValidator(
|
|
2611
|
-
'
|
|
2612
|
-
|
|
2596
|
+
'myValidator',
|
|
2597
|
+
myValidator,
|
|
2613
2598
|
);
|
|
2614
2599
|
S.defineModel({
|
|
2615
2600
|
name: 'model',
|
|
@@ -2617,7 +2602,7 @@ describe('ModelDataValidator', function () {
|
|
|
2617
2602
|
foo: {
|
|
2618
2603
|
type: DataType.ANY,
|
|
2619
2604
|
validate: {
|
|
2620
|
-
|
|
2605
|
+
myValidator: {
|
|
2621
2606
|
option1: 'value1',
|
|
2622
2607
|
option2: 'value2',
|
|
2623
2608
|
},
|
|
@@ -2625,54 +2610,54 @@ describe('ModelDataValidator', function () {
|
|
|
2625
2610
|
},
|
|
2626
2611
|
},
|
|
2627
2612
|
});
|
|
2628
|
-
|
|
2613
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
2629
2614
|
foo: 'test',
|
|
2630
2615
|
});
|
|
2631
2616
|
expect(validated).to.be.true;
|
|
2632
2617
|
});
|
|
2633
2618
|
|
|
2634
|
-
it('invokes validators by the given order',
|
|
2619
|
+
it('invokes validators by the given order', function () {
|
|
2635
2620
|
const invocation = [];
|
|
2636
2621
|
const validator1 = function () {
|
|
2637
|
-
invocation.push('
|
|
2622
|
+
invocation.push('myValidator1');
|
|
2638
2623
|
return true;
|
|
2639
2624
|
};
|
|
2640
2625
|
const validator2 = function () {
|
|
2641
|
-
invocation.push('
|
|
2626
|
+
invocation.push('myValidator2');
|
|
2642
2627
|
return true;
|
|
2643
2628
|
};
|
|
2644
2629
|
const S = new Schema();
|
|
2645
2630
|
S.getService(PropertyValidatorRegistry)
|
|
2646
|
-
.addValidator('
|
|
2647
|
-
.addValidator('
|
|
2631
|
+
.addValidator('myValidator1', validator1)
|
|
2632
|
+
.addValidator('myValidator2', validator2);
|
|
2648
2633
|
S.defineModel({
|
|
2649
2634
|
name: 'model',
|
|
2650
2635
|
properties: {
|
|
2651
2636
|
foo: {
|
|
2652
2637
|
type: DataType.ANY,
|
|
2653
2638
|
validate: {
|
|
2654
|
-
|
|
2655
|
-
|
|
2639
|
+
myValidator1: true,
|
|
2640
|
+
myValidator2: true,
|
|
2656
2641
|
},
|
|
2657
2642
|
},
|
|
2658
2643
|
},
|
|
2659
2644
|
});
|
|
2660
|
-
|
|
2645
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
2661
2646
|
foo: 'test',
|
|
2662
2647
|
});
|
|
2663
|
-
expect(invocation).to.be.eql(['
|
|
2648
|
+
expect(invocation).to.be.eql(['myValidator1', 'myValidator2']);
|
|
2664
2649
|
});
|
|
2665
2650
|
|
|
2666
|
-
it('validates even the validator options is false',
|
|
2651
|
+
it('validates even the validator options is false', function () {
|
|
2667
2652
|
let validated = false;
|
|
2668
|
-
const
|
|
2653
|
+
const myValidator = function () {
|
|
2669
2654
|
validated = true;
|
|
2670
2655
|
return true;
|
|
2671
2656
|
};
|
|
2672
2657
|
const S = new Schema();
|
|
2673
2658
|
S.getService(PropertyValidatorRegistry).addValidator(
|
|
2674
|
-
'
|
|
2675
|
-
|
|
2659
|
+
'myValidator',
|
|
2660
|
+
myValidator,
|
|
2676
2661
|
);
|
|
2677
2662
|
S.defineModel({
|
|
2678
2663
|
name: 'model',
|
|
@@ -2680,49 +2665,16 @@ describe('ModelDataValidator', function () {
|
|
|
2680
2665
|
foo: {
|
|
2681
2666
|
type: DataType.ANY,
|
|
2682
2667
|
validate: {
|
|
2683
|
-
|
|
2668
|
+
myValidator: false,
|
|
2684
2669
|
},
|
|
2685
2670
|
},
|
|
2686
2671
|
},
|
|
2687
2672
|
});
|
|
2688
|
-
|
|
2673
|
+
S.getService(ModelDataValidator).validate('model', {
|
|
2689
2674
|
foo: 'test',
|
|
2690
2675
|
});
|
|
2691
2676
|
expect(validated).to.be.true;
|
|
2692
2677
|
});
|
|
2693
|
-
|
|
2694
|
-
it('waits rejection from one of async validators', async function () {
|
|
2695
|
-
const error1 = new Error('Occurs after 15 ms');
|
|
2696
|
-
const error2 = new Error('Occurs after 5 ms');
|
|
2697
|
-
const validator1 = () =>
|
|
2698
|
-
new Promise((res, rej) => {
|
|
2699
|
-
setTimeout(() => rej(error1), 15);
|
|
2700
|
-
});
|
|
2701
|
-
const validator2 = () =>
|
|
2702
|
-
new Promise((res, rej) => {
|
|
2703
|
-
setTimeout(() => rej(error2), 5);
|
|
2704
|
-
});
|
|
2705
|
-
const S = new Schema();
|
|
2706
|
-
S.getService(PropertyValidatorRegistry)
|
|
2707
|
-
.addValidator('validator1', validator1)
|
|
2708
|
-
.addValidator('validator2', validator2);
|
|
2709
|
-
S.defineModel({
|
|
2710
|
-
name: 'model',
|
|
2711
|
-
properties: {
|
|
2712
|
-
foo: {
|
|
2713
|
-
type: DataType.ANY,
|
|
2714
|
-
validate: {
|
|
2715
|
-
validator1: true,
|
|
2716
|
-
validator2: true,
|
|
2717
|
-
},
|
|
2718
|
-
},
|
|
2719
|
-
},
|
|
2720
|
-
});
|
|
2721
|
-
const promise = S.getService(ModelDataValidator).validate('model', {
|
|
2722
|
-
foo: 'test',
|
|
2723
|
-
});
|
|
2724
|
-
await expect(promise).to.be.rejectedWith(error2);
|
|
2725
|
-
});
|
|
2726
2678
|
});
|
|
2727
2679
|
});
|
|
2728
2680
|
});
|