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