@e22m4u/js-repository 0.1.4 → 0.1.5

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.
@@ -174,1780 +174,1782 @@ describe('ModelDataValidator', function () {
174
174
  });
175
175
  });
176
176
 
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,
177
+ describe('validate by property type', function () {
178
+ describe('DataType.ANY', function () {
179
+ describe('ShortPropertyDefinition', function () {
180
+ it('does not throw an error if an undefined given', async function () {
181
+ const S = new Schema();
182
+ S.defineModel({
183
+ name: 'model',
184
+ datasource: 'datasource',
185
+ properties: {
186
+ foo: DataType.ANY,
187
+ },
188
+ });
189
+ await S.getService(ModelDataValidator).validate('model', {
190
+ foo: undefined,
191
+ });
190
192
  });
191
- });
192
193
 
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,
194
+ it('does not throw an error if a null given', async function () {
195
+ const S = new Schema();
196
+ S.defineModel({
197
+ name: 'model',
198
+ datasource: 'datasource',
199
+ properties: {
200
+ foo: DataType.ANY,
201
+ },
202
+ });
203
+ await S.getService(ModelDataValidator).validate('model', {
204
+ foo: null,
205
+ });
204
206
  });
205
- });
206
207
 
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',
208
+ it('does not throw an error if a string given', async function () {
209
+ const S = new Schema();
210
+ S.defineModel({
211
+ name: 'model',
212
+ datasource: 'datasource',
213
+ properties: {
214
+ foo: DataType.ANY,
215
+ },
216
+ });
217
+ await S.getService(ModelDataValidator).validate('model', {
218
+ foo: 'bar',
219
+ });
218
220
  });
219
- });
220
221
 
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,
222
+ it('does not throw an error if a number given', async function () {
223
+ const S = new Schema();
224
+ S.defineModel({
225
+ name: 'model',
226
+ datasource: 'datasource',
227
+ properties: {
228
+ foo: DataType.ANY,
229
+ },
230
+ });
231
+ await S.getService(ModelDataValidator).validate('model', {
232
+ foo: 10,
233
+ });
232
234
  });
233
- });
234
235
 
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,
236
+ it('does not throw an error if true given', async function () {
237
+ const S = new Schema();
238
+ S.defineModel({
239
+ name: 'model',
240
+ datasource: 'datasource',
241
+ properties: {
242
+ foo: DataType.ANY,
243
+ },
244
+ });
245
+ await S.getService(ModelDataValidator).validate('model', {
246
+ foo: true,
247
+ });
246
248
  });
247
- });
248
249
 
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,
250
+ it('does not throw an error if false given', async function () {
251
+ const S = new Schema();
252
+ S.defineModel({
253
+ name: 'model',
254
+ datasource: 'datasource',
255
+ properties: {
256
+ foo: DataType.ANY,
257
+ },
258
+ });
259
+ await S.getService(ModelDataValidator).validate('model', {
260
+ foo: false,
261
+ });
260
262
  });
261
- });
262
263
 
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: [],
264
+ it('does not throw an error if an array given', async function () {
265
+ const S = new Schema();
266
+ S.defineModel({
267
+ name: 'model',
268
+ datasource: 'datasource',
269
+ properties: {
270
+ foo: DataType.ANY,
271
+ },
272
+ });
273
+ await S.getService(ModelDataValidator).validate('model', {
274
+ foo: [],
275
+ });
274
276
  });
275
- });
276
277
 
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: {},
278
+ it('does not throw an error if an object given', async function () {
279
+ const S = new Schema();
280
+ S.defineModel({
281
+ name: 'model',
282
+ datasource: 'datasource',
283
+ properties: {
284
+ foo: DataType.ANY,
285
+ },
286
+ });
287
+ await S.getService(ModelDataValidator).validate('model', {
288
+ foo: {},
289
+ });
288
290
  });
289
291
  });
290
- });
291
292
 
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,
293
+ describe('FullPropertyDefinition', function () {
294
+ it('does not throw an error if an undefined given', async function () {
295
+ const S = new Schema();
296
+ S.defineModel({
297
+ name: 'model',
298
+ datasource: 'datasource',
299
+ properties: {
300
+ foo: {
301
+ type: DataType.ANY,
302
+ },
301
303
  },
302
- },
303
- });
304
- await S.getService(ModelDataValidator).validate('model', {
305
- foo: undefined,
304
+ });
305
+ await S.getService(ModelDataValidator).validate('model', {
306
+ foo: undefined,
307
+ });
306
308
  });
307
- });
308
309
 
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,
310
+ it('does not throw an error if a null given', async function () {
311
+ const S = new Schema();
312
+ S.defineModel({
313
+ name: 'model',
314
+ datasource: 'datasource',
315
+ properties: {
316
+ foo: {
317
+ type: DataType.ANY,
318
+ },
317
319
  },
318
- },
319
- });
320
- await S.getService(ModelDataValidator).validate('model', {
321
- foo: null,
320
+ });
321
+ await S.getService(ModelDataValidator).validate('model', {
322
+ foo: null,
323
+ });
322
324
  });
323
- });
324
325
 
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,
326
+ it('does not throw an error if a string given', async function () {
327
+ const S = new Schema();
328
+ S.defineModel({
329
+ name: 'model',
330
+ datasource: 'datasource',
331
+ properties: {
332
+ foo: {
333
+ type: DataType.ANY,
334
+ },
333
335
  },
334
- },
335
- });
336
- await S.getService(ModelDataValidator).validate('model', {
337
- foo: 'bar',
336
+ });
337
+ await S.getService(ModelDataValidator).validate('model', {
338
+ foo: 'bar',
339
+ });
338
340
  });
339
- });
340
341
 
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,
342
+ it('does not throw an error if a number given', async function () {
343
+ const S = new Schema();
344
+ S.defineModel({
345
+ name: 'model',
346
+ datasource: 'datasource',
347
+ properties: {
348
+ foo: {
349
+ type: DataType.ANY,
350
+ },
349
351
  },
350
- },
351
- });
352
- await S.getService(ModelDataValidator).validate('model', {
353
- foo: 10,
352
+ });
353
+ await S.getService(ModelDataValidator).validate('model', {
354
+ foo: 10,
355
+ });
354
356
  });
355
- });
356
357
 
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,
358
+ it('does not throw an error if true given', async function () {
359
+ const S = new Schema();
360
+ S.defineModel({
361
+ name: 'model',
362
+ datasource: 'datasource',
363
+ properties: {
364
+ foo: {
365
+ type: DataType.ANY,
366
+ },
365
367
  },
366
- },
367
- });
368
- await S.getService(ModelDataValidator).validate('model', {
369
- foo: true,
368
+ });
369
+ await S.getService(ModelDataValidator).validate('model', {
370
+ foo: true,
371
+ });
370
372
  });
371
- });
372
373
 
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,
374
+ it('does not throw an error if false given', async function () {
375
+ const S = new Schema();
376
+ S.defineModel({
377
+ name: 'model',
378
+ datasource: 'datasource',
379
+ properties: {
380
+ foo: {
381
+ type: DataType.ANY,
382
+ },
381
383
  },
382
- },
383
- });
384
- await S.getService(ModelDataValidator).validate('model', {
385
- foo: false,
384
+ });
385
+ await S.getService(ModelDataValidator).validate('model', {
386
+ foo: false,
387
+ });
386
388
  });
387
- });
388
389
 
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,
390
+ it('does not throw an error if an array given', async function () {
391
+ const S = new Schema();
392
+ S.defineModel({
393
+ name: 'model',
394
+ datasource: 'datasource',
395
+ properties: {
396
+ foo: {
397
+ type: DataType.ANY,
398
+ },
397
399
  },
398
- },
399
- });
400
- await S.getService(ModelDataValidator).validate('model', {
401
- foo: [],
400
+ });
401
+ await S.getService(ModelDataValidator).validate('model', {
402
+ foo: [],
403
+ });
402
404
  });
403
- });
404
405
 
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,
406
+ it('does not throw an error if an object given', async function () {
407
+ const S = new Schema();
408
+ S.defineModel({
409
+ name: 'model',
410
+ datasource: 'datasource',
411
+ properties: {
412
+ foo: {
413
+ type: DataType.ANY,
414
+ },
413
415
  },
414
- },
415
- });
416
- await S.getService(ModelDataValidator).validate('model', {
417
- foo: {},
416
+ });
417
+ await S.getService(ModelDataValidator).validate('model', {
418
+ foo: {},
419
+ });
418
420
  });
419
421
  });
420
422
  });
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
423
 
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,
424
+ describe('DataType.STRING', function () {
425
+ describe('ShortPropertyDefinition', function () {
426
+ it('does not throw an error if an undefined given', async function () {
427
+ const S = new Schema();
428
+ S.defineModel({
429
+ name: 'model',
430
+ datasource: 'datasource',
431
+ properties: {
432
+ foo: DataType.STRING,
433
+ },
434
+ });
435
+ await S.getService(ModelDataValidator).validate('model', {
436
+ foo: undefined,
437
+ });
450
438
  });
451
- });
452
439
 
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',
440
+ it('does not throw an error if a null given', async function () {
441
+ const S = new Schema();
442
+ S.defineModel({
443
+ name: 'model',
444
+ datasource: 'datasource',
445
+ properties: {
446
+ foo: DataType.STRING,
447
+ },
448
+ });
449
+ await S.getService(ModelDataValidator).validate('model', {
450
+ foo: null,
451
+ });
464
452
  });
465
- });
466
453
 
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,
454
+ it('does not throw an error if a string given', async function () {
455
+ const S = new Schema();
456
+ S.defineModel({
457
+ name: 'model',
458
+ datasource: 'datasource',
459
+ properties: {
460
+ foo: DataType.STRING,
461
+ },
462
+ });
463
+ await S.getService(ModelDataValidator).validate('model', {
464
+ foo: 'bar',
465
+ });
478
466
  });
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
467
 
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,
468
+ it('throws an error if a number given', async function () {
469
+ const S = new Schema();
470
+ S.defineModel({
471
+ name: 'model',
472
+ datasource: 'datasource',
473
+ properties: {
474
+ foo: DataType.STRING,
475
+ },
476
+ });
477
+ const promise = S.getService(ModelDataValidator).validate('model', {
478
+ foo: 10,
479
+ });
480
+ await expect(promise).to.be.rejectedWith(
481
+ 'The property "foo" of the model "model" must have ' +
482
+ 'a String, but Number given.',
483
+ );
496
484
  });
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
485
 
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,
486
+ it('throws an error if true given', async function () {
487
+ const S = new Schema();
488
+ S.defineModel({
489
+ name: 'model',
490
+ datasource: 'datasource',
491
+ properties: {
492
+ foo: DataType.STRING,
493
+ },
494
+ });
495
+ const promise = S.getService(ModelDataValidator).validate('model', {
496
+ foo: true,
497
+ });
498
+ await expect(promise).to.be.rejectedWith(
499
+ 'The property "foo" of the model "model" must have ' +
500
+ 'a String, but Boolean given.',
501
+ );
514
502
  });
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
503
 
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: [],
504
+ it('throws an error if false given', async function () {
505
+ const S = new Schema();
506
+ S.defineModel({
507
+ name: 'model',
508
+ datasource: 'datasource',
509
+ properties: {
510
+ foo: DataType.STRING,
511
+ },
512
+ });
513
+ const promise = S.getService(ModelDataValidator).validate('model', {
514
+ foo: false,
515
+ });
516
+ await expect(promise).to.be.rejectedWith(
517
+ 'The property "foo" of the model "model" must have ' +
518
+ 'a String, but Boolean given.',
519
+ );
532
520
  });
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
521
 
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: {},
522
+ it('throws an error if an array given', async function () {
523
+ const S = new Schema();
524
+ S.defineModel({
525
+ name: 'model',
526
+ datasource: 'datasource',
527
+ properties: {
528
+ foo: DataType.STRING,
529
+ },
530
+ });
531
+ const promise = S.getService(ModelDataValidator).validate('model', {
532
+ foo: [],
533
+ });
534
+ await expect(promise).to.be.rejectedWith(
535
+ 'The property "foo" of the model "model" must have ' +
536
+ 'a String, but Array given.',
537
+ );
550
538
  });
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
- });
556
- });
557
539
 
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,
540
+ it('throws an error if an object given', async function () {
541
+ const S = new Schema();
542
+ S.defineModel({
543
+ name: 'model',
544
+ datasource: 'datasource',
545
+ properties: {
546
+ foo: DataType.STRING,
567
547
  },
568
- },
569
- });
570
- await S.getService(ModelDataValidator).validate('model', {
571
- foo: undefined,
548
+ });
549
+ const promise = S.getService(ModelDataValidator).validate('model', {
550
+ foo: {},
551
+ });
552
+ await expect(promise).to.be.rejectedWith(
553
+ 'The property "foo" of the model "model" must have ' +
554
+ 'a String, but Object given.',
555
+ );
572
556
  });
573
557
  });
574
558
 
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,
559
+ describe('FullPropertyDefinition', function () {
560
+ it('does not throw an error if an undefined given', async function () {
561
+ const S = new Schema();
562
+ S.defineModel({
563
+ name: 'model',
564
+ datasource: 'datasource',
565
+ properties: {
566
+ foo: {
567
+ type: DataType.STRING,
568
+ },
583
569
  },
584
- },
585
- });
586
- await S.getService(ModelDataValidator).validate('model', {
587
- foo: null,
570
+ });
571
+ await S.getService(ModelDataValidator).validate('model', {
572
+ foo: undefined,
573
+ });
588
574
  });
589
- });
590
575
 
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,
576
+ it('does not throw an error if a null given', async function () {
577
+ const S = new Schema();
578
+ S.defineModel({
579
+ name: 'model',
580
+ datasource: 'datasource',
581
+ properties: {
582
+ foo: {
583
+ type: DataType.STRING,
584
+ },
599
585
  },
600
- },
601
- });
602
- await S.getService(ModelDataValidator).validate('model', {
603
- foo: 'bar',
586
+ });
587
+ await S.getService(ModelDataValidator).validate('model', {
588
+ foo: null,
589
+ });
604
590
  });
605
- });
606
591
 
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,
592
+ it('does not throw an error if a string given', async function () {
593
+ const S = new Schema();
594
+ S.defineModel({
595
+ name: 'model',
596
+ datasource: 'datasource',
597
+ properties: {
598
+ foo: {
599
+ type: DataType.STRING,
600
+ },
615
601
  },
616
- },
617
- });
618
- const promise = S.getService(ModelDataValidator).validate('model', {
619
- foo: 10,
602
+ });
603
+ await S.getService(ModelDataValidator).validate('model', {
604
+ foo: 'bar',
605
+ });
620
606
  });
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
607
 
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,
608
+ it('throws an error if a number given', async function () {
609
+ const S = new Schema();
610
+ S.defineModel({
611
+ name: 'model',
612
+ datasource: 'datasource',
613
+ properties: {
614
+ foo: {
615
+ type: DataType.STRING,
616
+ },
635
617
  },
636
- },
637
- });
638
- const promise = S.getService(ModelDataValidator).validate('model', {
639
- foo: true,
618
+ });
619
+ const promise = S.getService(ModelDataValidator).validate('model', {
620
+ foo: 10,
621
+ });
622
+ await expect(promise).to.be.rejectedWith(
623
+ 'The property "foo" of the model "model" must have ' +
624
+ 'a String, but Number given.',
625
+ );
640
626
  });
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
627
 
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,
628
+ it('throws an error if true given', async function () {
629
+ const S = new Schema();
630
+ S.defineModel({
631
+ name: 'model',
632
+ datasource: 'datasource',
633
+ properties: {
634
+ foo: {
635
+ type: DataType.STRING,
636
+ },
655
637
  },
656
- },
657
- });
658
- const promise = S.getService(ModelDataValidator).validate('model', {
659
- foo: false,
638
+ });
639
+ const promise = S.getService(ModelDataValidator).validate('model', {
640
+ foo: true,
641
+ });
642
+ await expect(promise).to.be.rejectedWith(
643
+ 'The property "foo" of the model "model" must have ' +
644
+ 'a String, but Boolean given.',
645
+ );
660
646
  });
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
647
 
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,
648
+ it('throws an error if false given', async function () {
649
+ const S = new Schema();
650
+ S.defineModel({
651
+ name: 'model',
652
+ datasource: 'datasource',
653
+ properties: {
654
+ foo: {
655
+ type: DataType.STRING,
656
+ },
675
657
  },
676
- },
677
- });
678
- const promise = S.getService(ModelDataValidator).validate('model', {
679
- foo: [],
658
+ });
659
+ const promise = S.getService(ModelDataValidator).validate('model', {
660
+ foo: false,
661
+ });
662
+ await expect(promise).to.be.rejectedWith(
663
+ 'The property "foo" of the model "model" must have ' +
664
+ 'a String, but Boolean given.',
665
+ );
680
666
  });
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
667
 
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,
668
+ it('throws an error if an array given', async function () {
669
+ const S = new Schema();
670
+ S.defineModel({
671
+ name: 'model',
672
+ datasource: 'datasource',
673
+ properties: {
674
+ foo: {
675
+ type: DataType.STRING,
676
+ },
695
677
  },
696
- },
697
- });
698
- const promise = S.getService(ModelDataValidator).validate('model', {
699
- foo: {},
700
- });
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
- });
706
- });
707
- });
708
-
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,
722
- });
723
- });
724
-
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,
736
- });
737
- });
738
-
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',
750
- });
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
-
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,
768
- });
769
- });
770
-
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,
782
- });
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
-
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,
800
- });
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
-
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: [],
818
- });
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
-
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: {},
678
+ });
679
+ const promise = S.getService(ModelDataValidator).validate('model', {
680
+ foo: [],
681
+ });
682
+ await expect(promise).to.be.rejectedWith(
683
+ 'The property "foo" of the model "model" must have ' +
684
+ 'a String, but Array given.',
685
+ );
836
686
  });
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
- });
842
- });
843
687
 
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,
688
+ it('throws an error if an object given', async function () {
689
+ const S = new Schema();
690
+ S.defineModel({
691
+ name: 'model',
692
+ datasource: 'datasource',
693
+ properties: {
694
+ foo: {
695
+ type: DataType.STRING,
696
+ },
853
697
  },
854
- },
855
- });
856
- await S.getService(ModelDataValidator).validate('model', {
857
- foo: undefined,
698
+ });
699
+ const promise = S.getService(ModelDataValidator).validate('model', {
700
+ foo: {},
701
+ });
702
+ await expect(promise).to.be.rejectedWith(
703
+ 'The property "foo" of the model "model" must have ' +
704
+ 'a String, but Object given.',
705
+ );
858
706
  });
859
707
  });
708
+ });
860
709
 
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,
710
+ describe('DataType.NUMBER', function () {
711
+ describe('ShortPropertyDefinition', function () {
712
+ it('does not throw an error if an undefined given', async function () {
713
+ const S = new Schema();
714
+ S.defineModel({
715
+ name: 'model',
716
+ datasource: 'datasource',
717
+ properties: {
718
+ foo: DataType.NUMBER,
869
719
  },
870
- },
871
- });
872
- await S.getService(ModelDataValidator).validate('model', {
873
- foo: null,
720
+ });
721
+ await S.getService(ModelDataValidator).validate('model', {
722
+ foo: undefined,
723
+ });
874
724
  });
875
- });
876
725
 
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,
726
+ it('does not throw an error if a null given', async function () {
727
+ const S = new Schema();
728
+ S.defineModel({
729
+ name: 'model',
730
+ datasource: 'datasource',
731
+ properties: {
732
+ foo: DataType.NUMBER,
885
733
  },
886
- },
887
- });
888
- const promise = S.getService(ModelDataValidator).validate('model', {
889
- foo: 'bar',
734
+ });
735
+ await S.getService(ModelDataValidator).validate('model', {
736
+ foo: null,
737
+ });
890
738
  });
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
739
 
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,
740
+ it('throws an error if a string given', async function () {
741
+ const S = new Schema();
742
+ S.defineModel({
743
+ name: 'model',
744
+ datasource: 'datasource',
745
+ properties: {
746
+ foo: DataType.NUMBER,
905
747
  },
906
- },
907
- });
908
- await S.getService(ModelDataValidator).validate('model', {
909
- foo: 10,
748
+ });
749
+ const promise = S.getService(ModelDataValidator).validate('model', {
750
+ foo: 'bar',
751
+ });
752
+ await expect(promise).to.be.rejectedWith(
753
+ 'The property "foo" of the model "model" must have ' +
754
+ 'a Number, but String given.',
755
+ );
910
756
  });
911
- });
912
757
 
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,
758
+ it('does not throw an error if a number given', async function () {
759
+ const S = new Schema();
760
+ S.defineModel({
761
+ name: 'model',
762
+ datasource: 'datasource',
763
+ properties: {
764
+ foo: DataType.NUMBER,
921
765
  },
922
- },
923
- });
924
- const promise = S.getService(ModelDataValidator).validate('model', {
925
- foo: true,
766
+ });
767
+ await S.getService(ModelDataValidator).validate('model', {
768
+ foo: 10,
769
+ });
926
770
  });
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
771
 
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,
772
+ it('throws an error if true given', async function () {
773
+ const S = new Schema();
774
+ S.defineModel({
775
+ name: 'model',
776
+ datasource: 'datasource',
777
+ properties: {
778
+ foo: DataType.NUMBER,
941
779
  },
942
- },
943
- });
944
- const promise = S.getService(ModelDataValidator).validate('model', {
945
- foo: false,
780
+ });
781
+ const promise = S.getService(ModelDataValidator).validate('model', {
782
+ foo: true,
783
+ });
784
+ await expect(promise).to.be.rejectedWith(
785
+ 'The property "foo" of the model "model" must have ' +
786
+ 'a Number, but Boolean given.',
787
+ );
946
788
  });
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
789
 
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,
790
+ it('throws an error if false given', async function () {
791
+ const S = new Schema();
792
+ S.defineModel({
793
+ name: 'model',
794
+ datasource: 'datasource',
795
+ properties: {
796
+ foo: DataType.NUMBER,
961
797
  },
962
- },
963
- });
964
- const promise = S.getService(ModelDataValidator).validate('model', {
965
- foo: [],
798
+ });
799
+ const promise = S.getService(ModelDataValidator).validate('model', {
800
+ foo: false,
801
+ });
802
+ await expect(promise).to.be.rejectedWith(
803
+ 'The property "foo" of the model "model" must have ' +
804
+ 'a Number, but Boolean given.',
805
+ );
966
806
  });
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
807
 
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,
808
+ it('throws an error if an array given', async function () {
809
+ const S = new Schema();
810
+ S.defineModel({
811
+ name: 'model',
812
+ datasource: 'datasource',
813
+ properties: {
814
+ foo: DataType.NUMBER,
981
815
  },
982
- },
983
- });
984
- const promise = S.getService(ModelDataValidator).validate('model', {
985
- foo: {},
986
- });
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
- });
992
- });
993
- });
994
-
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,
1008
- });
1009
- });
1010
-
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,
1022
- });
1023
- });
1024
-
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',
816
+ });
817
+ const promise = S.getService(ModelDataValidator).validate('model', {
818
+ foo: [],
819
+ });
820
+ await expect(promise).to.be.rejectedWith(
821
+ 'The property "foo" of the model "model" must have ' +
822
+ 'a Number, but Array given.',
823
+ );
1036
824
  });
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
825
 
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,
826
+ it('throws an error if an object given', async function () {
827
+ const S = new Schema();
828
+ S.defineModel({
829
+ name: 'model',
830
+ datasource: 'datasource',
831
+ properties: {
832
+ foo: DataType.NUMBER,
833
+ },
834
+ });
835
+ const promise = S.getService(ModelDataValidator).validate('model', {
836
+ foo: {},
837
+ });
838
+ await expect(promise).to.be.rejectedWith(
839
+ 'The property "foo" of the model "model" must have ' +
840
+ 'a Number, but Object given.',
841
+ );
1054
842
  });
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
843
  });
1060
844
 
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,
845
+ describe('FullPropertyDefinition', function () {
846
+ it('does not throw an error if an undefined given', async function () {
847
+ const S = new Schema();
848
+ S.defineModel({
849
+ name: 'model',
850
+ datasource: 'datasource',
851
+ properties: {
852
+ foo: {
853
+ type: DataType.NUMBER,
854
+ },
855
+ },
856
+ });
857
+ await S.getService(ModelDataValidator).validate('model', {
858
+ foo: undefined,
859
+ });
1072
860
  });
1073
- });
1074
861
 
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,
862
+ it('does not throw an error if a null given', async function () {
863
+ const S = new Schema();
864
+ S.defineModel({
865
+ name: 'model',
866
+ datasource: 'datasource',
867
+ properties: {
868
+ foo: {
869
+ type: DataType.NUMBER,
870
+ },
871
+ },
872
+ });
873
+ await S.getService(ModelDataValidator).validate('model', {
874
+ foo: null,
875
+ });
1086
876
  });
1087
- });
1088
877
 
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: [],
878
+ it('throws an error if a string given', async function () {
879
+ const S = new Schema();
880
+ S.defineModel({
881
+ name: 'model',
882
+ datasource: 'datasource',
883
+ properties: {
884
+ foo: {
885
+ type: DataType.NUMBER,
886
+ },
887
+ },
888
+ });
889
+ const promise = S.getService(ModelDataValidator).validate('model', {
890
+ foo: 'bar',
891
+ });
892
+ await expect(promise).to.be.rejectedWith(
893
+ 'The property "foo" of the model "model" must have ' +
894
+ 'a Number, but String given.',
895
+ );
1100
896
  });
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
897
 
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: {},
898
+ it('does not throw an error if a number given', async function () {
899
+ const S = new Schema();
900
+ S.defineModel({
901
+ name: 'model',
902
+ datasource: 'datasource',
903
+ properties: {
904
+ foo: {
905
+ type: DataType.NUMBER,
906
+ },
907
+ },
908
+ });
909
+ await S.getService(ModelDataValidator).validate('model', {
910
+ foo: 10,
911
+ });
1118
912
  });
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
- });
1124
- });
1125
913
 
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,
914
+ it('throws an error if true given', async function () {
915
+ const S = new Schema();
916
+ S.defineModel({
917
+ name: 'model',
918
+ datasource: 'datasource',
919
+ properties: {
920
+ foo: {
921
+ type: DataType.NUMBER,
922
+ },
1135
923
  },
1136
- },
1137
- });
1138
- await S.getService(ModelDataValidator).validate('model', {
1139
- foo: undefined,
924
+ });
925
+ const promise = S.getService(ModelDataValidator).validate('model', {
926
+ foo: true,
927
+ });
928
+ await expect(promise).to.be.rejectedWith(
929
+ 'The property "foo" of the model "model" must have ' +
930
+ 'a Number, but Boolean given.',
931
+ );
1140
932
  });
1141
- });
1142
933
 
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,
934
+ it('throws an error if false given', async function () {
935
+ const S = new Schema();
936
+ S.defineModel({
937
+ name: 'model',
938
+ datasource: 'datasource',
939
+ properties: {
940
+ foo: {
941
+ type: DataType.NUMBER,
942
+ },
1151
943
  },
1152
- },
1153
- });
1154
- await S.getService(ModelDataValidator).validate('model', {
1155
- foo: null,
944
+ });
945
+ const promise = S.getService(ModelDataValidator).validate('model', {
946
+ foo: false,
947
+ });
948
+ await expect(promise).to.be.rejectedWith(
949
+ 'The property "foo" of the model "model" must have ' +
950
+ 'a Number, but Boolean given.',
951
+ );
1156
952
  });
1157
- });
1158
953
 
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,
954
+ it('throws an error if an array given', async function () {
955
+ const S = new Schema();
956
+ S.defineModel({
957
+ name: 'model',
958
+ datasource: 'datasource',
959
+ properties: {
960
+ foo: {
961
+ type: DataType.NUMBER,
962
+ },
1167
963
  },
1168
- },
964
+ });
965
+ const promise = S.getService(ModelDataValidator).validate('model', {
966
+ foo: [],
967
+ });
968
+ await expect(promise).to.be.rejectedWith(
969
+ 'The property "foo" of the model "model" must have ' +
970
+ 'a Number, but Array given.',
971
+ );
1169
972
  });
1170
- const promise = S.getService(ModelDataValidator).validate('model', {
1171
- foo: 'bar',
973
+
974
+ it('throws an error if an object given', async function () {
975
+ const S = new Schema();
976
+ S.defineModel({
977
+ name: 'model',
978
+ datasource: 'datasource',
979
+ properties: {
980
+ foo: {
981
+ type: DataType.NUMBER,
982
+ },
983
+ },
984
+ });
985
+ const promise = S.getService(ModelDataValidator).validate('model', {
986
+ foo: {},
987
+ });
988
+ await expect(promise).to.be.rejectedWith(
989
+ 'The property "foo" of the model "model" must have ' +
990
+ 'a Number, but Object given.',
991
+ );
1172
992
  });
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
993
  });
994
+ });
1178
995
 
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,
996
+ describe('DataType.BOOLEAN', function () {
997
+ describe('ShortPropertyDefinition', function () {
998
+ it('does not throw an error if an undefined given', async function () {
999
+ const S = new Schema();
1000
+ S.defineModel({
1001
+ name: 'model',
1002
+ datasource: 'datasource',
1003
+ properties: {
1004
+ foo: DataType.BOOLEAN,
1187
1005
  },
1188
- },
1189
- });
1190
- const promise = S.getService(ModelDataValidator).validate('model', {
1191
- foo: 10,
1006
+ });
1007
+ await S.getService(ModelDataValidator).validate('model', {
1008
+ foo: undefined,
1009
+ });
1192
1010
  });
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
1011
 
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,
1012
+ it('does not throw an error if a null given', async function () {
1013
+ const S = new Schema();
1014
+ S.defineModel({
1015
+ name: 'model',
1016
+ datasource: 'datasource',
1017
+ properties: {
1018
+ foo: DataType.BOOLEAN,
1207
1019
  },
1208
- },
1020
+ });
1021
+ await S.getService(ModelDataValidator).validate('model', {
1022
+ foo: null,
1023
+ });
1209
1024
  });
1210
- await S.getService(ModelDataValidator).validate('model', {
1211
- foo: true,
1025
+
1026
+ it('throws an error if a string given', async function () {
1027
+ const S = new Schema();
1028
+ S.defineModel({
1029
+ name: 'model',
1030
+ datasource: 'datasource',
1031
+ properties: {
1032
+ foo: DataType.BOOLEAN,
1033
+ },
1034
+ });
1035
+ const promise = S.getService(ModelDataValidator).validate('model', {
1036
+ foo: 'bar',
1037
+ });
1038
+ await expect(promise).to.be.rejectedWith(
1039
+ 'The property "foo" of the model "model" must have ' +
1040
+ 'a Boolean, but String given.',
1041
+ );
1212
1042
  });
1213
- });
1214
1043
 
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,
1044
+ it('throws an error if a number given', async function () {
1045
+ const S = new Schema();
1046
+ S.defineModel({
1047
+ name: 'model',
1048
+ datasource: 'datasource',
1049
+ properties: {
1050
+ foo: DataType.BOOLEAN,
1223
1051
  },
1224
- },
1052
+ });
1053
+ const promise = S.getService(ModelDataValidator).validate('model', {
1054
+ foo: 10,
1055
+ });
1056
+ await expect(promise).to.be.rejectedWith(
1057
+ 'The property "foo" of the model "model" must have ' +
1058
+ 'a Boolean, but Number given.',
1059
+ );
1225
1060
  });
1226
- await S.getService(ModelDataValidator).validate('model', {
1227
- foo: false,
1061
+
1062
+ it('does not throw an error if true given', async function () {
1063
+ const S = new Schema();
1064
+ S.defineModel({
1065
+ name: 'model',
1066
+ datasource: 'datasource',
1067
+ properties: {
1068
+ foo: DataType.BOOLEAN,
1069
+ },
1070
+ });
1071
+ await S.getService(ModelDataValidator).validate('model', {
1072
+ foo: true,
1073
+ });
1228
1074
  });
1229
- });
1230
1075
 
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,
1076
+ it('does not throw an error if false given', async function () {
1077
+ const S = new Schema();
1078
+ S.defineModel({
1079
+ name: 'model',
1080
+ datasource: 'datasource',
1081
+ properties: {
1082
+ foo: DataType.BOOLEAN,
1239
1083
  },
1240
- },
1241
- });
1242
- const promise = S.getService(ModelDataValidator).validate('model', {
1243
- foo: [],
1084
+ });
1085
+ await S.getService(ModelDataValidator).validate('model', {
1086
+ foo: false,
1087
+ });
1244
1088
  });
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
1089
 
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,
1090
+ it('throws an error if an array given', async function () {
1091
+ const S = new Schema();
1092
+ S.defineModel({
1093
+ name: 'model',
1094
+ datasource: 'datasource',
1095
+ properties: {
1096
+ foo: DataType.BOOLEAN,
1259
1097
  },
1260
- },
1261
- });
1262
- const promise = S.getService(ModelDataValidator).validate('model', {
1263
- foo: {},
1098
+ });
1099
+ const promise = S.getService(ModelDataValidator).validate('model', {
1100
+ foo: [],
1101
+ });
1102
+ await expect(promise).to.be.rejectedWith(
1103
+ 'The property "foo" of the model "model" must have ' +
1104
+ 'a Boolean, but Array given.',
1105
+ );
1264
1106
  });
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
- });
1270
- });
1271
- });
1272
1107
 
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,
1108
+ it('throws an error if an object given', async function () {
1109
+ const S = new Schema();
1110
+ S.defineModel({
1111
+ name: 'model',
1112
+ datasource: 'datasource',
1113
+ properties: {
1114
+ foo: DataType.BOOLEAN,
1115
+ },
1116
+ });
1117
+ const promise = S.getService(ModelDataValidator).validate('model', {
1118
+ foo: {},
1119
+ });
1120
+ await expect(promise).to.be.rejectedWith(
1121
+ 'The property "foo" of the model "model" must have ' +
1122
+ 'a Boolean, but Object given.',
1123
+ );
1286
1124
  });
1287
1125
  });
1288
1126
 
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,
1127
+ describe('FullPropertyDefinition', function () {
1128
+ it('does not throw an error if an undefined given', async function () {
1129
+ const S = new Schema();
1130
+ S.defineModel({
1131
+ name: 'model',
1132
+ datasource: 'datasource',
1133
+ properties: {
1134
+ foo: {
1135
+ type: DataType.BOOLEAN,
1136
+ },
1137
+ },
1138
+ });
1139
+ await S.getService(ModelDataValidator).validate('model', {
1140
+ foo: undefined,
1141
+ });
1300
1142
  });
1301
- });
1302
1143
 
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',
1144
+ it('does not throw an error if a null given', async function () {
1145
+ const S = new Schema();
1146
+ S.defineModel({
1147
+ name: 'model',
1148
+ datasource: 'datasource',
1149
+ properties: {
1150
+ foo: {
1151
+ type: DataType.BOOLEAN,
1152
+ },
1153
+ },
1154
+ });
1155
+ await S.getService(ModelDataValidator).validate('model', {
1156
+ foo: null,
1157
+ });
1314
1158
  });
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
1159
 
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,
1160
+ it('throws an error if a string given', async function () {
1161
+ const S = new Schema();
1162
+ S.defineModel({
1163
+ name: 'model',
1164
+ datasource: 'datasource',
1165
+ properties: {
1166
+ foo: {
1167
+ type: DataType.BOOLEAN,
1168
+ },
1169
+ },
1170
+ });
1171
+ const promise = S.getService(ModelDataValidator).validate('model', {
1172
+ foo: 'bar',
1173
+ });
1174
+ await expect(promise).to.be.rejectedWith(
1175
+ 'The property "foo" of the model "model" must have ' +
1176
+ 'a Boolean, but String given.',
1177
+ );
1332
1178
  });
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
1179
 
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,
1180
+ it('throws an error if a number given', async 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 promise = S.getService(ModelDataValidator).validate('model', {
1192
+ foo: 10,
1193
+ });
1194
+ await expect(promise).to.be.rejectedWith(
1195
+ 'The property "foo" of the model "model" must have ' +
1196
+ 'a Boolean, but Number given.',
1197
+ );
1350
1198
  });
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
1199
 
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,
1200
+ it('does not throw an error if true given', async function () {
1201
+ const S = new Schema();
1202
+ S.defineModel({
1203
+ name: 'model',
1204
+ datasource: 'datasource',
1205
+ properties: {
1206
+ foo: {
1207
+ type: DataType.BOOLEAN,
1208
+ },
1209
+ },
1210
+ });
1211
+ await S.getService(ModelDataValidator).validate('model', {
1212
+ foo: true,
1213
+ });
1368
1214
  });
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
1215
 
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: [],
1216
+ it('does not throw an error if false given', async function () {
1217
+ const S = new Schema();
1218
+ S.defineModel({
1219
+ name: 'model',
1220
+ datasource: 'datasource',
1221
+ properties: {
1222
+ foo: {
1223
+ type: DataType.BOOLEAN,
1224
+ },
1225
+ },
1226
+ });
1227
+ await S.getService(ModelDataValidator).validate('model', {
1228
+ foo: false,
1229
+ });
1386
1230
  });
1387
- });
1388
1231
 
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
- },
1232
+ it('throws an error if an array given', async function () {
1233
+ const S = new Schema();
1234
+ S.defineModel({
1235
+ name: 'model',
1236
+ datasource: 'datasource',
1237
+ properties: {
1238
+ foo: {
1239
+ type: DataType.BOOLEAN,
1240
+ },
1241
+ },
1242
+ });
1243
+ const promise = S.getService(ModelDataValidator).validate('model', {
1244
+ foo: [],
1245
+ });
1246
+ await expect(promise).to.be.rejectedWith(
1247
+ 'The property "foo" of the model "model" must have ' +
1248
+ 'a Boolean, but Array given.',
1249
+ );
1397
1250
  });
1398
- const promise = S.getService(ModelDataValidator).validate('model', {
1399
- foo: {},
1251
+
1252
+ it('throws an error if an object given', async function () {
1253
+ const S = new Schema();
1254
+ S.defineModel({
1255
+ name: 'model',
1256
+ datasource: 'datasource',
1257
+ properties: {
1258
+ foo: {
1259
+ type: DataType.BOOLEAN,
1260
+ },
1261
+ },
1262
+ });
1263
+ const promise = S.getService(ModelDataValidator).validate('model', {
1264
+ foo: {},
1265
+ });
1266
+ await expect(promise).to.be.rejectedWith(
1267
+ 'The property "foo" of the model "model" must have ' +
1268
+ 'a Boolean, but Object given.',
1269
+ );
1400
1270
  });
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
1271
  });
1406
1272
  });
1407
1273
 
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,
1274
+ describe('DataType.ARRAY', function () {
1275
+ describe('ShortPropertyDefinition', function () {
1276
+ it('does not throw an error if an undefined given', async function () {
1277
+ const S = new Schema();
1278
+ S.defineModel({
1279
+ name: 'model',
1280
+ datasource: 'datasource',
1281
+ properties: {
1282
+ foo: DataType.ARRAY,
1417
1283
  },
1418
- },
1419
- });
1420
- await S.getService(ModelDataValidator).validate('model', {
1421
- foo: undefined,
1284
+ });
1285
+ await S.getService(ModelDataValidator).validate('model', {
1286
+ foo: undefined,
1287
+ });
1422
1288
  });
1423
- });
1424
1289
 
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,
1290
+ it('does not throw an error if a null given', async function () {
1291
+ const S = new Schema();
1292
+ S.defineModel({
1293
+ name: 'model',
1294
+ datasource: 'datasource',
1295
+ properties: {
1296
+ foo: DataType.ARRAY,
1433
1297
  },
1434
- },
1298
+ });
1299
+ await S.getService(ModelDataValidator).validate('model', {
1300
+ foo: null,
1301
+ });
1435
1302
  });
1436
- await S.getService(ModelDataValidator).validate('model', {
1437
- foo: null,
1303
+
1304
+ it('throws an error if a string given', async function () {
1305
+ const S = new Schema();
1306
+ S.defineModel({
1307
+ name: 'model',
1308
+ datasource: 'datasource',
1309
+ properties: {
1310
+ foo: DataType.ARRAY,
1311
+ },
1312
+ });
1313
+ const promise = S.getService(ModelDataValidator).validate('model', {
1314
+ foo: 'bar',
1315
+ });
1316
+ await expect(promise).to.be.rejectedWith(
1317
+ 'The property "foo" of the model "model" must have ' +
1318
+ 'an Array, but String given.',
1319
+ );
1438
1320
  });
1439
- });
1440
1321
 
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,
1322
+ it('throws an error if a number given', async function () {
1323
+ const S = new Schema();
1324
+ S.defineModel({
1325
+ name: 'model',
1326
+ datasource: 'datasource',
1327
+ properties: {
1328
+ foo: DataType.ARRAY,
1449
1329
  },
1450
- },
1451
- });
1452
- const promise = S.getService(ModelDataValidator).validate('model', {
1453
- foo: 'bar',
1330
+ });
1331
+ const promise = S.getService(ModelDataValidator).validate('model', {
1332
+ foo: 10,
1333
+ });
1334
+ await expect(promise).to.be.rejectedWith(
1335
+ 'The property "foo" of the model "model" must have ' +
1336
+ 'an Array, but Number given.',
1337
+ );
1454
1338
  });
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
1339
 
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,
1340
+ it('throws an error if true given', async function () {
1341
+ const S = new Schema();
1342
+ S.defineModel({
1343
+ name: 'model',
1344
+ datasource: 'datasource',
1345
+ properties: {
1346
+ foo: DataType.ARRAY,
1469
1347
  },
1470
- },
1471
- });
1472
- const promise = S.getService(ModelDataValidator).validate('model', {
1473
- foo: 10,
1348
+ });
1349
+ const promise = S.getService(ModelDataValidator).validate('model', {
1350
+ foo: true,
1351
+ });
1352
+ await expect(promise).to.be.rejectedWith(
1353
+ 'The property "foo" of the model "model" must have ' +
1354
+ 'an Array, but Boolean given.',
1355
+ );
1474
1356
  });
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
1357
 
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,
1358
+ it('throws an error if false given', async function () {
1359
+ const S = new Schema();
1360
+ S.defineModel({
1361
+ name: 'model',
1362
+ datasource: 'datasource',
1363
+ properties: {
1364
+ foo: DataType.ARRAY,
1489
1365
  },
1490
- },
1491
- });
1492
- const promise = S.getService(ModelDataValidator).validate('model', {
1493
- foo: true,
1366
+ });
1367
+ const promise = S.getService(ModelDataValidator).validate('model', {
1368
+ foo: false,
1369
+ });
1370
+ await expect(promise).to.be.rejectedWith(
1371
+ 'The property "foo" of the model "model" must have ' +
1372
+ 'an Array, but Boolean given.',
1373
+ );
1494
1374
  });
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
- });
1500
1375
 
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,
1376
+ it('does not throw an error if an array given', async function () {
1377
+ const S = new Schema();
1378
+ S.defineModel({
1379
+ name: 'model',
1380
+ datasource: 'datasource',
1381
+ properties: {
1382
+ foo: DataType.ARRAY,
1509
1383
  },
1510
- },
1511
- });
1512
- const promise = S.getService(ModelDataValidator).validate('model', {
1513
- foo: false,
1384
+ });
1385
+ await S.getService(ModelDataValidator).validate('model', {
1386
+ foo: [],
1387
+ });
1514
1388
  });
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
1389
 
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,
1390
+ it('throws an error if an object given', async function () {
1391
+ const S = new Schema();
1392
+ S.defineModel({
1393
+ name: 'model',
1394
+ datasource: 'datasource',
1395
+ properties: {
1396
+ foo: DataType.ARRAY,
1529
1397
  },
1530
- },
1531
- });
1532
- await S.getService(ModelDataValidator).validate('model', {
1533
- foo: [],
1398
+ });
1399
+ const promise = S.getService(ModelDataValidator).validate('model', {
1400
+ foo: {},
1401
+ });
1402
+ await expect(promise).to.be.rejectedWith(
1403
+ 'The property "foo" of the model "model" must have ' +
1404
+ 'an Array, but Object given.',
1405
+ );
1534
1406
  });
1535
1407
  });
1536
1408
 
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,
1409
+ describe('FullPropertyDefinition', function () {
1410
+ it('does not throw an error if an undefined given', async function () {
1411
+ const S = new Schema();
1412
+ S.defineModel({
1413
+ name: 'model',
1414
+ datasource: 'datasource',
1415
+ properties: {
1416
+ foo: {
1417
+ type: DataType.ARRAY,
1418
+ },
1545
1419
  },
1546
- },
1547
- });
1548
- const promise = S.getService(ModelDataValidator).validate('model', {
1549
- foo: {},
1420
+ });
1421
+ await S.getService(ModelDataValidator).validate('model', {
1422
+ foo: undefined,
1423
+ });
1550
1424
  });
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
1425
 
1557
- describe('the "model" option', function () {
1558
- it('throws an error when the given object element has an invalid model', async function () {
1426
+ it('does not throw an error if a null given', async function () {
1559
1427
  const S = new Schema();
1560
1428
  S.defineModel({
1561
- name: 'modelA',
1429
+ name: 'model',
1430
+ datasource: 'datasource',
1562
1431
  properties: {
1563
- foo: DataType.STRING,
1432
+ foo: {
1433
+ type: DataType.ARRAY,
1434
+ },
1564
1435
  },
1565
1436
  });
1437
+ await S.getService(ModelDataValidator).validate('model', {
1438
+ foo: null,
1439
+ });
1440
+ });
1441
+
1442
+ it('throws an error if a string given', async function () {
1443
+ const S = new Schema();
1566
1444
  S.defineModel({
1567
- name: 'modelB',
1445
+ name: 'model',
1568
1446
  datasource: 'datasource',
1569
1447
  properties: {
1570
- bar: {
1448
+ foo: {
1571
1449
  type: DataType.ARRAY,
1572
- itemType: DataType.OBJECT,
1573
- model: 'modelA',
1574
1450
  },
1575
1451
  },
1576
1452
  });
1577
- const promise = S.getService(ModelDataValidator).validate(
1578
- 'modelB',
1579
- {
1580
- bar: [{foo: 10}],
1581
- },
1582
- );
1453
+ const promise = S.getService(ModelDataValidator).validate('model', {
1454
+ foo: 'bar',
1455
+ });
1583
1456
  await expect(promise).to.be.rejectedWith(
1584
- 'The property "foo" of the model "modelA" must have ' +
1585
- 'a String, but Number given.',
1457
+ 'The property "foo" of the model "model" must have ' +
1458
+ 'an Array, but String given.',
1586
1459
  );
1587
1460
  });
1588
1461
 
1589
- it('does not throw an error when the given object element has a valid model', async function () {
1462
+ it('throws an error if a number given', async function () {
1590
1463
  const S = new Schema();
1591
1464
  S.defineModel({
1592
- name: 'modelA',
1465
+ name: 'model',
1466
+ datasource: 'datasource',
1593
1467
  properties: {
1594
- foo: DataType.STRING,
1468
+ foo: {
1469
+ type: DataType.ARRAY,
1470
+ },
1595
1471
  },
1596
1472
  });
1473
+ const promise = S.getService(ModelDataValidator).validate('model', {
1474
+ foo: 10,
1475
+ });
1476
+ await expect(promise).to.be.rejectedWith(
1477
+ 'The property "foo" of the model "model" must have ' +
1478
+ 'an Array, but Number given.',
1479
+ );
1480
+ });
1481
+
1482
+ it('throws an error if true given', async function () {
1483
+ const S = new Schema();
1597
1484
  S.defineModel({
1598
- name: 'modelB',
1485
+ name: 'model',
1599
1486
  datasource: 'datasource',
1600
1487
  properties: {
1601
- bar: {
1488
+ foo: {
1602
1489
  type: DataType.ARRAY,
1603
- itemType: DataType.OBJECT,
1604
- model: 'modelA',
1605
1490
  },
1606
1491
  },
1607
1492
  });
1608
- await S.getService(ModelDataValidator).validate('modelB', {
1609
- bar: [{foo: '10'}],
1493
+ const promise = S.getService(ModelDataValidator).validate('model', {
1494
+ foo: true,
1610
1495
  });
1496
+ await expect(promise).to.be.rejectedWith(
1497
+ 'The property "foo" of the model "model" must have ' +
1498
+ 'an Array, but Boolean given.',
1499
+ );
1611
1500
  });
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
-
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,
1643
- });
1644
- });
1645
-
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
- });
1663
1501
 
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,
1502
+ it('throws an error if false given', async function () {
1503
+ const S = new Schema();
1504
+ S.defineModel({
1505
+ name: 'model',
1506
+ datasource: 'datasource',
1507
+ properties: {
1508
+ foo: {
1509
+ type: DataType.ARRAY,
1510
+ },
1511
+ },
1512
+ });
1513
+ const promise = S.getService(ModelDataValidator).validate('model', {
1514
+ foo: false,
1515
+ });
1516
+ await expect(promise).to.be.rejectedWith(
1517
+ 'The property "foo" of the model "model" must have ' +
1518
+ 'an Array, but Boolean given.',
1519
+ );
1675
1520
  });
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
- });
1681
1521
 
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,
1522
+ it('does not throw an error if an array given', async function () {
1523
+ const S = new Schema();
1524
+ S.defineModel({
1525
+ name: 'model',
1526
+ datasource: 'datasource',
1527
+ properties: {
1528
+ foo: {
1529
+ type: DataType.ARRAY,
1530
+ },
1531
+ },
1532
+ });
1533
+ await S.getService(ModelDataValidator).validate('model', {
1534
+ foo: [],
1535
+ });
1693
1536
  });
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
1537
 
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,
1538
+ it('throws an error if an object given', async function () {
1539
+ const S = new Schema();
1540
+ S.defineModel({
1541
+ name: 'model',
1542
+ datasource: 'datasource',
1543
+ properties: {
1544
+ foo: {
1545
+ type: DataType.ARRAY,
1546
+ },
1547
+ },
1548
+ });
1549
+ const promise = S.getService(ModelDataValidator).validate('model', {
1550
+ foo: {},
1551
+ });
1552
+ await expect(promise).to.be.rejectedWith(
1553
+ 'The property "foo" of the model "model" must have ' +
1554
+ 'an Array, but Object given.',
1555
+ );
1711
1556
  });
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
1557
 
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: [],
1729
- });
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
- });
1558
+ describe('the "model" option', function () {
1559
+ it('throws an error when the given object element has an invalid model', async function () {
1560
+ const S = new Schema();
1561
+ S.defineModel({
1562
+ name: 'modelA',
1563
+ properties: {
1564
+ foo: DataType.STRING,
1565
+ },
1566
+ });
1567
+ S.defineModel({
1568
+ name: 'modelB',
1569
+ datasource: 'datasource',
1570
+ properties: {
1571
+ bar: {
1572
+ type: DataType.ARRAY,
1573
+ itemType: DataType.OBJECT,
1574
+ model: 'modelA',
1575
+ },
1576
+ },
1577
+ });
1578
+ const promise = S.getService(ModelDataValidator).validate(
1579
+ 'modelB',
1580
+ {
1581
+ bar: [{foo: 10}],
1582
+ },
1583
+ );
1584
+ await expect(promise).to.be.rejectedWith(
1585
+ 'The property "foo" of the model "modelA" must have ' +
1586
+ 'a String, but Number given.',
1587
+ );
1588
+ });
1735
1589
 
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: {},
1590
+ it('does not throw an error when the given object element has a valid model', async function () {
1591
+ const S = new Schema();
1592
+ S.defineModel({
1593
+ name: 'modelA',
1594
+ properties: {
1595
+ foo: DataType.STRING,
1596
+ },
1597
+ });
1598
+ S.defineModel({
1599
+ name: 'modelB',
1600
+ datasource: 'datasource',
1601
+ properties: {
1602
+ bar: {
1603
+ type: DataType.ARRAY,
1604
+ itemType: DataType.OBJECT,
1605
+ model: 'modelA',
1606
+ },
1607
+ },
1608
+ });
1609
+ await S.getService(ModelDataValidator).validate('modelB', {
1610
+ bar: [{foo: '10'}],
1611
+ });
1612
+ });
1747
1613
  });
1748
1614
  });
1749
1615
  });
1750
1616
 
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,
1617
+ describe('DataType.OBJECT', function () {
1618
+ describe('ShortPropertyDefinition', function () {
1619
+ it('does not throw an error if an undefined given', async function () {
1620
+ const S = new Schema();
1621
+ S.defineModel({
1622
+ name: 'model',
1623
+ datasource: 'datasource',
1624
+ properties: {
1625
+ foo: DataType.OBJECT,
1760
1626
  },
1761
- },
1762
- });
1763
- await S.getService(ModelDataValidator).validate('model', {
1764
- foo: undefined,
1627
+ });
1628
+ await S.getService(ModelDataValidator).validate('model', {
1629
+ foo: undefined,
1630
+ });
1765
1631
  });
1766
- });
1767
1632
 
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,
1633
+ it('does not throw an error if a null given', async function () {
1634
+ const S = new Schema();
1635
+ S.defineModel({
1636
+ name: 'model',
1637
+ datasource: 'datasource',
1638
+ properties: {
1639
+ foo: DataType.OBJECT,
1776
1640
  },
1777
- },
1778
- });
1779
- await S.getService(ModelDataValidator).validate('model', {
1780
- foo: null,
1641
+ });
1642
+ await S.getService(ModelDataValidator).validate('model', {
1643
+ foo: null,
1644
+ });
1781
1645
  });
1782
- });
1783
1646
 
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,
1647
+ it('throws an error if a string given', async function () {
1648
+ const S = new Schema();
1649
+ S.defineModel({
1650
+ name: 'model',
1651
+ datasource: 'datasource',
1652
+ properties: {
1653
+ foo: DataType.OBJECT,
1792
1654
  },
1793
- },
1794
- });
1795
- const promise = S.getService(ModelDataValidator).validate('model', {
1796
- foo: 'bar',
1655
+ });
1656
+ const promise = S.getService(ModelDataValidator).validate('model', {
1657
+ foo: 'bar',
1658
+ });
1659
+ await expect(promise).to.be.rejectedWith(
1660
+ 'The property "foo" of the model "model" must have ' +
1661
+ 'an Object, but String given.',
1662
+ );
1797
1663
  });
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
1664
 
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,
1665
+ it('throws an error if a number given', async function () {
1666
+ const S = new Schema();
1667
+ S.defineModel({
1668
+ name: 'model',
1669
+ datasource: 'datasource',
1670
+ properties: {
1671
+ foo: DataType.OBJECT,
1812
1672
  },
1813
- },
1814
- });
1815
- const promise = S.getService(ModelDataValidator).validate('model', {
1816
- foo: 10,
1673
+ });
1674
+ const promise = S.getService(ModelDataValidator).validate('model', {
1675
+ foo: 10,
1676
+ });
1677
+ await expect(promise).to.be.rejectedWith(
1678
+ 'The property "foo" of the model "model" must have ' +
1679
+ 'an Object, but Number given.',
1680
+ );
1817
1681
  });
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
- });
1823
1682
 
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,
1683
+ it('throws an error if true given', async function () {
1684
+ const S = new Schema();
1685
+ S.defineModel({
1686
+ name: 'model',
1687
+ datasource: 'datasource',
1688
+ properties: {
1689
+ foo: DataType.OBJECT,
1832
1690
  },
1833
- },
1834
- });
1835
- const promise = S.getService(ModelDataValidator).validate('model', {
1836
- foo: true,
1691
+ });
1692
+ const promise = S.getService(ModelDataValidator).validate('model', {
1693
+ foo: true,
1694
+ });
1695
+ await expect(promise).to.be.rejectedWith(
1696
+ 'The property "foo" of the model "model" must have ' +
1697
+ 'an Object, but Boolean given.',
1698
+ );
1837
1699
  });
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
1700
 
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,
1701
+ it('throws an error if false given', async function () {
1702
+ const S = new Schema();
1703
+ S.defineModel({
1704
+ name: 'model',
1705
+ datasource: 'datasource',
1706
+ properties: {
1707
+ foo: DataType.OBJECT,
1852
1708
  },
1853
- },
1854
- });
1855
- const promise = S.getService(ModelDataValidator).validate('model', {
1856
- foo: false,
1709
+ });
1710
+ const promise = S.getService(ModelDataValidator).validate('model', {
1711
+ foo: false,
1712
+ });
1713
+ await expect(promise).to.be.rejectedWith(
1714
+ 'The property "foo" of the model "model" must have ' +
1715
+ 'an Object, but Boolean given.',
1716
+ );
1857
1717
  });
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
1718
 
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,
1719
+ it('throws an error if an array given', async function () {
1720
+ const S = new Schema();
1721
+ S.defineModel({
1722
+ name: 'model',
1723
+ datasource: 'datasource',
1724
+ properties: {
1725
+ foo: DataType.OBJECT,
1872
1726
  },
1873
- },
1727
+ });
1728
+ const promise = S.getService(ModelDataValidator).validate('model', {
1729
+ foo: [],
1730
+ });
1731
+ await expect(promise).to.be.rejectedWith(
1732
+ 'The property "foo" of the model "model" must have ' +
1733
+ 'an Object, but Array given.',
1734
+ );
1874
1735
  });
1875
- const promise = S.getService(ModelDataValidator).validate('model', {
1876
- foo: [],
1736
+
1737
+ it('does not throw an error if an object given', async function () {
1738
+ const S = new Schema();
1739
+ S.defineModel({
1740
+ name: 'model',
1741
+ datasource: 'datasource',
1742
+ properties: {
1743
+ foo: DataType.OBJECT,
1744
+ },
1745
+ });
1746
+ await S.getService(ModelDataValidator).validate('model', {
1747
+ foo: {},
1748
+ });
1877
1749
  });
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
1750
  });
1883
1751
 
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,
1752
+ describe('FullPropertyDefinition', function () {
1753
+ it('does not throw an error if an undefined given', async function () {
1754
+ const S = new Schema();
1755
+ S.defineModel({
1756
+ name: 'model',
1757
+ datasource: 'datasource',
1758
+ properties: {
1759
+ foo: {
1760
+ type: DataType.OBJECT,
1761
+ },
1892
1762
  },
1893
- },
1763
+ });
1764
+ await S.getService(ModelDataValidator).validate('model', {
1765
+ foo: undefined,
1766
+ });
1894
1767
  });
1895
- await S.getService(ModelDataValidator).validate('model', {
1896
- foo: {},
1768
+
1769
+ it('does not throw an error if a null given', async function () {
1770
+ const S = new Schema();
1771
+ S.defineModel({
1772
+ name: 'model',
1773
+ datasource: 'datasource',
1774
+ properties: {
1775
+ foo: {
1776
+ type: DataType.OBJECT,
1777
+ },
1778
+ },
1779
+ });
1780
+ await S.getService(ModelDataValidator).validate('model', {
1781
+ foo: null,
1782
+ });
1897
1783
  });
1898
- });
1899
1784
 
1900
- describe('the "model" option', function () {
1901
- it('throws an error when the given object has an invalid model', async function () {
1785
+ it('throws an error if a string given', async function () {
1902
1786
  const S = new Schema();
1903
1787
  S.defineModel({
1904
- name: 'modelA',
1788
+ name: 'model',
1789
+ datasource: 'datasource',
1905
1790
  properties: {
1906
- foo: DataType.STRING,
1791
+ foo: {
1792
+ type: DataType.OBJECT,
1793
+ },
1907
1794
  },
1908
1795
  });
1796
+ const promise = S.getService(ModelDataValidator).validate('model', {
1797
+ foo: 'bar',
1798
+ });
1799
+ await expect(promise).to.be.rejectedWith(
1800
+ 'The property "foo" of the model "model" must have ' +
1801
+ 'an Object, but String given.',
1802
+ );
1803
+ });
1804
+
1805
+ it('throws an error if a number given', async function () {
1806
+ const S = new Schema();
1909
1807
  S.defineModel({
1910
- name: 'modelB',
1808
+ name: 'model',
1911
1809
  datasource: 'datasource',
1912
1810
  properties: {
1913
- bar: {
1811
+ foo: {
1914
1812
  type: DataType.OBJECT,
1915
- model: 'modelA',
1916
1813
  },
1917
1814
  },
1918
1815
  });
1919
- const promise = S.getService(ModelDataValidator).validate(
1920
- 'modelB',
1921
- {
1922
- bar: {foo: 10},
1816
+ const promise = S.getService(ModelDataValidator).validate('model', {
1817
+ foo: 10,
1818
+ });
1819
+ await expect(promise).to.be.rejectedWith(
1820
+ 'The property "foo" of the model "model" must have ' +
1821
+ 'an Object, but Number given.',
1822
+ );
1823
+ });
1824
+
1825
+ it('throws an error if true given', async function () {
1826
+ const S = new Schema();
1827
+ S.defineModel({
1828
+ name: 'model',
1829
+ datasource: 'datasource',
1830
+ properties: {
1831
+ foo: {
1832
+ type: DataType.OBJECT,
1833
+ },
1923
1834
  },
1835
+ });
1836
+ const promise = S.getService(ModelDataValidator).validate('model', {
1837
+ foo: true,
1838
+ });
1839
+ await expect(promise).to.be.rejectedWith(
1840
+ 'The property "foo" of the model "model" must have ' +
1841
+ 'an Object, but Boolean given.',
1924
1842
  );
1843
+ });
1844
+
1845
+ it('throws an error if false given', async function () {
1846
+ const S = new Schema();
1847
+ S.defineModel({
1848
+ name: 'model',
1849
+ datasource: 'datasource',
1850
+ properties: {
1851
+ foo: {
1852
+ type: DataType.OBJECT,
1853
+ },
1854
+ },
1855
+ });
1856
+ const promise = S.getService(ModelDataValidator).validate('model', {
1857
+ foo: false,
1858
+ });
1925
1859
  await expect(promise).to.be.rejectedWith(
1926
- 'The property "foo" of the model "modelA" must have ' +
1927
- 'a String, but Number given.',
1860
+ 'The property "foo" of the model "model" must have ' +
1861
+ 'an Object, but Boolean given.',
1928
1862
  );
1929
1863
  });
1930
1864
 
1931
- it('does not throw an error when the given object has a valid model', async function () {
1865
+ it('throws an error if an array given', async function () {
1932
1866
  const S = new Schema();
1933
1867
  S.defineModel({
1934
- name: 'modelA',
1868
+ name: 'model',
1869
+ datasource: 'datasource',
1935
1870
  properties: {
1936
- foo: DataType.STRING,
1871
+ foo: {
1872
+ type: DataType.OBJECT,
1873
+ },
1937
1874
  },
1938
1875
  });
1876
+ const promise = S.getService(ModelDataValidator).validate('model', {
1877
+ foo: [],
1878
+ });
1879
+ await expect(promise).to.be.rejectedWith(
1880
+ 'The property "foo" of the model "model" must have ' +
1881
+ 'an Object, but Array given.',
1882
+ );
1883
+ });
1884
+
1885
+ it('does not throw an error if an object given', async function () {
1886
+ const S = new Schema();
1939
1887
  S.defineModel({
1940
- name: 'modelB',
1888
+ name: 'model',
1941
1889
  datasource: 'datasource',
1942
1890
  properties: {
1943
- bar: {
1891
+ foo: {
1944
1892
  type: DataType.OBJECT,
1945
- model: 'modelA',
1946
1893
  },
1947
1894
  },
1948
1895
  });
1949
- await S.getService(ModelDataValidator).validate('modelB', {
1950
- bar: {foo: '10'},
1896
+ await S.getService(ModelDataValidator).validate('model', {
1897
+ foo: {},
1898
+ });
1899
+ });
1900
+
1901
+ describe('the "model" option', function () {
1902
+ it('throws an error when the given object has an invalid model', async function () {
1903
+ const S = new Schema();
1904
+ S.defineModel({
1905
+ name: 'modelA',
1906
+ properties: {
1907
+ foo: DataType.STRING,
1908
+ },
1909
+ });
1910
+ S.defineModel({
1911
+ name: 'modelB',
1912
+ datasource: 'datasource',
1913
+ properties: {
1914
+ bar: {
1915
+ type: DataType.OBJECT,
1916
+ model: 'modelA',
1917
+ },
1918
+ },
1919
+ });
1920
+ const promise = S.getService(ModelDataValidator).validate(
1921
+ 'modelB',
1922
+ {
1923
+ bar: {foo: 10},
1924
+ },
1925
+ );
1926
+ await expect(promise).to.be.rejectedWith(
1927
+ 'The property "foo" of the model "modelA" must have ' +
1928
+ 'a String, but Number given.',
1929
+ );
1930
+ });
1931
+
1932
+ it('does not throw an error when the given object has a valid model', async function () {
1933
+ const S = new Schema();
1934
+ S.defineModel({
1935
+ name: 'modelA',
1936
+ properties: {
1937
+ foo: DataType.STRING,
1938
+ },
1939
+ });
1940
+ S.defineModel({
1941
+ name: 'modelB',
1942
+ datasource: 'datasource',
1943
+ properties: {
1944
+ bar: {
1945
+ type: DataType.OBJECT,
1946
+ model: 'modelA',
1947
+ },
1948
+ },
1949
+ });
1950
+ await S.getService(ModelDataValidator).validate('modelB', {
1951
+ bar: {foo: '10'},
1952
+ });
1951
1953
  });
1952
1954
  });
1953
1955
  });