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