@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.
- package/README.md +3 -2
- package/docs/index.html +4 -2
- package/package.json +1 -1
- package/src/definition/model/model-data-validator.js +6 -11
- package/src/definition/model/model-data-validator.spec.js +1485 -1483
- package/src/definition/model/properties/property-validator/builtin/index.d.ts +1 -0
- package/src/definition/model/properties/property-validator/builtin/index.js +1 -0
- package/src/definition/model/properties/property-validator/builtin/max-length-validator.spec.js +29 -1
- package/src/definition/model/properties/property-validator/builtin/min-length-validator.spec.js +29 -1
- package/src/definition/model/properties/property-validator/builtin/regexp-validator.d.ts +6 -0
- package/src/definition/model/properties/property-validator/builtin/regexp-validator.js +30 -0
- package/src/definition/model/properties/property-validator/builtin/regexp-validator.spec.js +95 -0
- package/src/definition/model/properties/property-validator/property-validator-registry.js +2 -0
|
@@ -174,1780 +174,1782 @@ describe('ModelDataValidator', function () {
|
|
|
174
174
|
});
|
|
175
175
|
});
|
|
176
176
|
|
|
177
|
-
describe('
|
|
178
|
-
describe('
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
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
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
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
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
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
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
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
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
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
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
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
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
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
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
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
|
-
|
|
305
|
-
|
|
304
|
+
});
|
|
305
|
+
await S.getService(ModelDataValidator).validate('model', {
|
|
306
|
+
foo: undefined,
|
|
307
|
+
});
|
|
306
308
|
});
|
|
307
|
-
});
|
|
308
309
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
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
|
-
|
|
321
|
-
|
|
320
|
+
});
|
|
321
|
+
await S.getService(ModelDataValidator).validate('model', {
|
|
322
|
+
foo: null,
|
|
323
|
+
});
|
|
322
324
|
});
|
|
323
|
-
});
|
|
324
325
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
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
|
-
|
|
337
|
-
|
|
336
|
+
});
|
|
337
|
+
await S.getService(ModelDataValidator).validate('model', {
|
|
338
|
+
foo: 'bar',
|
|
339
|
+
});
|
|
338
340
|
});
|
|
339
|
-
});
|
|
340
341
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
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
|
-
|
|
353
|
-
|
|
352
|
+
});
|
|
353
|
+
await S.getService(ModelDataValidator).validate('model', {
|
|
354
|
+
foo: 10,
|
|
355
|
+
});
|
|
354
356
|
});
|
|
355
|
-
});
|
|
356
357
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
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
|
-
|
|
369
|
-
|
|
368
|
+
});
|
|
369
|
+
await S.getService(ModelDataValidator).validate('model', {
|
|
370
|
+
foo: true,
|
|
371
|
+
});
|
|
370
372
|
});
|
|
371
|
-
});
|
|
372
373
|
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
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
|
-
|
|
385
|
-
|
|
384
|
+
});
|
|
385
|
+
await S.getService(ModelDataValidator).validate('model', {
|
|
386
|
+
foo: false,
|
|
387
|
+
});
|
|
386
388
|
});
|
|
387
|
-
});
|
|
388
389
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
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
|
-
|
|
401
|
-
|
|
400
|
+
});
|
|
401
|
+
await S.getService(ModelDataValidator).validate('model', {
|
|
402
|
+
foo: [],
|
|
403
|
+
});
|
|
402
404
|
});
|
|
403
|
-
});
|
|
404
405
|
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
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
|
-
|
|
417
|
-
|
|
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
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
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
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
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
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
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
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
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
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
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
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
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
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
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
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
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
|
-
|
|
571
|
-
|
|
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
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
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
|
-
|
|
587
|
-
|
|
570
|
+
});
|
|
571
|
+
await S.getService(ModelDataValidator).validate('model', {
|
|
572
|
+
foo: undefined,
|
|
573
|
+
});
|
|
588
574
|
});
|
|
589
|
-
});
|
|
590
575
|
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
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
|
-
|
|
603
|
-
|
|
586
|
+
});
|
|
587
|
+
await S.getService(ModelDataValidator).validate('model', {
|
|
588
|
+
foo: null,
|
|
589
|
+
});
|
|
604
590
|
});
|
|
605
|
-
});
|
|
606
591
|
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
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
|
-
|
|
619
|
-
|
|
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
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
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
|
-
|
|
639
|
-
|
|
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
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
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
|
-
|
|
659
|
-
|
|
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
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
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
|
-
|
|
679
|
-
|
|
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
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
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
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
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
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
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
|
-
|
|
857
|
-
|
|
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
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
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
|
-
|
|
873
|
-
|
|
720
|
+
});
|
|
721
|
+
await S.getService(ModelDataValidator).validate('model', {
|
|
722
|
+
foo: undefined,
|
|
723
|
+
});
|
|
874
724
|
});
|
|
875
|
-
});
|
|
876
725
|
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
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
|
-
|
|
889
|
-
|
|
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
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
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
|
-
|
|
909
|
-
|
|
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
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
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
|
-
|
|
925
|
-
|
|
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
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
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
|
-
|
|
945
|
-
|
|
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
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
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
|
-
|
|
965
|
-
|
|
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
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
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
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
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
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
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
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
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
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
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
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
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
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
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
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
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
|
-
|
|
1139
|
-
|
|
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
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
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
|
-
|
|
1155
|
-
|
|
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
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
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
|
-
|
|
1171
|
-
|
|
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
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
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
|
-
|
|
1191
|
-
|
|
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
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
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
|
-
|
|
1211
|
-
|
|
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
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
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
|
-
|
|
1227
|
-
|
|
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
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
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
|
-
|
|
1243
|
-
|
|
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
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
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
|
-
|
|
1263
|
-
|
|
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
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
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
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
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
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
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
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
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
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
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
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
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
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
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
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
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
|
-
|
|
1399
|
-
|
|
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('
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
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
|
-
|
|
1421
|
-
|
|
1284
|
+
});
|
|
1285
|
+
await S.getService(ModelDataValidator).validate('model', {
|
|
1286
|
+
foo: undefined,
|
|
1287
|
+
});
|
|
1422
1288
|
});
|
|
1423
|
-
});
|
|
1424
1289
|
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
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
|
-
|
|
1437
|
-
|
|
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
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
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
|
-
|
|
1453
|
-
|
|
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
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
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
|
-
|
|
1473
|
-
|
|
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
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
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
|
-
|
|
1493
|
-
|
|
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
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
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
|
-
|
|
1513
|
-
|
|
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
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
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
|
-
|
|
1533
|
-
|
|
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
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
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
|
-
|
|
1549
|
-
|
|
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
|
-
|
|
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: '
|
|
1429
|
+
name: 'model',
|
|
1430
|
+
datasource: 'datasource',
|
|
1562
1431
|
properties: {
|
|
1563
|
-
foo:
|
|
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: '
|
|
1445
|
+
name: 'model',
|
|
1568
1446
|
datasource: 'datasource',
|
|
1569
1447
|
properties: {
|
|
1570
|
-
|
|
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
|
-
'
|
|
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 "
|
|
1585
|
-
'
|
|
1457
|
+
'The property "foo" of the model "model" must have ' +
|
|
1458
|
+
'an Array, but String given.',
|
|
1586
1459
|
);
|
|
1587
1460
|
});
|
|
1588
1461
|
|
|
1589
|
-
it('
|
|
1462
|
+
it('throws an error if a number given', async function () {
|
|
1590
1463
|
const S = new Schema();
|
|
1591
1464
|
S.defineModel({
|
|
1592
|
-
name: '
|
|
1465
|
+
name: 'model',
|
|
1466
|
+
datasource: 'datasource',
|
|
1593
1467
|
properties: {
|
|
1594
|
-
foo:
|
|
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: '
|
|
1485
|
+
name: 'model',
|
|
1599
1486
|
datasource: 'datasource',
|
|
1600
1487
|
properties: {
|
|
1601
|
-
|
|
1488
|
+
foo: {
|
|
1602
1489
|
type: DataType.ARRAY,
|
|
1603
|
-
itemType: DataType.OBJECT,
|
|
1604
|
-
model: 'modelA',
|
|
1605
1490
|
},
|
|
1606
1491
|
},
|
|
1607
1492
|
});
|
|
1608
|
-
|
|
1609
|
-
|
|
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
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
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
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
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
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
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
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
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
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
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('
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
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
|
-
|
|
1764
|
-
|
|
1627
|
+
});
|
|
1628
|
+
await S.getService(ModelDataValidator).validate('model', {
|
|
1629
|
+
foo: undefined,
|
|
1630
|
+
});
|
|
1765
1631
|
});
|
|
1766
|
-
});
|
|
1767
1632
|
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
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
|
-
|
|
1780
|
-
|
|
1641
|
+
});
|
|
1642
|
+
await S.getService(ModelDataValidator).validate('model', {
|
|
1643
|
+
foo: null,
|
|
1644
|
+
});
|
|
1781
1645
|
});
|
|
1782
|
-
});
|
|
1783
1646
|
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
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
|
-
|
|
1796
|
-
|
|
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
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
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
|
-
|
|
1816
|
-
|
|
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
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
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
|
-
|
|
1836
|
-
|
|
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
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
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
|
-
|
|
1856
|
-
|
|
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
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
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
|
-
|
|
1876
|
-
|
|
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
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
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
|
-
|
|
1896
|
-
|
|
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
|
-
|
|
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: '
|
|
1788
|
+
name: 'model',
|
|
1789
|
+
datasource: 'datasource',
|
|
1905
1790
|
properties: {
|
|
1906
|
-
foo:
|
|
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: '
|
|
1808
|
+
name: 'model',
|
|
1911
1809
|
datasource: 'datasource',
|
|
1912
1810
|
properties: {
|
|
1913
|
-
|
|
1811
|
+
foo: {
|
|
1914
1812
|
type: DataType.OBJECT,
|
|
1915
|
-
model: 'modelA',
|
|
1916
1813
|
},
|
|
1917
1814
|
},
|
|
1918
1815
|
});
|
|
1919
|
-
const promise = S.getService(ModelDataValidator).validate(
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
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 "
|
|
1927
|
-
'
|
|
1860
|
+
'The property "foo" of the model "model" must have ' +
|
|
1861
|
+
'an Object, but Boolean given.',
|
|
1928
1862
|
);
|
|
1929
1863
|
});
|
|
1930
1864
|
|
|
1931
|
-
it('
|
|
1865
|
+
it('throws an error if an array given', async function () {
|
|
1932
1866
|
const S = new Schema();
|
|
1933
1867
|
S.defineModel({
|
|
1934
|
-
name: '
|
|
1868
|
+
name: 'model',
|
|
1869
|
+
datasource: 'datasource',
|
|
1935
1870
|
properties: {
|
|
1936
|
-
foo:
|
|
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: '
|
|
1888
|
+
name: 'model',
|
|
1941
1889
|
datasource: 'datasource',
|
|
1942
1890
|
properties: {
|
|
1943
|
-
|
|
1891
|
+
foo: {
|
|
1944
1892
|
type: DataType.OBJECT,
|
|
1945
|
-
model: 'modelA',
|
|
1946
1893
|
},
|
|
1947
1894
|
},
|
|
1948
1895
|
});
|
|
1949
|
-
await S.getService(ModelDataValidator).validate('
|
|
1950
|
-
|
|
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
|
});
|