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