@e22m4u/js-repository 0.1.5 → 0.1.7

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