@e22m4u/js-repository 0.1.3 → 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 +33 -33
- package/assets/mermaid-diagram.png +0 -0
- package/assets/mermaid-diagram.txt +29 -0
- package/docs/assets/main.js +4 -4
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/Adapter.html +14 -14
- package/docs/classes/AdapterLoader.html +2 -2
- package/docs/classes/AdapterRegistry.html +2 -2
- package/docs/classes/BelongsToResolver.html +3 -3
- package/docs/classes/DatasourceDefinitionValidator.html +2 -2
- package/docs/classes/DefinitionRegistry.html +7 -7
- package/docs/classes/FieldsClauseTool.html +4 -4
- package/docs/classes/HasManyResolver.html +4 -4
- package/docs/classes/HasOneResolver.html +4 -4
- package/docs/classes/IncludeClauseTool.html +6 -6
- package/docs/classes/InvalidArgumentError.html +1 -1
- package/docs/classes/InvalidOperatorValueError.html +2 -2
- package/docs/classes/ModelDataSanitizer.html +2 -2
- package/docs/classes/ModelDataValidator.html +3 -5
- package/docs/classes/ModelDefinitionUtils.html +17 -17
- package/docs/classes/ModelDefinitionValidator.html +2 -2
- package/docs/classes/NotImplementedError.html +1 -1
- package/docs/classes/OperatorClauseTool.html +14 -14
- package/docs/classes/OrderClauseTool.html +4 -4
- package/docs/classes/PrimaryKeysDefinitionValidator.html +2 -2
- package/docs/classes/PropertiesDefinitionValidator.html +2 -2
- package/docs/classes/PropertyValidatorRegistry.html +20 -0
- package/docs/classes/ReferencesManyResolver.html +2 -2
- package/docs/classes/RelationsDefinitionValidator.html +2 -2
- package/docs/classes/Repository.html +17 -17
- package/docs/classes/RepositoryRegistry.html +3 -3
- package/docs/classes/Schema.html +4 -4
- package/docs/classes/SliceClauseTool.html +4 -4
- package/docs/classes/WhereClauseTool.html +3 -3
- package/docs/enums/DataType.html +2 -2
- package/docs/enums/DecoratorTargetType.html +2 -2
- package/docs/enums/RelationType.html +2 -2
- package/docs/functions/capitalize.html +1 -1
- package/docs/functions/cloneDeep.html +1 -1
- package/docs/functions/excludeObjectKeys.html +1 -1
- package/docs/functions/getCtorName.html +1 -1
- package/docs/functions/getDecoratorTargetType.html +1 -1
- package/docs/functions/getValueByPath.html +1 -1
- package/docs/functions/isCtor.html +1 -1
- package/docs/functions/isPureObject.html +1 -1
- package/docs/functions/selectObjectKeys.html +1 -1
- package/docs/functions/singularize.html +1 -1
- package/docs/functions/stringToRegexp.html +1 -1
- package/docs/index.html +18 -4
- package/docs/interfaces/AndClause.html +2 -2
- package/docs/interfaces/Constructor.html +2 -2
- package/docs/interfaces/OrClause.html +2 -2
- package/docs/modules.html +4 -0
- package/docs/types/AnyObject.html +1 -1
- package/docs/types/BelongsToDefinition.html +1 -1
- package/docs/types/DEFAULT_PRIMARY_KEY_PROPERTY_NAME.html +1 -1
- package/docs/types/DatasourceDefinition.html +1 -1
- package/docs/types/FieldsClause.html +1 -1
- package/docs/types/FilterClause.html +1 -1
- package/docs/types/Flatten.html +1 -1
- package/docs/types/FullPropertyDefinition.html +2 -2
- package/docs/types/HasManyDefinition.html +1 -1
- package/docs/types/HasOneDefinition.html +1 -1
- package/docs/types/Identity.html +1 -1
- package/docs/types/IncludeClause.html +1 -1
- package/docs/types/ItemFilterClause.html +1 -1
- package/docs/types/ModelData.html +1 -1
- package/docs/types/ModelDefinition.html +1 -1
- package/docs/types/ModelId.html +1 -1
- package/docs/types/NestedIncludeClause.html +1 -1
- package/docs/types/NormalizedFieldsClause.html +1 -1
- package/docs/types/NormalizedIncludeClause.html +1 -1
- package/docs/types/OperatorClause.html +1 -1
- package/docs/types/OptionalUnlessRequiredId.html +1 -1
- package/docs/types/OrderClause.html +1 -1
- package/docs/types/PartialBy.html +1 -1
- package/docs/types/PartialWithoutId.html +1 -1
- package/docs/types/PolyBelongsToDefinition.html +1 -1
- package/docs/types/PolyHasManyDefinitionWithTargetKeys.html +1 -1
- package/docs/types/PolyHasManyDefinitionWithTargetRelationName.html +1 -1
- package/docs/types/PolyHasOneDefinitionWithTargetKeys.html +1 -1
- package/docs/types/PolyHasOneDefinitionWithTargetRelationName.html +1 -1
- package/docs/types/PropertiesClause.html +1 -1
- package/docs/types/PropertyDefinition.html +1 -1
- package/docs/types/PropertyDefinitionMap.html +1 -1
- package/docs/types/PropertyValidateOptions.html +2 -0
- package/docs/types/PropertyValidator.html +2 -0
- package/docs/types/PropertyValidatorContext.html +2 -0
- package/docs/types/ReferencesManyDefinition.html +1 -1
- package/docs/types/RelationDefinition.html +1 -1
- package/docs/types/RelationDefinitionMap.html +1 -1
- package/docs/types/WhereClause.html +1 -1
- package/docs/types/WithoutId.html +1 -1
- package/package.json +2 -2
- package/src/definition/model/model-data-validator.js +7 -17
- package/src/definition/model/model-data-validator.spec.js +1577 -1543
- package/src/definition/model/properties/property-validator/builtin/index.d.ts +3 -0
- package/src/definition/model/properties/property-validator/builtin/index.js +3 -0
- package/src/definition/model/properties/property-validator/builtin/max-length-validator.d.ts +6 -0
- package/src/definition/model/properties/property-validator/builtin/max-length-validator.js +28 -0
- package/src/definition/model/properties/property-validator/builtin/max-length-validator.spec.js +93 -0
- package/src/definition/model/properties/property-validator/builtin/min-length-validator.d.ts +6 -0
- package/src/definition/model/properties/property-validator/builtin/min-length-validator.js +28 -0
- package/src/definition/model/properties/property-validator/builtin/min-length-validator.spec.js +93 -0
- 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 +8 -1
- package/src/definition/model/properties/property-validator/property-validator-registry.spec.js +1 -1
- package/src/schema.d.ts +0 -9
- package/src/schema.js +0 -13
- package/src/schema.spec.ts +0 -29
|
@@ -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
|
-
}
|
|
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
|
+
);
|
|
697
686
|
});
|
|
698
|
-
|
|
699
|
-
|
|
687
|
+
|
|
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
|
+
},
|
|
697
|
+
},
|
|
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
|
+
);
|
|
700
706
|
});
|
|
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
707
|
});
|
|
706
708
|
});
|
|
707
|
-
});
|
|
708
709
|
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
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,
|
|
719
|
+
},
|
|
720
|
+
});
|
|
721
|
+
await S.getService(ModelDataValidator).validate('model', {
|
|
722
|
+
foo: undefined,
|
|
723
|
+
});
|
|
722
724
|
});
|
|
723
|
-
});
|
|
724
725
|
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
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,
|
|
733
|
+
},
|
|
734
|
+
});
|
|
735
|
+
await S.getService(ModelDataValidator).validate('model', {
|
|
736
|
+
foo: null,
|
|
737
|
+
});
|
|
736
738
|
});
|
|
737
|
-
});
|
|
738
739
|
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
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,
|
|
747
|
+
},
|
|
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
|
+
);
|
|
750
756
|
});
|
|
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
|
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
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,
|
|
765
|
+
},
|
|
766
|
+
});
|
|
767
|
+
await S.getService(ModelDataValidator).validate('model', {
|
|
768
|
+
foo: 10,
|
|
769
|
+
});
|
|
768
770
|
});
|
|
769
|
-
});
|
|
770
771
|
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
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,
|
|
779
|
+
},
|
|
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
|
+
);
|
|
782
788
|
});
|
|
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
|
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
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,
|
|
797
|
+
},
|
|
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
|
+
);
|
|
800
806
|
});
|
|
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
|
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
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,
|
|
815
|
+
},
|
|
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
|
+
);
|
|
818
824
|
});
|
|
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
|
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
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
|
+
);
|
|
836
842
|
});
|
|
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
843
|
});
|
|
842
|
-
});
|
|
843
844
|
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
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
|
+
},
|
|
853
855
|
},
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
856
|
+
});
|
|
857
|
+
await S.getService(ModelDataValidator).validate('model', {
|
|
858
|
+
foo: undefined,
|
|
859
|
+
});
|
|
858
860
|
});
|
|
859
|
-
});
|
|
860
861
|
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
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
|
+
},
|
|
869
871
|
},
|
|
870
|
-
}
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
872
|
+
});
|
|
873
|
+
await S.getService(ModelDataValidator).validate('model', {
|
|
874
|
+
foo: null,
|
|
875
|
+
});
|
|
874
876
|
});
|
|
875
|
-
});
|
|
876
877
|
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
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
|
+
},
|
|
885
887
|
},
|
|
886
|
-
}
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
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
|
+
);
|
|
890
896
|
});
|
|
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
897
|
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
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
|
+
},
|
|
905
907
|
},
|
|
906
|
-
}
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
908
|
+
});
|
|
909
|
+
await S.getService(ModelDataValidator).validate('model', {
|
|
910
|
+
foo: 10,
|
|
911
|
+
});
|
|
910
912
|
});
|
|
911
|
-
});
|
|
912
913
|
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
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
|
+
},
|
|
921
923
|
},
|
|
922
|
-
}
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
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
|
+
);
|
|
926
932
|
});
|
|
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
933
|
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
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
|
+
},
|
|
941
943
|
},
|
|
942
|
-
}
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
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
|
+
);
|
|
946
952
|
});
|
|
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
953
|
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
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
|
+
},
|
|
961
963
|
},
|
|
962
|
-
}
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
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
|
+
);
|
|
966
972
|
});
|
|
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
973
|
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
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
|
+
},
|
|
981
983
|
},
|
|
982
|
-
}
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
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
|
+
);
|
|
986
992
|
});
|
|
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
993
|
});
|
|
992
994
|
});
|
|
993
|
-
});
|
|
994
995
|
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
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,
|
|
1005
|
+
},
|
|
1006
|
+
});
|
|
1007
|
+
await S.getService(ModelDataValidator).validate('model', {
|
|
1008
|
+
foo: undefined,
|
|
1009
|
+
});
|
|
1008
1010
|
});
|
|
1009
|
-
});
|
|
1010
1011
|
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
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,
|
|
1019
|
+
},
|
|
1020
|
+
});
|
|
1021
|
+
await S.getService(ModelDataValidator).validate('model', {
|
|
1022
|
+
foo: null,
|
|
1023
|
+
});
|
|
1022
1024
|
});
|
|
1023
|
-
});
|
|
1024
1025
|
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
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
|
+
);
|
|
1036
1042
|
});
|
|
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
1043
|
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
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,
|
|
1051
|
+
},
|
|
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
|
+
);
|
|
1054
1060
|
});
|
|
1055
|
-
await expect(promise).to.be.rejectedWith(
|
|
1056
|
-
'The property "foo" of the model "model" must have ' +
|
|
1057
|
-
'a Boolean, but Number given.',
|
|
1058
|
-
);
|
|
1059
|
-
});
|
|
1060
1061
|
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
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
|
+
});
|
|
1072
1074
|
});
|
|
1073
|
-
});
|
|
1074
1075
|
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
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,
|
|
1083
|
+
},
|
|
1084
|
+
});
|
|
1085
|
+
await S.getService(ModelDataValidator).validate('model', {
|
|
1086
|
+
foo: false,
|
|
1087
|
+
});
|
|
1086
1088
|
});
|
|
1087
|
-
});
|
|
1088
1089
|
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
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,
|
|
1097
|
+
},
|
|
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
|
+
);
|
|
1100
1106
|
});
|
|
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
1107
|
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
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
|
+
);
|
|
1118
1124
|
});
|
|
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
1125
|
});
|
|
1124
|
-
});
|
|
1125
1126
|
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
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
|
+
},
|
|
1135
1137
|
},
|
|
1136
|
-
}
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1138
|
+
});
|
|
1139
|
+
await S.getService(ModelDataValidator).validate('model', {
|
|
1140
|
+
foo: undefined,
|
|
1141
|
+
});
|
|
1140
1142
|
});
|
|
1141
|
-
});
|
|
1142
1143
|
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
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
|
+
},
|
|
1151
1153
|
},
|
|
1152
|
-
}
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1154
|
+
});
|
|
1155
|
+
await S.getService(ModelDataValidator).validate('model', {
|
|
1156
|
+
foo: null,
|
|
1157
|
+
});
|
|
1156
1158
|
});
|
|
1157
|
-
});
|
|
1158
1159
|
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
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
|
+
},
|
|
1167
1169
|
},
|
|
1168
|
-
}
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
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
|
+
);
|
|
1172
1178
|
});
|
|
1173
|
-
await expect(promise).to.be.rejectedWith(
|
|
1174
|
-
'The property "foo" of the model "model" must have ' +
|
|
1175
|
-
'a Boolean, but String given.',
|
|
1176
|
-
);
|
|
1177
|
-
});
|
|
1178
1179
|
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
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
|
+
},
|
|
1187
1189
|
},
|
|
1188
|
-
}
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
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
|
+
);
|
|
1192
1198
|
});
|
|
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
1199
|
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
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
|
+
},
|
|
1207
1209
|
},
|
|
1208
|
-
}
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1210
|
+
});
|
|
1211
|
+
await S.getService(ModelDataValidator).validate('model', {
|
|
1212
|
+
foo: true,
|
|
1213
|
+
});
|
|
1212
1214
|
});
|
|
1213
|
-
});
|
|
1214
1215
|
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
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
|
+
},
|
|
1223
1225
|
},
|
|
1224
|
-
}
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1226
|
+
});
|
|
1227
|
+
await S.getService(ModelDataValidator).validate('model', {
|
|
1228
|
+
foo: false,
|
|
1229
|
+
});
|
|
1228
1230
|
});
|
|
1229
|
-
});
|
|
1230
1231
|
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
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
|
+
},
|
|
1239
1241
|
},
|
|
1240
|
-
}
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
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
|
+
);
|
|
1244
1250
|
});
|
|
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
1251
|
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
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
|
+
},
|
|
1259
1261
|
},
|
|
1260
|
-
}
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
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
|
+
);
|
|
1264
1270
|
});
|
|
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
1271
|
});
|
|
1270
1272
|
});
|
|
1271
|
-
});
|
|
1272
1273
|
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
});
|
|
1288
|
-
|
|
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,
|
|
1300
|
-
});
|
|
1301
|
-
});
|
|
1302
|
-
|
|
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',
|
|
1314
|
-
});
|
|
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
|
-
|
|
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,
|
|
1332
|
-
});
|
|
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
|
-
|
|
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,
|
|
1350
|
-
});
|
|
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
|
-
|
|
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,
|
|
1368
|
-
});
|
|
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
|
-
|
|
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: [],
|
|
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,
|
|
1283
|
+
},
|
|
1284
|
+
});
|
|
1285
|
+
await S.getService(ModelDataValidator).validate('model', {
|
|
1286
|
+
foo: undefined,
|
|
1287
|
+
});
|
|
1386
1288
|
});
|
|
1387
|
-
});
|
|
1388
1289
|
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
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,
|
|
1297
|
+
},
|
|
1298
|
+
});
|
|
1299
|
+
await S.getService(ModelDataValidator).validate('model', {
|
|
1300
|
+
foo: null,
|
|
1301
|
+
});
|
|
1400
1302
|
});
|
|
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
|
-
});
|
|
1406
|
-
});
|
|
1407
1303
|
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
foo: {
|
|
1416
|
-
type: DataType.ARRAY,
|
|
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,
|
|
1417
1311
|
},
|
|
1418
|
-
}
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
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
|
+
);
|
|
1422
1320
|
});
|
|
1423
|
-
});
|
|
1424
1321
|
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
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,
|
|
1433
1329
|
},
|
|
1434
|
-
}
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
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
|
+
);
|
|
1438
1338
|
});
|
|
1439
|
-
});
|
|
1440
1339
|
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
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,
|
|
1449
1347
|
},
|
|
1450
|
-
}
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
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
|
+
);
|
|
1454
1356
|
});
|
|
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
1357
|
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
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,
|
|
1469
1365
|
},
|
|
1470
|
-
}
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
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
|
+
);
|
|
1474
1374
|
});
|
|
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
1375
|
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
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,
|
|
1489
1383
|
},
|
|
1490
|
-
}
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1384
|
+
});
|
|
1385
|
+
await S.getService(ModelDataValidator).validate('model', {
|
|
1386
|
+
foo: [],
|
|
1387
|
+
});
|
|
1494
1388
|
});
|
|
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
1389
|
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
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,
|
|
1509
1397
|
},
|
|
1510
|
-
}
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
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
|
+
);
|
|
1514
1406
|
});
|
|
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
1407
|
});
|
|
1520
1408
|
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
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
|
+
},
|
|
1529
1419
|
},
|
|
1530
|
-
}
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1420
|
+
});
|
|
1421
|
+
await S.getService(ModelDataValidator).validate('model', {
|
|
1422
|
+
foo: undefined,
|
|
1423
|
+
});
|
|
1534
1424
|
});
|
|
1535
|
-
});
|
|
1536
1425
|
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1426
|
+
it('does not throw an error if a null given', async function () {
|
|
1427
|
+
const S = new Schema();
|
|
1428
|
+
S.defineModel({
|
|
1429
|
+
name: 'model',
|
|
1430
|
+
datasource: 'datasource',
|
|
1431
|
+
properties: {
|
|
1432
|
+
foo: {
|
|
1433
|
+
type: DataType.ARRAY,
|
|
1434
|
+
},
|
|
1545
1435
|
},
|
|
1546
|
-
}
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1436
|
+
});
|
|
1437
|
+
await S.getService(ModelDataValidator).validate('model', {
|
|
1438
|
+
foo: null,
|
|
1439
|
+
});
|
|
1550
1440
|
});
|
|
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
1441
|
|
|
1557
|
-
|
|
1558
|
-
it('throws an error when the given object element has an invalid model', async function () {
|
|
1442
|
+
it('throws an error if a string given', async function () {
|
|
1559
1443
|
const S = new Schema();
|
|
1560
1444
|
S.defineModel({
|
|
1561
|
-
name: '
|
|
1445
|
+
name: 'model',
|
|
1446
|
+
datasource: 'datasource',
|
|
1562
1447
|
properties: {
|
|
1563
|
-
foo:
|
|
1448
|
+
foo: {
|
|
1449
|
+
type: DataType.ARRAY,
|
|
1450
|
+
},
|
|
1564
1451
|
},
|
|
1565
1452
|
});
|
|
1453
|
+
const promise = S.getService(ModelDataValidator).validate('model', {
|
|
1454
|
+
foo: 'bar',
|
|
1455
|
+
});
|
|
1456
|
+
await expect(promise).to.be.rejectedWith(
|
|
1457
|
+
'The property "foo" of the model "model" must have ' +
|
|
1458
|
+
'an Array, but String given.',
|
|
1459
|
+
);
|
|
1460
|
+
});
|
|
1461
|
+
|
|
1462
|
+
it('throws an error if a number given', async function () {
|
|
1463
|
+
const S = new Schema();
|
|
1566
1464
|
S.defineModel({
|
|
1567
|
-
name: '
|
|
1465
|
+
name: 'model',
|
|
1568
1466
|
datasource: 'datasource',
|
|
1569
1467
|
properties: {
|
|
1570
|
-
|
|
1468
|
+
foo: {
|
|
1571
1469
|
type: DataType.ARRAY,
|
|
1572
|
-
itemType: DataType.OBJECT,
|
|
1573
|
-
model: 'modelA',
|
|
1574
1470
|
},
|
|
1575
1471
|
},
|
|
1576
1472
|
});
|
|
1577
|
-
const promise = S.getService(ModelDataValidator).validate(
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
bar: [{foo: 10}],
|
|
1581
|
-
},
|
|
1582
|
-
);
|
|
1473
|
+
const promise = S.getService(ModelDataValidator).validate('model', {
|
|
1474
|
+
foo: 10,
|
|
1475
|
+
});
|
|
1583
1476
|
await expect(promise).to.be.rejectedWith(
|
|
1584
|
-
'The property "foo" of the model "
|
|
1585
|
-
'
|
|
1477
|
+
'The property "foo" of the model "model" must have ' +
|
|
1478
|
+
'an Array, but Number given.',
|
|
1586
1479
|
);
|
|
1587
1480
|
});
|
|
1588
1481
|
|
|
1589
|
-
it('
|
|
1482
|
+
it('throws an error if true given', async function () {
|
|
1590
1483
|
const S = new Schema();
|
|
1591
1484
|
S.defineModel({
|
|
1592
|
-
name: '
|
|
1485
|
+
name: 'model',
|
|
1486
|
+
datasource: 'datasource',
|
|
1593
1487
|
properties: {
|
|
1594
|
-
foo:
|
|
1488
|
+
foo: {
|
|
1489
|
+
type: DataType.ARRAY,
|
|
1490
|
+
},
|
|
1595
1491
|
},
|
|
1596
1492
|
});
|
|
1493
|
+
const promise = S.getService(ModelDataValidator).validate('model', {
|
|
1494
|
+
foo: true,
|
|
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
|
+
);
|
|
1500
|
+
});
|
|
1501
|
+
|
|
1502
|
+
it('throws an error if false given', async function () {
|
|
1503
|
+
const S = new Schema();
|
|
1597
1504
|
S.defineModel({
|
|
1598
|
-
name: '
|
|
1505
|
+
name: 'model',
|
|
1599
1506
|
datasource: 'datasource',
|
|
1600
1507
|
properties: {
|
|
1601
|
-
|
|
1508
|
+
foo: {
|
|
1602
1509
|
type: DataType.ARRAY,
|
|
1603
|
-
itemType: DataType.OBJECT,
|
|
1604
|
-
model: 'modelA',
|
|
1605
1510
|
},
|
|
1606
1511
|
},
|
|
1607
1512
|
});
|
|
1608
|
-
|
|
1609
|
-
|
|
1513
|
+
const promise = S.getService(ModelDataValidator).validate('model', {
|
|
1514
|
+
foo: false,
|
|
1610
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
|
+
);
|
|
1611
1520
|
});
|
|
1612
|
-
});
|
|
1613
|
-
});
|
|
1614
|
-
});
|
|
1615
1521
|
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
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
|
+
});
|
|
1629
1536
|
});
|
|
1630
|
-
});
|
|
1631
1537
|
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
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
|
+
);
|
|
1643
1556
|
});
|
|
1644
|
-
});
|
|
1645
1557
|
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
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
|
+
});
|
|
1663
1589
|
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
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
|
+
});
|
|
1675
1613
|
});
|
|
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
1614
|
});
|
|
1615
|
+
});
|
|
1681
1616
|
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
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,
|
|
1626
|
+
},
|
|
1627
|
+
});
|
|
1628
|
+
await S.getService(ModelDataValidator).validate('model', {
|
|
1629
|
+
foo: undefined,
|
|
1630
|
+
});
|
|
1693
1631
|
});
|
|
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
1632
|
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
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,
|
|
1640
|
+
},
|
|
1641
|
+
});
|
|
1642
|
+
await S.getService(ModelDataValidator).validate('model', {
|
|
1643
|
+
foo: null,
|
|
1644
|
+
});
|
|
1711
1645
|
});
|
|
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
1646
|
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
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,
|
|
1654
|
+
},
|
|
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
|
+
);
|
|
1729
1663
|
});
|
|
1730
|
-
await expect(promise).to.be.rejectedWith(
|
|
1731
|
-
'The property "foo" of the model "model" must have ' +
|
|
1732
|
-
'an Object, but Array given.',
|
|
1733
|
-
);
|
|
1734
|
-
});
|
|
1735
1664
|
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
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,
|
|
1672
|
+
},
|
|
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
|
+
);
|
|
1747
1681
|
});
|
|
1748
|
-
});
|
|
1749
|
-
});
|
|
1750
1682
|
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
foo: {
|
|
1759
|
-
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,
|
|
1760
1690
|
},
|
|
1761
|
-
}
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
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
|
+
);
|
|
1765
1699
|
});
|
|
1766
|
-
});
|
|
1767
1700
|
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
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,
|
|
1776
1708
|
},
|
|
1777
|
-
}
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
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
|
+
);
|
|
1781
1717
|
});
|
|
1782
|
-
});
|
|
1783
1718
|
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
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,
|
|
1792
1726
|
},
|
|
1793
|
-
}
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
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
|
+
);
|
|
1797
1735
|
});
|
|
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
1736
|
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
type: DataType.OBJECT,
|
|
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,
|
|
1812
1744
|
},
|
|
1813
|
-
}
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1745
|
+
});
|
|
1746
|
+
await S.getService(ModelDataValidator).validate('model', {
|
|
1747
|
+
foo: {},
|
|
1748
|
+
});
|
|
1817
1749
|
});
|
|
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
1750
|
});
|
|
1823
1751
|
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
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
|
+
},
|
|
1832
1762
|
},
|
|
1833
|
-
}
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1763
|
+
});
|
|
1764
|
+
await S.getService(ModelDataValidator).validate('model', {
|
|
1765
|
+
foo: undefined,
|
|
1766
|
+
});
|
|
1837
1767
|
});
|
|
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
1768
|
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
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
|
+
},
|
|
1852
1778
|
},
|
|
1853
|
-
}
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1779
|
+
});
|
|
1780
|
+
await S.getService(ModelDataValidator).validate('model', {
|
|
1781
|
+
foo: null,
|
|
1782
|
+
});
|
|
1857
1783
|
});
|
|
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
1784
|
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1785
|
+
it('throws an error if a string given', async function () {
|
|
1786
|
+
const S = new Schema();
|
|
1787
|
+
S.defineModel({
|
|
1788
|
+
name: 'model',
|
|
1789
|
+
datasource: 'datasource',
|
|
1790
|
+
properties: {
|
|
1791
|
+
foo: {
|
|
1792
|
+
type: DataType.OBJECT,
|
|
1793
|
+
},
|
|
1872
1794
|
},
|
|
1873
|
-
}
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
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
|
+
);
|
|
1877
1803
|
});
|
|
1878
|
-
await expect(promise).to.be.rejectedWith(
|
|
1879
|
-
'The property "foo" of the model "model" must have ' +
|
|
1880
|
-
'an Object, but Array given.',
|
|
1881
|
-
);
|
|
1882
|
-
});
|
|
1883
1804
|
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1805
|
+
it('throws an error if a number given', async function () {
|
|
1806
|
+
const S = new Schema();
|
|
1807
|
+
S.defineModel({
|
|
1808
|
+
name: 'model',
|
|
1809
|
+
datasource: 'datasource',
|
|
1810
|
+
properties: {
|
|
1811
|
+
foo: {
|
|
1812
|
+
type: DataType.OBJECT,
|
|
1813
|
+
},
|
|
1892
1814
|
},
|
|
1893
|
-
}
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1815
|
+
});
|
|
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
|
+
);
|
|
1897
1823
|
});
|
|
1898
|
-
});
|
|
1899
1824
|
|
|
1900
|
-
|
|
1901
|
-
it('throws an error when the given object has an invalid model', async function () {
|
|
1825
|
+
it('throws an error if true given', async function () {
|
|
1902
1826
|
const S = new Schema();
|
|
1903
1827
|
S.defineModel({
|
|
1904
|
-
name: '
|
|
1828
|
+
name: 'model',
|
|
1829
|
+
datasource: 'datasource',
|
|
1905
1830
|
properties: {
|
|
1906
|
-
foo:
|
|
1831
|
+
foo: {
|
|
1832
|
+
type: DataType.OBJECT,
|
|
1833
|
+
},
|
|
1907
1834
|
},
|
|
1908
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.',
|
|
1842
|
+
);
|
|
1843
|
+
});
|
|
1844
|
+
|
|
1845
|
+
it('throws an error if false given', async function () {
|
|
1846
|
+
const S = new Schema();
|
|
1909
1847
|
S.defineModel({
|
|
1910
|
-
name: '
|
|
1848
|
+
name: 'model',
|
|
1911
1849
|
datasource: 'datasource',
|
|
1912
1850
|
properties: {
|
|
1913
|
-
|
|
1851
|
+
foo: {
|
|
1914
1852
|
type: DataType.OBJECT,
|
|
1915
|
-
model: 'modelA',
|
|
1916
1853
|
},
|
|
1917
1854
|
},
|
|
1918
1855
|
});
|
|
1919
|
-
const promise = S.getService(ModelDataValidator).validate(
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
bar: {foo: 10},
|
|
1923
|
-
},
|
|
1924
|
-
);
|
|
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
|
});
|
|
@@ -1958,8 +1960,10 @@ describe('ModelDataValidator', function () {
|
|
|
1958
1960
|
describe('the option "validate" with the string value', function () {
|
|
1959
1961
|
it('do not validate null and undefined values', async function () {
|
|
1960
1962
|
const S = new Schema();
|
|
1961
|
-
S.getService(PropertyValidatorRegistry)
|
|
1962
|
-
|
|
1963
|
+
S.getService(PropertyValidatorRegistry).addValidator(
|
|
1964
|
+
'validator',
|
|
1965
|
+
() => false,
|
|
1966
|
+
);
|
|
1963
1967
|
S.defineModel({
|
|
1964
1968
|
name: 'model',
|
|
1965
1969
|
properties: {
|
|
@@ -1986,10 +1990,12 @@ describe('ModelDataValidator', function () {
|
|
|
1986
1990
|
it('throws an error from the validator', async function () {
|
|
1987
1991
|
const validator = function () {
|
|
1988
1992
|
throw Error('My error');
|
|
1989
|
-
}
|
|
1993
|
+
};
|
|
1990
1994
|
const S = new Schema();
|
|
1991
|
-
S.getService(PropertyValidatorRegistry)
|
|
1992
|
-
|
|
1995
|
+
S.getService(PropertyValidatorRegistry).addValidator(
|
|
1996
|
+
'validator',
|
|
1997
|
+
validator,
|
|
1998
|
+
);
|
|
1993
1999
|
S.defineModel({
|
|
1994
2000
|
name: 'model',
|
|
1995
2001
|
properties: {
|
|
@@ -2007,8 +2013,10 @@ describe('ModelDataValidator', function () {
|
|
|
2007
2013
|
|
|
2008
2014
|
it('allows the given value if the validator returns true', async function () {
|
|
2009
2015
|
const S = new Schema();
|
|
2010
|
-
S.getService(PropertyValidatorRegistry)
|
|
2011
|
-
|
|
2016
|
+
S.getService(PropertyValidatorRegistry).addValidator(
|
|
2017
|
+
'validator',
|
|
2018
|
+
() => true,
|
|
2019
|
+
);
|
|
2012
2020
|
S.defineModel({
|
|
2013
2021
|
name: 'model',
|
|
2014
2022
|
properties: {
|
|
@@ -2025,8 +2033,10 @@ describe('ModelDataValidator', function () {
|
|
|
2025
2033
|
|
|
2026
2034
|
it('allows the given value if the validator returns a promise of true', async function () {
|
|
2027
2035
|
const S = new Schema();
|
|
2028
|
-
S.getService(PropertyValidatorRegistry)
|
|
2029
|
-
|
|
2036
|
+
S.getService(PropertyValidatorRegistry).addValidator(
|
|
2037
|
+
'validator',
|
|
2038
|
+
() => Promise.resolve(true),
|
|
2039
|
+
);
|
|
2030
2040
|
S.defineModel({
|
|
2031
2041
|
name: 'model',
|
|
2032
2042
|
properties: {
|
|
@@ -2042,10 +2052,12 @@ describe('ModelDataValidator', function () {
|
|
|
2042
2052
|
});
|
|
2043
2053
|
|
|
2044
2054
|
it('throws an error for non-true result from the validator', async function () {
|
|
2045
|
-
const testFn = async
|
|
2055
|
+
const testFn = async v => {
|
|
2046
2056
|
const S = new Schema();
|
|
2047
|
-
S.getService(PropertyValidatorRegistry)
|
|
2048
|
-
|
|
2057
|
+
S.getService(PropertyValidatorRegistry).addValidator(
|
|
2058
|
+
'validator',
|
|
2059
|
+
() => v,
|
|
2060
|
+
);
|
|
2049
2061
|
S.defineModel({
|
|
2050
2062
|
name: 'model',
|
|
2051
2063
|
properties: {
|
|
@@ -2055,13 +2067,14 @@ describe('ModelDataValidator', function () {
|
|
|
2055
2067
|
},
|
|
2056
2068
|
},
|
|
2057
2069
|
});
|
|
2058
|
-
const promise = S.getService(ModelDataValidator)
|
|
2059
|
-
|
|
2070
|
+
const promise = S.getService(ModelDataValidator).validate('model', {
|
|
2071
|
+
foo: 'test',
|
|
2072
|
+
});
|
|
2060
2073
|
return expect(promise).to.be.rejectedWith(
|
|
2061
2074
|
'The property "foo" of the model "model" has an invalid value "test" ' +
|
|
2062
|
-
|
|
2075
|
+
'that caught by the validator "validator".',
|
|
2063
2076
|
);
|
|
2064
|
-
}
|
|
2077
|
+
};
|
|
2065
2078
|
await testFn('str');
|
|
2066
2079
|
await testFn('');
|
|
2067
2080
|
await testFn(10);
|
|
@@ -2092,9 +2105,11 @@ describe('ModelDataValidator', function () {
|
|
|
2092
2105
|
});
|
|
2093
2106
|
validated = true;
|
|
2094
2107
|
return true;
|
|
2095
|
-
}
|
|
2096
|
-
S.getService(PropertyValidatorRegistry)
|
|
2097
|
-
|
|
2108
|
+
};
|
|
2109
|
+
S.getService(PropertyValidatorRegistry).addValidator(
|
|
2110
|
+
'validator',
|
|
2111
|
+
validator,
|
|
2112
|
+
);
|
|
2098
2113
|
S.defineModel({
|
|
2099
2114
|
name: 'model',
|
|
2100
2115
|
properties: {
|
|
@@ -2115,10 +2130,12 @@ describe('ModelDataValidator', function () {
|
|
|
2115
2130
|
const validator = function () {
|
|
2116
2131
|
invoked++;
|
|
2117
2132
|
return true;
|
|
2118
|
-
}
|
|
2133
|
+
};
|
|
2119
2134
|
const S = new Schema();
|
|
2120
|
-
S.getService(PropertyValidatorRegistry)
|
|
2121
|
-
|
|
2135
|
+
S.getService(PropertyValidatorRegistry).addValidator(
|
|
2136
|
+
'validator',
|
|
2137
|
+
validator,
|
|
2138
|
+
);
|
|
2122
2139
|
S.defineModel({
|
|
2123
2140
|
name: 'model',
|
|
2124
2141
|
properties: {
|
|
@@ -2140,10 +2157,12 @@ describe('ModelDataValidator', function () {
|
|
|
2140
2157
|
return new Promise((resolve, reject) => {
|
|
2141
2158
|
setTimeout(() => reject(error), 5);
|
|
2142
2159
|
});
|
|
2143
|
-
}
|
|
2160
|
+
};
|
|
2144
2161
|
const S = new Schema();
|
|
2145
|
-
S.getService(PropertyValidatorRegistry)
|
|
2146
|
-
|
|
2162
|
+
S.getService(PropertyValidatorRegistry).addValidator(
|
|
2163
|
+
'validator',
|
|
2164
|
+
validator,
|
|
2165
|
+
);
|
|
2147
2166
|
S.defineModel({
|
|
2148
2167
|
name: 'model',
|
|
2149
2168
|
properties: {
|
|
@@ -2179,8 +2198,10 @@ describe('ModelDataValidator', function () {
|
|
|
2179
2198
|
|
|
2180
2199
|
it('do not validate null and undefined values', async function () {
|
|
2181
2200
|
const S = new Schema();
|
|
2182
|
-
S.getService(PropertyValidatorRegistry)
|
|
2183
|
-
|
|
2201
|
+
S.getService(PropertyValidatorRegistry).addValidator(
|
|
2202
|
+
'validator',
|
|
2203
|
+
() => false,
|
|
2204
|
+
);
|
|
2184
2205
|
S.defineModel({
|
|
2185
2206
|
name: 'model',
|
|
2186
2207
|
properties: {
|
|
@@ -2207,10 +2228,12 @@ describe('ModelDataValidator', function () {
|
|
|
2207
2228
|
it('throws an error from the validator', async function () {
|
|
2208
2229
|
const validator = function () {
|
|
2209
2230
|
throw Error('My error');
|
|
2210
|
-
}
|
|
2231
|
+
};
|
|
2211
2232
|
const S = new Schema();
|
|
2212
|
-
S.getService(PropertyValidatorRegistry)
|
|
2213
|
-
|
|
2233
|
+
S.getService(PropertyValidatorRegistry).addValidator(
|
|
2234
|
+
'validator',
|
|
2235
|
+
validator,
|
|
2236
|
+
);
|
|
2214
2237
|
S.defineModel({
|
|
2215
2238
|
name: 'model',
|
|
2216
2239
|
properties: {
|
|
@@ -2284,9 +2307,9 @@ describe('ModelDataValidator', function () {
|
|
|
2284
2307
|
});
|
|
2285
2308
|
return expect(promise).to.be.rejectedWith(
|
|
2286
2309
|
'The property "foo" of the model "model" has an invalid value "test" ' +
|
|
2287
|
-
|
|
2310
|
+
'that caught by the validator "validator2".',
|
|
2288
2311
|
);
|
|
2289
|
-
}
|
|
2312
|
+
};
|
|
2290
2313
|
await testFn('str');
|
|
2291
2314
|
await testFn('');
|
|
2292
2315
|
await testFn(10);
|
|
@@ -2317,9 +2340,11 @@ describe('ModelDataValidator', function () {
|
|
|
2317
2340
|
});
|
|
2318
2341
|
validated = true;
|
|
2319
2342
|
return true;
|
|
2320
|
-
}
|
|
2321
|
-
S.getService(PropertyValidatorRegistry)
|
|
2322
|
-
|
|
2343
|
+
};
|
|
2344
|
+
S.getService(PropertyValidatorRegistry).addValidator(
|
|
2345
|
+
'validator',
|
|
2346
|
+
validator,
|
|
2347
|
+
);
|
|
2323
2348
|
S.defineModel({
|
|
2324
2349
|
name: 'model',
|
|
2325
2350
|
properties: {
|
|
@@ -2340,11 +2365,11 @@ describe('ModelDataValidator', function () {
|
|
|
2340
2365
|
const validator1 = function () {
|
|
2341
2366
|
invocation.push('validator1');
|
|
2342
2367
|
return true;
|
|
2343
|
-
}
|
|
2368
|
+
};
|
|
2344
2369
|
const validator2 = function () {
|
|
2345
2370
|
invocation.push('validator2');
|
|
2346
2371
|
return true;
|
|
2347
|
-
}
|
|
2372
|
+
};
|
|
2348
2373
|
const S = new Schema();
|
|
2349
2374
|
S.getService(PropertyValidatorRegistry)
|
|
2350
2375
|
.addValidator('validator1', validator1)
|
|
@@ -2367,12 +2392,14 @@ describe('ModelDataValidator', function () {
|
|
|
2367
2392
|
it('waits rejection from one of async validators', async function () {
|
|
2368
2393
|
const error1 = new Error('Occurs after 15 ms');
|
|
2369
2394
|
const error2 = new Error('Occurs after 5 ms');
|
|
2370
|
-
const validator1 = () =>
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2395
|
+
const validator1 = () =>
|
|
2396
|
+
new Promise((res, rej) => {
|
|
2397
|
+
setTimeout(() => rej(error1), 15);
|
|
2398
|
+
});
|
|
2399
|
+
const validator2 = () =>
|
|
2400
|
+
new Promise((res, rej) => {
|
|
2401
|
+
setTimeout(() => rej(error2), 5);
|
|
2402
|
+
});
|
|
2376
2403
|
const S = new Schema();
|
|
2377
2404
|
S.getService(PropertyValidatorRegistry)
|
|
2378
2405
|
.addValidator('validator1', validator1)
|
|
@@ -2382,10 +2409,7 @@ describe('ModelDataValidator', function () {
|
|
|
2382
2409
|
properties: {
|
|
2383
2410
|
foo: {
|
|
2384
2411
|
type: DataType.ANY,
|
|
2385
|
-
validate: [
|
|
2386
|
-
'validator1',
|
|
2387
|
-
'validator2',
|
|
2388
|
-
],
|
|
2412
|
+
validate: ['validator1', 'validator2'],
|
|
2389
2413
|
},
|
|
2390
2414
|
},
|
|
2391
2415
|
});
|
|
@@ -2415,8 +2439,10 @@ describe('ModelDataValidator', function () {
|
|
|
2415
2439
|
|
|
2416
2440
|
it('do not validate null and undefined values', async function () {
|
|
2417
2441
|
const S = new Schema();
|
|
2418
|
-
S.getService(PropertyValidatorRegistry)
|
|
2419
|
-
|
|
2442
|
+
S.getService(PropertyValidatorRegistry).addValidator(
|
|
2443
|
+
'validator',
|
|
2444
|
+
() => false,
|
|
2445
|
+
);
|
|
2420
2446
|
S.defineModel({
|
|
2421
2447
|
name: 'model',
|
|
2422
2448
|
properties: {
|
|
@@ -2449,10 +2475,12 @@ describe('ModelDataValidator', function () {
|
|
|
2449
2475
|
it('throws an error from the validator', async function () {
|
|
2450
2476
|
const validator = function () {
|
|
2451
2477
|
throw Error('My error');
|
|
2452
|
-
}
|
|
2478
|
+
};
|
|
2453
2479
|
const S = new Schema();
|
|
2454
|
-
S.getService(PropertyValidatorRegistry)
|
|
2455
|
-
|
|
2480
|
+
S.getService(PropertyValidatorRegistry).addValidator(
|
|
2481
|
+
'validator',
|
|
2482
|
+
validator,
|
|
2483
|
+
);
|
|
2456
2484
|
S.defineModel({
|
|
2457
2485
|
name: 'model',
|
|
2458
2486
|
properties: {
|
|
@@ -2537,9 +2565,9 @@ describe('ModelDataValidator', function () {
|
|
|
2537
2565
|
});
|
|
2538
2566
|
return expect(promise).to.be.rejectedWith(
|
|
2539
2567
|
'The property "foo" of the model "model" has an invalid value "test" ' +
|
|
2540
|
-
|
|
2568
|
+
'that caught by the validator "validator2".',
|
|
2541
2569
|
);
|
|
2542
|
-
}
|
|
2570
|
+
};
|
|
2543
2571
|
await testFn('str');
|
|
2544
2572
|
await testFn('');
|
|
2545
2573
|
await testFn(10);
|
|
@@ -2578,9 +2606,11 @@ describe('ModelDataValidator', function () {
|
|
|
2578
2606
|
});
|
|
2579
2607
|
validated = true;
|
|
2580
2608
|
return true;
|
|
2581
|
-
}
|
|
2582
|
-
S.getService(PropertyValidatorRegistry)
|
|
2583
|
-
|
|
2609
|
+
};
|
|
2610
|
+
S.getService(PropertyValidatorRegistry).addValidator(
|
|
2611
|
+
'validator',
|
|
2612
|
+
validator,
|
|
2613
|
+
);
|
|
2584
2614
|
S.defineModel({
|
|
2585
2615
|
name: 'model',
|
|
2586
2616
|
properties: {
|
|
@@ -2606,11 +2636,11 @@ describe('ModelDataValidator', function () {
|
|
|
2606
2636
|
const validator1 = function () {
|
|
2607
2637
|
invocation.push('validator1');
|
|
2608
2638
|
return true;
|
|
2609
|
-
}
|
|
2639
|
+
};
|
|
2610
2640
|
const validator2 = function () {
|
|
2611
2641
|
invocation.push('validator2');
|
|
2612
2642
|
return true;
|
|
2613
|
-
}
|
|
2643
|
+
};
|
|
2614
2644
|
const S = new Schema();
|
|
2615
2645
|
S.getService(PropertyValidatorRegistry)
|
|
2616
2646
|
.addValidator('validator1', validator1)
|
|
@@ -2638,10 +2668,12 @@ describe('ModelDataValidator', function () {
|
|
|
2638
2668
|
const validator = function () {
|
|
2639
2669
|
validated = true;
|
|
2640
2670
|
return true;
|
|
2641
|
-
}
|
|
2671
|
+
};
|
|
2642
2672
|
const S = new Schema();
|
|
2643
|
-
S.getService(PropertyValidatorRegistry)
|
|
2644
|
-
|
|
2673
|
+
S.getService(PropertyValidatorRegistry).addValidator(
|
|
2674
|
+
'validator',
|
|
2675
|
+
validator,
|
|
2676
|
+
);
|
|
2645
2677
|
S.defineModel({
|
|
2646
2678
|
name: 'model',
|
|
2647
2679
|
properties: {
|
|
@@ -2662,12 +2694,14 @@ describe('ModelDataValidator', function () {
|
|
|
2662
2694
|
it('waits rejection from one of async validators', async function () {
|
|
2663
2695
|
const error1 = new Error('Occurs after 15 ms');
|
|
2664
2696
|
const error2 = new Error('Occurs after 5 ms');
|
|
2665
|
-
const validator1 = () =>
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2697
|
+
const validator1 = () =>
|
|
2698
|
+
new Promise((res, rej) => {
|
|
2699
|
+
setTimeout(() => rej(error1), 15);
|
|
2700
|
+
});
|
|
2701
|
+
const validator2 = () =>
|
|
2702
|
+
new Promise((res, rej) => {
|
|
2703
|
+
setTimeout(() => rej(error2), 5);
|
|
2704
|
+
});
|
|
2671
2705
|
const S = new Schema();
|
|
2672
2706
|
S.getService(PropertyValidatorRegistry)
|
|
2673
2707
|
.addValidator('validator1', validator1)
|
|
@@ -2680,7 +2714,7 @@ describe('ModelDataValidator', function () {
|
|
|
2680
2714
|
validate: {
|
|
2681
2715
|
validator1: true,
|
|
2682
2716
|
validator2: true,
|
|
2683
|
-
}
|
|
2717
|
+
},
|
|
2684
2718
|
},
|
|
2685
2719
|
},
|
|
2686
2720
|
});
|