@e22m4u/js-repository 0.2.6 → 0.3.0
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 +79 -80
- package/dist/cjs/index.cjs +2023 -2093
- package/eslint.config.js +1 -1
- package/package.json +15 -12
- 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.js +3 -3
- package/src/definition/model/model-data-transformer.spec.js +93 -93
- package/src/definition/model/model-data-validator.js +2 -2
- package/src/definition/model/model-data-validator.spec.js +517 -531
- package/src/definition/model/model-definition-utils.js +3 -3
- package/src/definition/model/model-definition-utils.spec.js +345 -343
- package/src/definition/model/properties/index.d.ts +0 -1
- package/src/definition/model/properties/index.js +0 -1
- package/src/definition/model/properties/property-transformer/property-transformer-registry.spec.js +36 -36
- package/src/definition/model/properties/property-uniqueness-validator.js +3 -3
- package/src/definition/model/properties/property-uniqueness-validator.spec.js +417 -384
- 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/definition/model/properties/empty-values-definer.d.ts +0 -23
- package/src/definition/model/properties/empty-values-definer.js +0 -66
- package/src/definition/model/properties/empty-values-definer.spec.js +0 -96
- package/src/schema.spec.ts +0 -86
|
@@ -1,16 +1,16 @@
|
|
|
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 '../definition/index.js';
|
|
5
4
|
import {RelationType} from '../definition/index.js';
|
|
6
5
|
import {HasOneResolver} from './has-one-resolver.js';
|
|
6
|
+
import {DatabaseSchema} from '../database-schema.js';
|
|
7
7
|
import {DEFAULT_PRIMARY_KEY_PROPERTY_NAME as DEF_PK} from '../definition/index.js';
|
|
8
8
|
|
|
9
9
|
describe('HasOneResolver', function () {
|
|
10
10
|
describe('includeTo', function () {
|
|
11
11
|
it('requires the "entities" parameter to be an array', async function () {
|
|
12
|
-
const
|
|
13
|
-
const R =
|
|
12
|
+
const dbs = new DatabaseSchema();
|
|
13
|
+
const R = dbs.getService(HasOneResolver);
|
|
14
14
|
const error = v =>
|
|
15
15
|
format(
|
|
16
16
|
'The parameter "entities" of HasOneResolver.includeTo requires ' +
|
|
@@ -36,9 +36,9 @@ describe('HasOneResolver', function () {
|
|
|
36
36
|
});
|
|
37
37
|
|
|
38
38
|
it('requires elements of the "entities" parameter to be an Object', async function () {
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
const R =
|
|
39
|
+
const dbs = new DatabaseSchema();
|
|
40
|
+
dbs.defineModel({name: 'source'});
|
|
41
|
+
const R = dbs.getService(HasOneResolver);
|
|
42
42
|
const error = v =>
|
|
43
43
|
format(
|
|
44
44
|
'The parameter "entities" of HasOneResolver.includeTo requires ' +
|
|
@@ -58,8 +58,8 @@ describe('HasOneResolver', function () {
|
|
|
58
58
|
});
|
|
59
59
|
|
|
60
60
|
it('requires the "sourceName" parameter to be a non-empty string', async function () {
|
|
61
|
-
const
|
|
62
|
-
const R =
|
|
61
|
+
const dbs = new DatabaseSchema();
|
|
62
|
+
const R = dbs.getService(HasOneResolver);
|
|
63
63
|
const error = v =>
|
|
64
64
|
format(
|
|
65
65
|
'The parameter "sourceName" of HasOneResolver.includeTo requires ' +
|
|
@@ -79,8 +79,8 @@ describe('HasOneResolver', function () {
|
|
|
79
79
|
});
|
|
80
80
|
|
|
81
81
|
it('requires the "targetName" parameter to be a non-empty string', async function () {
|
|
82
|
-
const
|
|
83
|
-
const R =
|
|
82
|
+
const dbs = new DatabaseSchema();
|
|
83
|
+
const R = dbs.getService(HasOneResolver);
|
|
84
84
|
const error = v =>
|
|
85
85
|
format(
|
|
86
86
|
'The parameter "targetName" of HasOneResolver.includeTo requires ' +
|
|
@@ -100,8 +100,8 @@ describe('HasOneResolver', function () {
|
|
|
100
100
|
});
|
|
101
101
|
|
|
102
102
|
it('requires the "relationName" parameter to be a non-empty string', async function () {
|
|
103
|
-
const
|
|
104
|
-
const R =
|
|
103
|
+
const dbs = new DatabaseSchema();
|
|
104
|
+
const R = dbs.getService(HasOneResolver);
|
|
105
105
|
const error = v =>
|
|
106
106
|
format(
|
|
107
107
|
'The parameter "relationName" of HasOneResolver.includeTo requires ' +
|
|
@@ -121,8 +121,8 @@ describe('HasOneResolver', function () {
|
|
|
121
121
|
});
|
|
122
122
|
|
|
123
123
|
it('requires the "foreignKey" parameter to be a non-empty string', async function () {
|
|
124
|
-
const
|
|
125
|
-
const R =
|
|
124
|
+
const dbs = new DatabaseSchema();
|
|
125
|
+
const R = dbs.getService(HasOneResolver);
|
|
126
126
|
const error = v =>
|
|
127
127
|
format(
|
|
128
128
|
'The parameter "foreignKey" of HasOneResolver.includeTo requires ' +
|
|
@@ -142,8 +142,8 @@ describe('HasOneResolver', function () {
|
|
|
142
142
|
});
|
|
143
143
|
|
|
144
144
|
it('requires the provided parameter "scope" to be an object', async function () {
|
|
145
|
-
const
|
|
146
|
-
const R =
|
|
145
|
+
const dbs = new DatabaseSchema();
|
|
146
|
+
const R = dbs.getService(HasOneResolver);
|
|
147
147
|
const error = v =>
|
|
148
148
|
format(
|
|
149
149
|
'The provided parameter "scope" of HasOneResolver.includeTo ' +
|
|
@@ -166,9 +166,9 @@ describe('HasOneResolver', function () {
|
|
|
166
166
|
});
|
|
167
167
|
|
|
168
168
|
it('throws an error if a target model is not found', async function () {
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
const R =
|
|
169
|
+
const dbs = new DatabaseSchema();
|
|
170
|
+
dbs.defineModel({name: 'source'});
|
|
171
|
+
const R = dbs.getService(HasOneResolver);
|
|
172
172
|
const promise = R.includeTo(
|
|
173
173
|
[],
|
|
174
174
|
'source',
|
|
@@ -182,10 +182,10 @@ describe('HasOneResolver', function () {
|
|
|
182
182
|
});
|
|
183
183
|
|
|
184
184
|
it('throws an error if a target model does not have datasource', async function () {
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
const R =
|
|
185
|
+
const dbs = new DatabaseSchema();
|
|
186
|
+
dbs.defineModel({name: 'source'});
|
|
187
|
+
dbs.defineModel({name: 'target'});
|
|
188
|
+
const R = dbs.getService(HasOneResolver);
|
|
189
189
|
const promise = R.includeTo(
|
|
190
190
|
[],
|
|
191
191
|
'source',
|
|
@@ -199,13 +199,13 @@ describe('HasOneResolver', function () {
|
|
|
199
199
|
});
|
|
200
200
|
|
|
201
201
|
it('does not throw an error if a relation target is not exist', async function () {
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
const sourceRel =
|
|
202
|
+
const dbs = new DatabaseSchema();
|
|
203
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
204
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
205
|
+
dbs.defineModel({name: 'target', datasource: 'datasource'});
|
|
206
|
+
const sourceRel = dbs.getRepository('source');
|
|
207
207
|
const source = await sourceRel.create({});
|
|
208
|
-
const R =
|
|
208
|
+
const R = dbs.getService(HasOneResolver);
|
|
209
209
|
await R.includeTo([source], 'source', 'target', 'child', 'parentId');
|
|
210
210
|
expect(source).to.be.eql({
|
|
211
211
|
[DEF_PK]: source[DEF_PK],
|
|
@@ -213,12 +213,12 @@ describe('HasOneResolver', function () {
|
|
|
213
213
|
});
|
|
214
214
|
|
|
215
215
|
it('includes if a primary key is not defined in the source model', async function () {
|
|
216
|
-
const
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
const sourceRep =
|
|
221
|
-
const targetRep =
|
|
216
|
+
const dbs = new DatabaseSchema();
|
|
217
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
218
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
219
|
+
dbs.defineModel({name: 'target', datasource: 'datasource'});
|
|
220
|
+
const sourceRep = dbs.getRepository('source');
|
|
221
|
+
const targetRep = dbs.getRepository('target');
|
|
222
222
|
const source = await sourceRep.create({});
|
|
223
223
|
expect(source).to.be.eql({[DEF_PK]: source[DEF_PK]});
|
|
224
224
|
const target = await targetRep.create({parentId: source[DEF_PK]});
|
|
@@ -226,7 +226,7 @@ describe('HasOneResolver', function () {
|
|
|
226
226
|
[DEF_PK]: target[DEF_PK],
|
|
227
227
|
parentId: source[DEF_PK],
|
|
228
228
|
});
|
|
229
|
-
const R =
|
|
229
|
+
const R = dbs.getService(HasOneResolver);
|
|
230
230
|
await R.includeTo([source], 'source', 'target', 'child', 'parentId');
|
|
231
231
|
expect(source).to.be.eql({
|
|
232
232
|
[DEF_PK]: source[DEF_PK],
|
|
@@ -238,9 +238,9 @@ describe('HasOneResolver', function () {
|
|
|
238
238
|
});
|
|
239
239
|
|
|
240
240
|
it('includes if the source model has a custom primary key', async function () {
|
|
241
|
-
const
|
|
242
|
-
|
|
243
|
-
|
|
241
|
+
const dbs = new DatabaseSchema();
|
|
242
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
243
|
+
dbs.defineModel({
|
|
244
244
|
name: 'source',
|
|
245
245
|
datasource: 'datasource',
|
|
246
246
|
properties: {
|
|
@@ -250,9 +250,9 @@ describe('HasOneResolver', function () {
|
|
|
250
250
|
},
|
|
251
251
|
},
|
|
252
252
|
});
|
|
253
|
-
|
|
254
|
-
const sourceRep =
|
|
255
|
-
const targetRep =
|
|
253
|
+
dbs.defineModel({name: 'target', datasource: 'datasource'});
|
|
254
|
+
const sourceRep = dbs.getRepository('source');
|
|
255
|
+
const targetRep = dbs.getRepository('target');
|
|
256
256
|
const source = await sourceRep.create({});
|
|
257
257
|
expect(source).to.be.eql({myId: source.myId});
|
|
258
258
|
const target = await targetRep.create({parentId: source.myId});
|
|
@@ -260,7 +260,7 @@ describe('HasOneResolver', function () {
|
|
|
260
260
|
[DEF_PK]: target[DEF_PK],
|
|
261
261
|
parentId: source.myId,
|
|
262
262
|
});
|
|
263
|
-
const R =
|
|
263
|
+
const R = dbs.getService(HasOneResolver);
|
|
264
264
|
await R.includeTo([source], 'source', 'target', 'child', 'parentId');
|
|
265
265
|
expect(source).to.be.eql({
|
|
266
266
|
myId: source.myId,
|
|
@@ -272,10 +272,10 @@ describe('HasOneResolver', function () {
|
|
|
272
272
|
});
|
|
273
273
|
|
|
274
274
|
it('includes if the target model has a custom primary key', async function () {
|
|
275
|
-
const
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
275
|
+
const dbs = new DatabaseSchema();
|
|
276
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
277
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
278
|
+
dbs.defineModel({
|
|
279
279
|
name: 'target',
|
|
280
280
|
datasource: 'datasource',
|
|
281
281
|
properties: {
|
|
@@ -285,8 +285,8 @@ describe('HasOneResolver', function () {
|
|
|
285
285
|
},
|
|
286
286
|
},
|
|
287
287
|
});
|
|
288
|
-
const sourceRep =
|
|
289
|
-
const targetRep =
|
|
288
|
+
const sourceRep = dbs.getRepository('source');
|
|
289
|
+
const targetRep = dbs.getRepository('target');
|
|
290
290
|
const source = await sourceRep.create({});
|
|
291
291
|
expect(source).to.be.eql({[DEF_PK]: source[DEF_PK]});
|
|
292
292
|
const target = await targetRep.create({parentId: source[DEF_PK]});
|
|
@@ -294,7 +294,7 @@ describe('HasOneResolver', function () {
|
|
|
294
294
|
myId: target.myId,
|
|
295
295
|
parentId: source[DEF_PK],
|
|
296
296
|
});
|
|
297
|
-
const R =
|
|
297
|
+
const R = dbs.getService(HasOneResolver);
|
|
298
298
|
await R.includeTo([source], 'source', 'target', 'child', 'parentId');
|
|
299
299
|
expect(source).to.be.eql({
|
|
300
300
|
[DEF_PK]: source[DEF_PK],
|
|
@@ -306,12 +306,12 @@ describe('HasOneResolver', function () {
|
|
|
306
306
|
});
|
|
307
307
|
|
|
308
308
|
it('uses a where clause of the given scope to filter the relation target', async function () {
|
|
309
|
-
const
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
const sourceRep =
|
|
314
|
-
const targetRep =
|
|
309
|
+
const dbs = new DatabaseSchema();
|
|
310
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
311
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
312
|
+
dbs.defineModel({name: 'target', datasource: 'datasource'});
|
|
313
|
+
const sourceRep = dbs.getRepository('source');
|
|
314
|
+
const targetRep = dbs.getRepository('target');
|
|
315
315
|
const source = await sourceRep.create({});
|
|
316
316
|
expect(source).to.be.eql({[DEF_PK]: source[DEF_PK]});
|
|
317
317
|
const target1 = await targetRep.create({
|
|
@@ -332,7 +332,7 @@ describe('HasOneResolver', function () {
|
|
|
332
332
|
featured: true,
|
|
333
333
|
parentId: source[DEF_PK],
|
|
334
334
|
});
|
|
335
|
-
const R =
|
|
335
|
+
const R = dbs.getService(HasOneResolver);
|
|
336
336
|
await R.includeTo([source], 'source', 'target', 'child', 'parentId', {
|
|
337
337
|
where: {featured: false},
|
|
338
338
|
});
|
|
@@ -358,12 +358,12 @@ describe('HasOneResolver', function () {
|
|
|
358
358
|
});
|
|
359
359
|
|
|
360
360
|
it('uses a fields clause of the given scope to filter the relation target', async function () {
|
|
361
|
-
const
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
const sourceRep =
|
|
366
|
-
const targetRep =
|
|
361
|
+
const dbs = new DatabaseSchema();
|
|
362
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
363
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
364
|
+
dbs.defineModel({name: 'target', datasource: 'datasource'});
|
|
365
|
+
const sourceRep = dbs.getRepository('source');
|
|
366
|
+
const targetRep = dbs.getRepository('target');
|
|
367
367
|
const source = await sourceRep.create({});
|
|
368
368
|
expect(source).to.be.eql({
|
|
369
369
|
[DEF_PK]: source[DEF_PK],
|
|
@@ -379,7 +379,7 @@ describe('HasOneResolver', function () {
|
|
|
379
379
|
bar: target.bar,
|
|
380
380
|
parentId: source[DEF_PK],
|
|
381
381
|
});
|
|
382
|
-
const R =
|
|
382
|
+
const R = dbs.getService(HasOneResolver);
|
|
383
383
|
await R.includeTo([source], 'source', 'target', 'child', 'parentId', {
|
|
384
384
|
fields: [DEF_PK, 'bar'],
|
|
385
385
|
});
|
|
@@ -393,12 +393,12 @@ describe('HasOneResolver', function () {
|
|
|
393
393
|
});
|
|
394
394
|
|
|
395
395
|
it('uses an include clause of the given scope to resolve target relations', async function () {
|
|
396
|
-
const
|
|
397
|
-
|
|
396
|
+
const dbs = new DatabaseSchema();
|
|
397
|
+
dbs.defineDatasource({
|
|
398
398
|
name: 'datasource',
|
|
399
399
|
adapter: 'memory',
|
|
400
400
|
});
|
|
401
|
-
|
|
401
|
+
dbs.defineModel({
|
|
402
402
|
name: 'modelA',
|
|
403
403
|
datasource: 'datasource',
|
|
404
404
|
properties: {
|
|
@@ -419,7 +419,7 @@ describe('HasOneResolver', function () {
|
|
|
419
419
|
},
|
|
420
420
|
},
|
|
421
421
|
});
|
|
422
|
-
|
|
422
|
+
dbs.defineModel({
|
|
423
423
|
name: 'modelB',
|
|
424
424
|
datasource: 'datasource',
|
|
425
425
|
properties: {
|
|
@@ -440,7 +440,7 @@ describe('HasOneResolver', function () {
|
|
|
440
440
|
},
|
|
441
441
|
},
|
|
442
442
|
});
|
|
443
|
-
|
|
443
|
+
dbs.defineModel({
|
|
444
444
|
name: 'modelC',
|
|
445
445
|
datasource: 'datasource',
|
|
446
446
|
properties: {
|
|
@@ -454,9 +454,9 @@ describe('HasOneResolver', function () {
|
|
|
454
454
|
},
|
|
455
455
|
},
|
|
456
456
|
});
|
|
457
|
-
const aRep =
|
|
458
|
-
const bRep =
|
|
459
|
-
const cRep =
|
|
457
|
+
const aRep = dbs.getRepository('modelA');
|
|
458
|
+
const bRep = dbs.getRepository('modelB');
|
|
459
|
+
const cRep = dbs.getRepository('modelC');
|
|
460
460
|
const a = await aRep.create({});
|
|
461
461
|
const b = await bRep.create({parentId: a.id});
|
|
462
462
|
const c = await cRep.create({parentId: b.id});
|
|
@@ -474,7 +474,7 @@ describe('HasOneResolver', function () {
|
|
|
474
474
|
source: 'modelC',
|
|
475
475
|
parentId: b.id,
|
|
476
476
|
});
|
|
477
|
-
const R =
|
|
477
|
+
const R = dbs.getService(HasOneResolver);
|
|
478
478
|
await R.includeTo([a], 'modelA', 'modelB', 'child', 'parentId', {
|
|
479
479
|
include: 'child',
|
|
480
480
|
});
|
|
@@ -495,12 +495,12 @@ describe('HasOneResolver', function () {
|
|
|
495
495
|
});
|
|
496
496
|
|
|
497
497
|
it('does not break the "and" operator of the given "where" clause', async function () {
|
|
498
|
-
const
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
const sourceRep =
|
|
503
|
-
const targetRep =
|
|
498
|
+
const dbs = new DatabaseSchema();
|
|
499
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
500
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
501
|
+
dbs.defineModel({name: 'target', datasource: 'datasource'});
|
|
502
|
+
const sourceRep = dbs.getRepository('source');
|
|
503
|
+
const targetRep = dbs.getRepository('target');
|
|
504
504
|
const source = await sourceRep.create({});
|
|
505
505
|
expect(source).to.be.eql({
|
|
506
506
|
[DEF_PK]: source[DEF_PK],
|
|
@@ -523,7 +523,7 @@ describe('HasOneResolver', function () {
|
|
|
523
523
|
featured: true,
|
|
524
524
|
parentId: source[DEF_PK],
|
|
525
525
|
});
|
|
526
|
-
const R =
|
|
526
|
+
const R = dbs.getService(HasOneResolver);
|
|
527
527
|
await R.includeTo([source], 'source', 'target', 'child', 'parentId', {
|
|
528
528
|
where: {and: [{featured: false}]},
|
|
529
529
|
});
|
|
@@ -552,8 +552,8 @@ describe('HasOneResolver', function () {
|
|
|
552
552
|
|
|
553
553
|
describe('includePolymorphicTo', function () {
|
|
554
554
|
it('requires the "entities" parameter to be an array', async function () {
|
|
555
|
-
const
|
|
556
|
-
const R =
|
|
555
|
+
const dbs = new DatabaseSchema();
|
|
556
|
+
const R = dbs.getService(HasOneResolver);
|
|
557
557
|
const error = v =>
|
|
558
558
|
format(
|
|
559
559
|
'The parameter "entities" of HasOneResolver.includePolymorphicTo requires ' +
|
|
@@ -580,9 +580,9 @@ describe('HasOneResolver', function () {
|
|
|
580
580
|
});
|
|
581
581
|
|
|
582
582
|
it('requires elements of the "entities" parameter to be an Object', async function () {
|
|
583
|
-
const
|
|
584
|
-
|
|
585
|
-
const R =
|
|
583
|
+
const dbs = new DatabaseSchema();
|
|
584
|
+
dbs.defineModel({name: 'source'});
|
|
585
|
+
const R = dbs.getService(HasOneResolver);
|
|
586
586
|
const error = v =>
|
|
587
587
|
format(
|
|
588
588
|
'The parameter "entities" of HasOneResolver.includePolymorphicTo requires ' +
|
|
@@ -609,8 +609,8 @@ describe('HasOneResolver', function () {
|
|
|
609
609
|
});
|
|
610
610
|
|
|
611
611
|
it('requires the "sourceName" parameter to be a non-empty string', async function () {
|
|
612
|
-
const
|
|
613
|
-
const R =
|
|
612
|
+
const dbs = new DatabaseSchema();
|
|
613
|
+
const R = dbs.getService(HasOneResolver);
|
|
614
614
|
const error = v =>
|
|
615
615
|
format(
|
|
616
616
|
'The parameter "sourceName" of HasOneResolver.includePolymorphicTo requires ' +
|
|
@@ -637,8 +637,8 @@ describe('HasOneResolver', function () {
|
|
|
637
637
|
});
|
|
638
638
|
|
|
639
639
|
it('requires the "targetName" parameter to be a non-empty string', async function () {
|
|
640
|
-
const
|
|
641
|
-
const R =
|
|
640
|
+
const dbs = new DatabaseSchema();
|
|
641
|
+
const R = dbs.getService(HasOneResolver);
|
|
642
642
|
const error = v =>
|
|
643
643
|
format(
|
|
644
644
|
'The parameter "targetName" of HasOneResolver.includePolymorphicTo requires ' +
|
|
@@ -665,8 +665,8 @@ describe('HasOneResolver', function () {
|
|
|
665
665
|
});
|
|
666
666
|
|
|
667
667
|
it('requires the "relationName" parameter to be a non-empty string', async function () {
|
|
668
|
-
const
|
|
669
|
-
const R =
|
|
668
|
+
const dbs = new DatabaseSchema();
|
|
669
|
+
const R = dbs.getService(HasOneResolver);
|
|
670
670
|
const error = v =>
|
|
671
671
|
format(
|
|
672
672
|
'The parameter "relationName" of HasOneResolver.includePolymorphicTo requires ' +
|
|
@@ -693,8 +693,8 @@ describe('HasOneResolver', function () {
|
|
|
693
693
|
});
|
|
694
694
|
|
|
695
695
|
it('requires the "foreignKey" parameter to be a non-empty string', async function () {
|
|
696
|
-
const
|
|
697
|
-
const R =
|
|
696
|
+
const dbs = new DatabaseSchema();
|
|
697
|
+
const R = dbs.getService(HasOneResolver);
|
|
698
698
|
const error = v =>
|
|
699
699
|
format(
|
|
700
700
|
'The parameter "foreignKey" of HasOneResolver.includePolymorphicTo requires ' +
|
|
@@ -721,8 +721,8 @@ describe('HasOneResolver', function () {
|
|
|
721
721
|
});
|
|
722
722
|
|
|
723
723
|
it('requires the "discriminator" parameter to be a non-empty string', async function () {
|
|
724
|
-
const
|
|
725
|
-
const R =
|
|
724
|
+
const dbs = new DatabaseSchema();
|
|
725
|
+
const R = dbs.getService(HasOneResolver);
|
|
726
726
|
const error = v =>
|
|
727
727
|
format(
|
|
728
728
|
'The parameter "discriminator" of HasOneResolver.includePolymorphicTo requires ' +
|
|
@@ -749,8 +749,8 @@ describe('HasOneResolver', function () {
|
|
|
749
749
|
});
|
|
750
750
|
|
|
751
751
|
it('requires the provided parameter "scope" to be an object', async function () {
|
|
752
|
-
const
|
|
753
|
-
const R =
|
|
752
|
+
const dbs = new DatabaseSchema();
|
|
753
|
+
const R = dbs.getService(HasOneResolver);
|
|
754
754
|
const error = v =>
|
|
755
755
|
format(
|
|
756
756
|
'The provided parameter "scope" of HasOneResolver.includePolymorphicTo ' +
|
|
@@ -774,9 +774,9 @@ describe('HasOneResolver', function () {
|
|
|
774
774
|
});
|
|
775
775
|
|
|
776
776
|
it('throws an error if the given target model is not found', async function () {
|
|
777
|
-
const
|
|
778
|
-
|
|
779
|
-
const R =
|
|
777
|
+
const dbs = new DatabaseSchema();
|
|
778
|
+
dbs.defineModel({name: 'source'});
|
|
779
|
+
const R = dbs.getService(HasOneResolver);
|
|
780
780
|
const entity = {[DEF_PK]: 1};
|
|
781
781
|
const promise = R.includePolymorphicTo(
|
|
782
782
|
[entity],
|
|
@@ -792,10 +792,10 @@ describe('HasOneResolver', function () {
|
|
|
792
792
|
});
|
|
793
793
|
|
|
794
794
|
it('throws an error if the given target model does not have a datasource', async function () {
|
|
795
|
-
const
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
const R =
|
|
795
|
+
const dbs = new DatabaseSchema();
|
|
796
|
+
dbs.defineModel({name: 'source'});
|
|
797
|
+
dbs.defineModel({name: 'target'});
|
|
798
|
+
const R = dbs.getService(HasOneResolver);
|
|
799
799
|
const entity = {[DEF_PK]: 1};
|
|
800
800
|
const promise = R.includePolymorphicTo(
|
|
801
801
|
[entity],
|
|
@@ -811,16 +811,16 @@ describe('HasOneResolver', function () {
|
|
|
811
811
|
});
|
|
812
812
|
|
|
813
813
|
it('does not throw an error if a relation target is not found', async function () {
|
|
814
|
-
const
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
const sourceRel =
|
|
814
|
+
const dbs = new DatabaseSchema();
|
|
815
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
816
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
817
|
+
dbs.defineModel({name: 'target', datasource: 'datasource'});
|
|
818
|
+
const sourceRel = dbs.getRepository('source');
|
|
819
819
|
const source = await sourceRel.create({});
|
|
820
820
|
expect(source).to.be.eql({
|
|
821
821
|
[DEF_PK]: source[DEF_PK],
|
|
822
822
|
});
|
|
823
|
-
const R =
|
|
823
|
+
const R = dbs.getService(HasOneResolver);
|
|
824
824
|
await R.includePolymorphicTo(
|
|
825
825
|
[source],
|
|
826
826
|
'source',
|
|
@@ -835,12 +835,12 @@ describe('HasOneResolver', function () {
|
|
|
835
835
|
});
|
|
836
836
|
|
|
837
837
|
it('does not include an entity with a not matched discriminator value', async function () {
|
|
838
|
-
const
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
const sourceRel =
|
|
843
|
-
const targetRel =
|
|
838
|
+
const dbs = new DatabaseSchema();
|
|
839
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
840
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
841
|
+
dbs.defineModel({name: 'target', datasource: 'datasource'});
|
|
842
|
+
const sourceRel = dbs.getRepository('source');
|
|
843
|
+
const targetRel = dbs.getRepository('target');
|
|
844
844
|
const source = await sourceRel.create({});
|
|
845
845
|
expect(source).to.be.eql({
|
|
846
846
|
[DEF_PK]: source[DEF_PK],
|
|
@@ -854,7 +854,7 @@ describe('HasOneResolver', function () {
|
|
|
854
854
|
parentId: source[DEF_PK],
|
|
855
855
|
parentType: 'unknown',
|
|
856
856
|
});
|
|
857
|
-
const R =
|
|
857
|
+
const R = dbs.getService(HasOneResolver);
|
|
858
858
|
await R.includePolymorphicTo(
|
|
859
859
|
[source],
|
|
860
860
|
'source',
|
|
@@ -869,12 +869,12 @@ describe('HasOneResolver', function () {
|
|
|
869
869
|
});
|
|
870
870
|
|
|
871
871
|
it('includes if a primary key is not defined in the source model', async function () {
|
|
872
|
-
const
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
const sourceRep =
|
|
877
|
-
const targetRep =
|
|
872
|
+
const dbs = new DatabaseSchema();
|
|
873
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
874
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
875
|
+
dbs.defineModel({name: 'target', datasource: 'datasource'});
|
|
876
|
+
const sourceRep = dbs.getRepository('source');
|
|
877
|
+
const targetRep = dbs.getRepository('target');
|
|
878
878
|
const source = await sourceRep.create({});
|
|
879
879
|
expect(source).to.be.eql({[DEF_PK]: source[DEF_PK]});
|
|
880
880
|
const target = await targetRep.create({
|
|
@@ -886,7 +886,7 @@ describe('HasOneResolver', function () {
|
|
|
886
886
|
parentId: source[DEF_PK],
|
|
887
887
|
parentType: target.parentType,
|
|
888
888
|
});
|
|
889
|
-
const R =
|
|
889
|
+
const R = dbs.getService(HasOneResolver);
|
|
890
890
|
await R.includePolymorphicTo(
|
|
891
891
|
[source],
|
|
892
892
|
'source',
|
|
@@ -906,9 +906,9 @@ describe('HasOneResolver', function () {
|
|
|
906
906
|
});
|
|
907
907
|
|
|
908
908
|
it('includes if the source model has a custom primary key', async function () {
|
|
909
|
-
const
|
|
910
|
-
|
|
911
|
-
|
|
909
|
+
const dbs = new DatabaseSchema();
|
|
910
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
911
|
+
dbs.defineModel({
|
|
912
912
|
name: 'source',
|
|
913
913
|
datasource: 'datasource',
|
|
914
914
|
properties: {
|
|
@@ -918,9 +918,9 @@ describe('HasOneResolver', function () {
|
|
|
918
918
|
},
|
|
919
919
|
},
|
|
920
920
|
});
|
|
921
|
-
|
|
922
|
-
const sourceRep =
|
|
923
|
-
const targetRep =
|
|
921
|
+
dbs.defineModel({name: 'target', datasource: 'datasource'});
|
|
922
|
+
const sourceRep = dbs.getRepository('source');
|
|
923
|
+
const targetRep = dbs.getRepository('target');
|
|
924
924
|
const source = await sourceRep.create({});
|
|
925
925
|
expect(source).to.be.eql({myId: source.myId});
|
|
926
926
|
const target = await targetRep.create({
|
|
@@ -932,7 +932,7 @@ describe('HasOneResolver', function () {
|
|
|
932
932
|
parentId: source.myId,
|
|
933
933
|
parentType: target.parentType,
|
|
934
934
|
});
|
|
935
|
-
const R =
|
|
935
|
+
const R = dbs.getService(HasOneResolver);
|
|
936
936
|
await R.includePolymorphicTo(
|
|
937
937
|
[source],
|
|
938
938
|
'source',
|
|
@@ -952,10 +952,10 @@ describe('HasOneResolver', function () {
|
|
|
952
952
|
});
|
|
953
953
|
|
|
954
954
|
it('includes if the target model has a custom primary key', async function () {
|
|
955
|
-
const
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
955
|
+
const dbs = new DatabaseSchema();
|
|
956
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
957
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
958
|
+
dbs.defineModel({
|
|
959
959
|
name: 'target',
|
|
960
960
|
datasource: 'datasource',
|
|
961
961
|
properties: {
|
|
@@ -965,8 +965,8 @@ describe('HasOneResolver', function () {
|
|
|
965
965
|
},
|
|
966
966
|
},
|
|
967
967
|
});
|
|
968
|
-
const sourceRep =
|
|
969
|
-
const targetRep =
|
|
968
|
+
const sourceRep = dbs.getRepository('source');
|
|
969
|
+
const targetRep = dbs.getRepository('target');
|
|
970
970
|
const source = await sourceRep.create({});
|
|
971
971
|
expect(source).to.be.eql({[DEF_PK]: source[DEF_PK]});
|
|
972
972
|
const target = await targetRep.create({
|
|
@@ -978,7 +978,7 @@ describe('HasOneResolver', function () {
|
|
|
978
978
|
parentId: source[DEF_PK],
|
|
979
979
|
parentType: target.parentType,
|
|
980
980
|
});
|
|
981
|
-
const R =
|
|
981
|
+
const R = dbs.getService(HasOneResolver);
|
|
982
982
|
await R.includePolymorphicTo(
|
|
983
983
|
[source],
|
|
984
984
|
'source',
|
|
@@ -998,12 +998,12 @@ describe('HasOneResolver', function () {
|
|
|
998
998
|
});
|
|
999
999
|
|
|
1000
1000
|
it('uses a where clause of the given scope to filter the relation target', async function () {
|
|
1001
|
-
const
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
const sourceRep =
|
|
1006
|
-
const targetRep =
|
|
1001
|
+
const dbs = new DatabaseSchema();
|
|
1002
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
1003
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
1004
|
+
dbs.defineModel({name: 'target', datasource: 'datasource'});
|
|
1005
|
+
const sourceRep = dbs.getRepository('source');
|
|
1006
|
+
const targetRep = dbs.getRepository('target');
|
|
1007
1007
|
const source = await sourceRep.create({});
|
|
1008
1008
|
expect(source).to.be.eql({[DEF_PK]: source[DEF_PK]});
|
|
1009
1009
|
const target1 = await targetRep.create({
|
|
@@ -1028,7 +1028,7 @@ describe('HasOneResolver', function () {
|
|
|
1028
1028
|
parentId: source[DEF_PK],
|
|
1029
1029
|
parentType: target2.parentType,
|
|
1030
1030
|
});
|
|
1031
|
-
const R =
|
|
1031
|
+
const R = dbs.getService(HasOneResolver);
|
|
1032
1032
|
await R.includePolymorphicTo(
|
|
1033
1033
|
[source],
|
|
1034
1034
|
'source',
|
|
@@ -1068,12 +1068,12 @@ describe('HasOneResolver', function () {
|
|
|
1068
1068
|
});
|
|
1069
1069
|
|
|
1070
1070
|
it('uses a fields clause of the given scope to filter the relation target', async function () {
|
|
1071
|
-
const
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
const sourceRep =
|
|
1076
|
-
const targetRep =
|
|
1071
|
+
const dbs = new DatabaseSchema();
|
|
1072
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
1073
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
1074
|
+
dbs.defineModel({name: 'target', datasource: 'datasource'});
|
|
1075
|
+
const sourceRep = dbs.getRepository('source');
|
|
1076
|
+
const targetRep = dbs.getRepository('target');
|
|
1077
1077
|
const source = await sourceRep.create({});
|
|
1078
1078
|
expect(source).to.be.eql({
|
|
1079
1079
|
[DEF_PK]: source[DEF_PK],
|
|
@@ -1091,7 +1091,7 @@ describe('HasOneResolver', function () {
|
|
|
1091
1091
|
parentId: source[DEF_PK],
|
|
1092
1092
|
parentType: target.parentType,
|
|
1093
1093
|
});
|
|
1094
|
-
const R =
|
|
1094
|
+
const R = dbs.getService(HasOneResolver);
|
|
1095
1095
|
await R.includePolymorphicTo(
|
|
1096
1096
|
[source],
|
|
1097
1097
|
'source',
|
|
@@ -1111,12 +1111,12 @@ describe('HasOneResolver', function () {
|
|
|
1111
1111
|
});
|
|
1112
1112
|
|
|
1113
1113
|
it('uses an include clause of the given scope to resolve target relations', async function () {
|
|
1114
|
-
const
|
|
1115
|
-
|
|
1114
|
+
const dbs = new DatabaseSchema();
|
|
1115
|
+
dbs.defineDatasource({
|
|
1116
1116
|
name: 'datasource',
|
|
1117
1117
|
adapter: 'memory',
|
|
1118
1118
|
});
|
|
1119
|
-
|
|
1119
|
+
dbs.defineModel({
|
|
1120
1120
|
name: 'modelA',
|
|
1121
1121
|
datasource: 'datasource',
|
|
1122
1122
|
properties: {
|
|
@@ -1139,7 +1139,7 @@ describe('HasOneResolver', function () {
|
|
|
1139
1139
|
},
|
|
1140
1140
|
},
|
|
1141
1141
|
});
|
|
1142
|
-
|
|
1142
|
+
dbs.defineModel({
|
|
1143
1143
|
name: 'modelB',
|
|
1144
1144
|
datasource: 'datasource',
|
|
1145
1145
|
properties: {
|
|
@@ -1162,7 +1162,7 @@ describe('HasOneResolver', function () {
|
|
|
1162
1162
|
},
|
|
1163
1163
|
},
|
|
1164
1164
|
});
|
|
1165
|
-
|
|
1165
|
+
dbs.defineModel({
|
|
1166
1166
|
name: 'modelC',
|
|
1167
1167
|
datasource: 'datasource',
|
|
1168
1168
|
properties: {
|
|
@@ -1176,9 +1176,9 @@ describe('HasOneResolver', function () {
|
|
|
1176
1176
|
},
|
|
1177
1177
|
},
|
|
1178
1178
|
});
|
|
1179
|
-
const aRep =
|
|
1180
|
-
const bRep =
|
|
1181
|
-
const cRep =
|
|
1179
|
+
const aRep = dbs.getRepository('modelA');
|
|
1180
|
+
const bRep = dbs.getRepository('modelB');
|
|
1181
|
+
const cRep = dbs.getRepository('modelC');
|
|
1182
1182
|
const a = await aRep.create({});
|
|
1183
1183
|
const b = await bRep.create({parentId: a.id, parentType: 'modelA'});
|
|
1184
1184
|
const c = await cRep.create({parentId: b.id, parentType: 'modelB'});
|
|
@@ -1198,7 +1198,7 @@ describe('HasOneResolver', function () {
|
|
|
1198
1198
|
parentId: b.id,
|
|
1199
1199
|
parentType: 'modelB',
|
|
1200
1200
|
});
|
|
1201
|
-
const R =
|
|
1201
|
+
const R = dbs.getService(HasOneResolver);
|
|
1202
1202
|
await R.includePolymorphicTo(
|
|
1203
1203
|
[a],
|
|
1204
1204
|
'modelA',
|
|
@@ -1227,12 +1227,12 @@ describe('HasOneResolver', function () {
|
|
|
1227
1227
|
});
|
|
1228
1228
|
|
|
1229
1229
|
it('does not break the "and" operator of the given "where" clause', async function () {
|
|
1230
|
-
const
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
const sourceRep =
|
|
1235
|
-
const targetRep =
|
|
1230
|
+
const dbs = new DatabaseSchema();
|
|
1231
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
1232
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
1233
|
+
dbs.defineModel({name: 'target', datasource: 'datasource'});
|
|
1234
|
+
const sourceRep = dbs.getRepository('source');
|
|
1235
|
+
const targetRep = dbs.getRepository('target');
|
|
1236
1236
|
const source = await sourceRep.create({});
|
|
1237
1237
|
expect(source).to.be.eql({
|
|
1238
1238
|
[DEF_PK]: source[DEF_PK],
|
|
@@ -1259,7 +1259,7 @@ describe('HasOneResolver', function () {
|
|
|
1259
1259
|
parentId: source[DEF_PK],
|
|
1260
1260
|
parentType: target2.parentType,
|
|
1261
1261
|
});
|
|
1262
|
-
const R =
|
|
1262
|
+
const R = dbs.getService(HasOneResolver);
|
|
1263
1263
|
await R.includePolymorphicTo(
|
|
1264
1264
|
[source],
|
|
1265
1265
|
'source',
|
|
@@ -1302,8 +1302,8 @@ describe('HasOneResolver', function () {
|
|
|
1302
1302
|
|
|
1303
1303
|
describe('includePolymorphicByRelationName', function () {
|
|
1304
1304
|
it('requires the "entities" parameter to be an array', async function () {
|
|
1305
|
-
const
|
|
1306
|
-
const R =
|
|
1305
|
+
const dbs = new DatabaseSchema();
|
|
1306
|
+
const R = dbs.getService(HasOneResolver);
|
|
1307
1307
|
const error = v =>
|
|
1308
1308
|
format(
|
|
1309
1309
|
'The parameter "entities" of HasOneResolver.includePolymorphicByRelationName requires ' +
|
|
@@ -1329,9 +1329,9 @@ describe('HasOneResolver', function () {
|
|
|
1329
1329
|
});
|
|
1330
1330
|
|
|
1331
1331
|
it('requires elements of the "entities" parameter to be an Object', async function () {
|
|
1332
|
-
const
|
|
1333
|
-
|
|
1334
|
-
|
|
1332
|
+
const dbs = new DatabaseSchema();
|
|
1333
|
+
dbs.defineModel({name: 'source'});
|
|
1334
|
+
dbs.defineModel({
|
|
1335
1335
|
name: 'target',
|
|
1336
1336
|
relations: {
|
|
1337
1337
|
parent: {
|
|
@@ -1340,7 +1340,7 @@ describe('HasOneResolver', function () {
|
|
|
1340
1340
|
},
|
|
1341
1341
|
},
|
|
1342
1342
|
});
|
|
1343
|
-
const R =
|
|
1343
|
+
const R = dbs.getService(HasOneResolver);
|
|
1344
1344
|
const error = v =>
|
|
1345
1345
|
format(
|
|
1346
1346
|
'The parameter "entities" of HasOneResolver.includePolymorphicTo requires ' +
|
|
@@ -1366,8 +1366,8 @@ describe('HasOneResolver', function () {
|
|
|
1366
1366
|
});
|
|
1367
1367
|
|
|
1368
1368
|
it('requires the "sourceName" parameter to be a non-empty string', async function () {
|
|
1369
|
-
const
|
|
1370
|
-
const R =
|
|
1369
|
+
const dbs = new DatabaseSchema();
|
|
1370
|
+
const R = dbs.getService(HasOneResolver);
|
|
1371
1371
|
const error = v =>
|
|
1372
1372
|
format(
|
|
1373
1373
|
'The parameter "sourceName" of HasOneResolver.includePolymorphicByRelationName requires ' +
|
|
@@ -1393,8 +1393,8 @@ describe('HasOneResolver', function () {
|
|
|
1393
1393
|
});
|
|
1394
1394
|
|
|
1395
1395
|
it('requires the "targetName" parameter to be a non-empty string', async function () {
|
|
1396
|
-
const
|
|
1397
|
-
const R =
|
|
1396
|
+
const dbs = new DatabaseSchema();
|
|
1397
|
+
const R = dbs.getService(HasOneResolver);
|
|
1398
1398
|
const error = v =>
|
|
1399
1399
|
format(
|
|
1400
1400
|
'The parameter "targetName" of HasOneResolver.includePolymorphicByRelationName requires ' +
|
|
@@ -1420,8 +1420,8 @@ describe('HasOneResolver', function () {
|
|
|
1420
1420
|
});
|
|
1421
1421
|
|
|
1422
1422
|
it('requires the "relationName" parameter to be a non-empty string', async function () {
|
|
1423
|
-
const
|
|
1424
|
-
const R =
|
|
1423
|
+
const dbs = new DatabaseSchema();
|
|
1424
|
+
const R = dbs.getService(HasOneResolver);
|
|
1425
1425
|
const error = v =>
|
|
1426
1426
|
format(
|
|
1427
1427
|
'The parameter "relationName" of HasOneResolver.includePolymorphicByRelationName requires ' +
|
|
@@ -1447,8 +1447,8 @@ describe('HasOneResolver', function () {
|
|
|
1447
1447
|
});
|
|
1448
1448
|
|
|
1449
1449
|
it('requires the "targetRelationName" parameter to be a non-empty string', async function () {
|
|
1450
|
-
const
|
|
1451
|
-
const R =
|
|
1450
|
+
const dbs = new DatabaseSchema();
|
|
1451
|
+
const R = dbs.getService(HasOneResolver);
|
|
1452
1452
|
const error = v =>
|
|
1453
1453
|
format(
|
|
1454
1454
|
'The parameter "targetRelationName" of HasOneResolver.includePolymorphicByRelationName requires ' +
|
|
@@ -1474,8 +1474,8 @@ describe('HasOneResolver', function () {
|
|
|
1474
1474
|
});
|
|
1475
1475
|
|
|
1476
1476
|
it('requires the provided parameter "scope" to be an object', async function () {
|
|
1477
|
-
const
|
|
1478
|
-
const R =
|
|
1477
|
+
const dbs = new DatabaseSchema();
|
|
1478
|
+
const R = dbs.getService(HasOneResolver);
|
|
1479
1479
|
const error = v =>
|
|
1480
1480
|
format(
|
|
1481
1481
|
'The provided parameter "scope" of HasOneResolver.includePolymorphicByRelationName ' +
|
|
@@ -1498,9 +1498,9 @@ describe('HasOneResolver', function () {
|
|
|
1498
1498
|
});
|
|
1499
1499
|
|
|
1500
1500
|
it('throws an error if the given target model is not found', async function () {
|
|
1501
|
-
const
|
|
1502
|
-
|
|
1503
|
-
const R =
|
|
1501
|
+
const dbs = new DatabaseSchema();
|
|
1502
|
+
dbs.defineModel({name: 'source'});
|
|
1503
|
+
const R = dbs.getService(HasOneResolver);
|
|
1504
1504
|
const entity = {[DEF_PK]: 1};
|
|
1505
1505
|
const promise = R.includePolymorphicByRelationName(
|
|
1506
1506
|
[entity],
|
|
@@ -1515,10 +1515,10 @@ describe('HasOneResolver', function () {
|
|
|
1515
1515
|
});
|
|
1516
1516
|
|
|
1517
1517
|
it('throws an error if the given target model does not have the given relation name', async function () {
|
|
1518
|
-
const
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
const R =
|
|
1518
|
+
const dbs = new DatabaseSchema();
|
|
1519
|
+
dbs.defineModel({name: 'source'});
|
|
1520
|
+
dbs.defineModel({name: 'target'});
|
|
1521
|
+
const R = dbs.getService(HasOneResolver);
|
|
1522
1522
|
const entity = {[DEF_PK]: 1};
|
|
1523
1523
|
const promise = R.includePolymorphicByRelationName(
|
|
1524
1524
|
[entity],
|
|
@@ -1533,9 +1533,9 @@ describe('HasOneResolver', function () {
|
|
|
1533
1533
|
});
|
|
1534
1534
|
|
|
1535
1535
|
it('throws an error if the target relation is not "belongsTo"', async function () {
|
|
1536
|
-
const
|
|
1537
|
-
|
|
1538
|
-
|
|
1536
|
+
const dbs = new DatabaseSchema();
|
|
1537
|
+
dbs.defineModel({name: 'source'});
|
|
1538
|
+
dbs.defineModel({
|
|
1539
1539
|
name: 'target',
|
|
1540
1540
|
relations: {
|
|
1541
1541
|
parent: {
|
|
@@ -1544,7 +1544,7 @@ describe('HasOneResolver', function () {
|
|
|
1544
1544
|
},
|
|
1545
1545
|
},
|
|
1546
1546
|
});
|
|
1547
|
-
const R =
|
|
1547
|
+
const R = dbs.getService(HasOneResolver);
|
|
1548
1548
|
const entity = {[DEF_PK]: 1};
|
|
1549
1549
|
const promise = R.includePolymorphicByRelationName(
|
|
1550
1550
|
[entity],
|
|
@@ -1561,9 +1561,9 @@ describe('HasOneResolver', function () {
|
|
|
1561
1561
|
});
|
|
1562
1562
|
|
|
1563
1563
|
it('throws an error if the target relation is not polymorphic', async function () {
|
|
1564
|
-
const
|
|
1565
|
-
|
|
1566
|
-
|
|
1564
|
+
const dbs = new DatabaseSchema();
|
|
1565
|
+
dbs.defineModel({name: 'source'});
|
|
1566
|
+
dbs.defineModel({
|
|
1567
1567
|
name: 'target',
|
|
1568
1568
|
relations: {
|
|
1569
1569
|
parent: {
|
|
@@ -1572,7 +1572,7 @@ describe('HasOneResolver', function () {
|
|
|
1572
1572
|
},
|
|
1573
1573
|
},
|
|
1574
1574
|
});
|
|
1575
|
-
const R =
|
|
1575
|
+
const R = dbs.getService(HasOneResolver);
|
|
1576
1576
|
const entity = {[DEF_PK]: 1};
|
|
1577
1577
|
const promise = R.includePolymorphicByRelationName(
|
|
1578
1578
|
[entity],
|
|
@@ -1589,9 +1589,9 @@ describe('HasOneResolver', function () {
|
|
|
1589
1589
|
});
|
|
1590
1590
|
|
|
1591
1591
|
it('throws an error if the given target model does not have a datasource', async function () {
|
|
1592
|
-
const
|
|
1593
|
-
|
|
1594
|
-
|
|
1592
|
+
const dbs = new DatabaseSchema();
|
|
1593
|
+
dbs.defineModel({name: 'source'});
|
|
1594
|
+
dbs.defineModel({
|
|
1595
1595
|
name: 'target',
|
|
1596
1596
|
relations: {
|
|
1597
1597
|
parent: {
|
|
@@ -1600,7 +1600,7 @@ describe('HasOneResolver', function () {
|
|
|
1600
1600
|
},
|
|
1601
1601
|
},
|
|
1602
1602
|
});
|
|
1603
|
-
const R =
|
|
1603
|
+
const R = dbs.getService(HasOneResolver);
|
|
1604
1604
|
const entity = {[DEF_PK]: 1};
|
|
1605
1605
|
const promise = R.includePolymorphicByRelationName(
|
|
1606
1606
|
[entity],
|
|
@@ -1615,10 +1615,10 @@ describe('HasOneResolver', function () {
|
|
|
1615
1615
|
});
|
|
1616
1616
|
|
|
1617
1617
|
it('does not throw an error if a relation target is not found', async function () {
|
|
1618
|
-
const
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1618
|
+
const dbs = new DatabaseSchema();
|
|
1619
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
1620
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
1621
|
+
dbs.defineModel({
|
|
1622
1622
|
name: 'target',
|
|
1623
1623
|
datasource: 'datasource',
|
|
1624
1624
|
relations: {
|
|
@@ -1628,12 +1628,12 @@ describe('HasOneResolver', function () {
|
|
|
1628
1628
|
},
|
|
1629
1629
|
},
|
|
1630
1630
|
});
|
|
1631
|
-
const sourceRel =
|
|
1631
|
+
const sourceRel = dbs.getRepository('source');
|
|
1632
1632
|
const source = await sourceRel.create({});
|
|
1633
1633
|
expect(source).to.be.eql({
|
|
1634
1634
|
[DEF_PK]: source[DEF_PK],
|
|
1635
1635
|
});
|
|
1636
|
-
const R =
|
|
1636
|
+
const R = dbs.getService(HasOneResolver);
|
|
1637
1637
|
await R.includePolymorphicByRelationName(
|
|
1638
1638
|
[source],
|
|
1639
1639
|
'source',
|
|
@@ -1647,10 +1647,10 @@ describe('HasOneResolver', function () {
|
|
|
1647
1647
|
});
|
|
1648
1648
|
|
|
1649
1649
|
it('does not include an entity with a not matched discriminator value', async function () {
|
|
1650
|
-
const
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1650
|
+
const dbs = new DatabaseSchema();
|
|
1651
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
1652
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
1653
|
+
dbs.defineModel({
|
|
1654
1654
|
name: 'target',
|
|
1655
1655
|
datasource: 'datasource',
|
|
1656
1656
|
relations: {
|
|
@@ -1660,8 +1660,8 @@ describe('HasOneResolver', function () {
|
|
|
1660
1660
|
},
|
|
1661
1661
|
},
|
|
1662
1662
|
});
|
|
1663
|
-
const sourceRel =
|
|
1664
|
-
const targetRel =
|
|
1663
|
+
const sourceRel = dbs.getRepository('source');
|
|
1664
|
+
const targetRel = dbs.getRepository('target');
|
|
1665
1665
|
const source = await sourceRel.create({});
|
|
1666
1666
|
expect(source).to.be.eql({
|
|
1667
1667
|
[DEF_PK]: source[DEF_PK],
|
|
@@ -1675,7 +1675,7 @@ describe('HasOneResolver', function () {
|
|
|
1675
1675
|
parentId: source[DEF_PK],
|
|
1676
1676
|
parentType: 'unknown',
|
|
1677
1677
|
});
|
|
1678
|
-
const R =
|
|
1678
|
+
const R = dbs.getService(HasOneResolver);
|
|
1679
1679
|
await R.includePolymorphicByRelationName(
|
|
1680
1680
|
[source],
|
|
1681
1681
|
'source',
|
|
@@ -1689,10 +1689,10 @@ describe('HasOneResolver', function () {
|
|
|
1689
1689
|
});
|
|
1690
1690
|
|
|
1691
1691
|
it('includes if a primary key is not defined in the source model', async function () {
|
|
1692
|
-
const
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1692
|
+
const dbs = new DatabaseSchema();
|
|
1693
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
1694
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
1695
|
+
dbs.defineModel({
|
|
1696
1696
|
name: 'target',
|
|
1697
1697
|
datasource: 'datasource',
|
|
1698
1698
|
relations: {
|
|
@@ -1702,8 +1702,8 @@ describe('HasOneResolver', function () {
|
|
|
1702
1702
|
},
|
|
1703
1703
|
},
|
|
1704
1704
|
});
|
|
1705
|
-
const sourceRep =
|
|
1706
|
-
const targetRep =
|
|
1705
|
+
const sourceRep = dbs.getRepository('source');
|
|
1706
|
+
const targetRep = dbs.getRepository('target');
|
|
1707
1707
|
const source = await sourceRep.create({});
|
|
1708
1708
|
expect(source).to.be.eql({[DEF_PK]: source[DEF_PK]});
|
|
1709
1709
|
const target = await targetRep.create({
|
|
@@ -1715,7 +1715,7 @@ describe('HasOneResolver', function () {
|
|
|
1715
1715
|
parentId: source[DEF_PK],
|
|
1716
1716
|
parentType: target.parentType,
|
|
1717
1717
|
});
|
|
1718
|
-
const R =
|
|
1718
|
+
const R = dbs.getService(HasOneResolver);
|
|
1719
1719
|
await R.includePolymorphicByRelationName(
|
|
1720
1720
|
[source],
|
|
1721
1721
|
'source',
|
|
@@ -1734,9 +1734,9 @@ describe('HasOneResolver', function () {
|
|
|
1734
1734
|
});
|
|
1735
1735
|
|
|
1736
1736
|
it('includes if the source model has a custom primary key', async function () {
|
|
1737
|
-
const
|
|
1738
|
-
|
|
1739
|
-
|
|
1737
|
+
const dbs = new DatabaseSchema();
|
|
1738
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
1739
|
+
dbs.defineModel({
|
|
1740
1740
|
name: 'source',
|
|
1741
1741
|
datasource: 'datasource',
|
|
1742
1742
|
properties: {
|
|
@@ -1746,7 +1746,7 @@ describe('HasOneResolver', function () {
|
|
|
1746
1746
|
},
|
|
1747
1747
|
},
|
|
1748
1748
|
});
|
|
1749
|
-
|
|
1749
|
+
dbs.defineModel({
|
|
1750
1750
|
name: 'target',
|
|
1751
1751
|
datasource: 'datasource',
|
|
1752
1752
|
relations: {
|
|
@@ -1756,8 +1756,8 @@ describe('HasOneResolver', function () {
|
|
|
1756
1756
|
},
|
|
1757
1757
|
},
|
|
1758
1758
|
});
|
|
1759
|
-
const sourceRep =
|
|
1760
|
-
const targetRep =
|
|
1759
|
+
const sourceRep = dbs.getRepository('source');
|
|
1760
|
+
const targetRep = dbs.getRepository('target');
|
|
1761
1761
|
const source = await sourceRep.create({});
|
|
1762
1762
|
expect(source).to.be.eql({myId: source.myId});
|
|
1763
1763
|
const target = await targetRep.create({
|
|
@@ -1769,7 +1769,7 @@ describe('HasOneResolver', function () {
|
|
|
1769
1769
|
parentId: source.myId,
|
|
1770
1770
|
parentType: target.parentType,
|
|
1771
1771
|
});
|
|
1772
|
-
const R =
|
|
1772
|
+
const R = dbs.getService(HasOneResolver);
|
|
1773
1773
|
await R.includePolymorphicByRelationName(
|
|
1774
1774
|
[source],
|
|
1775
1775
|
'source',
|
|
@@ -1788,10 +1788,10 @@ describe('HasOneResolver', function () {
|
|
|
1788
1788
|
});
|
|
1789
1789
|
|
|
1790
1790
|
it('includes if the target model has a custom primary key', async function () {
|
|
1791
|
-
const
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1791
|
+
const dbs = new DatabaseSchema();
|
|
1792
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
1793
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
1794
|
+
dbs.defineModel({
|
|
1795
1795
|
name: 'target',
|
|
1796
1796
|
datasource: 'datasource',
|
|
1797
1797
|
properties: {
|
|
@@ -1807,8 +1807,8 @@ describe('HasOneResolver', function () {
|
|
|
1807
1807
|
},
|
|
1808
1808
|
},
|
|
1809
1809
|
});
|
|
1810
|
-
const sourceRep =
|
|
1811
|
-
const targetRep =
|
|
1810
|
+
const sourceRep = dbs.getRepository('source');
|
|
1811
|
+
const targetRep = dbs.getRepository('target');
|
|
1812
1812
|
const source = await sourceRep.create({});
|
|
1813
1813
|
expect(source).to.be.eql({[DEF_PK]: source[DEF_PK]});
|
|
1814
1814
|
const target = await targetRep.create({
|
|
@@ -1820,7 +1820,7 @@ describe('HasOneResolver', function () {
|
|
|
1820
1820
|
parentId: source[DEF_PK],
|
|
1821
1821
|
parentType: target.parentType,
|
|
1822
1822
|
});
|
|
1823
|
-
const R =
|
|
1823
|
+
const R = dbs.getService(HasOneResolver);
|
|
1824
1824
|
await R.includePolymorphicByRelationName(
|
|
1825
1825
|
[source],
|
|
1826
1826
|
'source',
|
|
@@ -1839,10 +1839,10 @@ describe('HasOneResolver', function () {
|
|
|
1839
1839
|
});
|
|
1840
1840
|
|
|
1841
1841
|
it('includes if the target model has a custom "foreignKey"', async function () {
|
|
1842
|
-
const
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1842
|
+
const dbs = new DatabaseSchema();
|
|
1843
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
1844
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
1845
|
+
dbs.defineModel({
|
|
1846
1846
|
name: 'target',
|
|
1847
1847
|
datasource: 'datasource',
|
|
1848
1848
|
properties: {
|
|
@@ -1859,8 +1859,8 @@ describe('HasOneResolver', function () {
|
|
|
1859
1859
|
},
|
|
1860
1860
|
},
|
|
1861
1861
|
});
|
|
1862
|
-
const sourceRep =
|
|
1863
|
-
const targetRep =
|
|
1862
|
+
const sourceRep = dbs.getRepository('source');
|
|
1863
|
+
const targetRep = dbs.getRepository('target');
|
|
1864
1864
|
const source = await sourceRep.create({});
|
|
1865
1865
|
expect(source).to.be.eql({[DEF_PK]: source[DEF_PK]});
|
|
1866
1866
|
const target = await targetRep.create({
|
|
@@ -1872,7 +1872,7 @@ describe('HasOneResolver', function () {
|
|
|
1872
1872
|
relationId: source[DEF_PK],
|
|
1873
1873
|
parentType: target.parentType,
|
|
1874
1874
|
});
|
|
1875
|
-
const R =
|
|
1875
|
+
const R = dbs.getService(HasOneResolver);
|
|
1876
1876
|
await R.includePolymorphicByRelationName(
|
|
1877
1877
|
[source],
|
|
1878
1878
|
'source',
|
|
@@ -1891,10 +1891,10 @@ describe('HasOneResolver', function () {
|
|
|
1891
1891
|
});
|
|
1892
1892
|
|
|
1893
1893
|
it('includes if the target model has a custom "discriminator"', async function () {
|
|
1894
|
-
const
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1894
|
+
const dbs = new DatabaseSchema();
|
|
1895
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
1896
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
1897
|
+
dbs.defineModel({
|
|
1898
1898
|
name: 'target',
|
|
1899
1899
|
datasource: 'datasource',
|
|
1900
1900
|
properties: {
|
|
@@ -1911,8 +1911,8 @@ describe('HasOneResolver', function () {
|
|
|
1911
1911
|
},
|
|
1912
1912
|
},
|
|
1913
1913
|
});
|
|
1914
|
-
const sourceRep =
|
|
1915
|
-
const targetRep =
|
|
1914
|
+
const sourceRep = dbs.getRepository('source');
|
|
1915
|
+
const targetRep = dbs.getRepository('target');
|
|
1916
1916
|
const source = await sourceRep.create({});
|
|
1917
1917
|
expect(source).to.be.eql({[DEF_PK]: source[DEF_PK]});
|
|
1918
1918
|
const target = await targetRep.create({
|
|
@@ -1924,7 +1924,7 @@ describe('HasOneResolver', function () {
|
|
|
1924
1924
|
parentId: source[DEF_PK],
|
|
1925
1925
|
relationType: target.relationType,
|
|
1926
1926
|
});
|
|
1927
|
-
const R =
|
|
1927
|
+
const R = dbs.getService(HasOneResolver);
|
|
1928
1928
|
await R.includePolymorphicByRelationName(
|
|
1929
1929
|
[source],
|
|
1930
1930
|
'source',
|
|
@@ -1943,10 +1943,10 @@ describe('HasOneResolver', function () {
|
|
|
1943
1943
|
});
|
|
1944
1944
|
|
|
1945
1945
|
it('uses a where clause of the given scope to filter the relation target', async function () {
|
|
1946
|
-
const
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1946
|
+
const dbs = new DatabaseSchema();
|
|
1947
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
1948
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
1949
|
+
dbs.defineModel({
|
|
1950
1950
|
name: 'target',
|
|
1951
1951
|
datasource: 'datasource',
|
|
1952
1952
|
relations: {
|
|
@@ -1956,8 +1956,8 @@ describe('HasOneResolver', function () {
|
|
|
1956
1956
|
},
|
|
1957
1957
|
},
|
|
1958
1958
|
});
|
|
1959
|
-
const sourceRep =
|
|
1960
|
-
const targetRep =
|
|
1959
|
+
const sourceRep = dbs.getRepository('source');
|
|
1960
|
+
const targetRep = dbs.getRepository('target');
|
|
1961
1961
|
const source = await sourceRep.create({});
|
|
1962
1962
|
expect(source).to.be.eql({[DEF_PK]: source[DEF_PK]});
|
|
1963
1963
|
const target1 = await targetRep.create({
|
|
@@ -1982,7 +1982,7 @@ describe('HasOneResolver', function () {
|
|
|
1982
1982
|
parentId: source[DEF_PK],
|
|
1983
1983
|
parentType: target2.parentType,
|
|
1984
1984
|
});
|
|
1985
|
-
const R =
|
|
1985
|
+
const R = dbs.getService(HasOneResolver);
|
|
1986
1986
|
await R.includePolymorphicByRelationName(
|
|
1987
1987
|
[source],
|
|
1988
1988
|
'source',
|
|
@@ -2020,10 +2020,10 @@ describe('HasOneResolver', function () {
|
|
|
2020
2020
|
});
|
|
2021
2021
|
|
|
2022
2022
|
it('uses a fields clause of the given scope to filter the relation target', async function () {
|
|
2023
|
-
const
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2023
|
+
const dbs = new DatabaseSchema();
|
|
2024
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
2025
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
2026
|
+
dbs.defineModel({
|
|
2027
2027
|
name: 'target',
|
|
2028
2028
|
datasource: 'datasource',
|
|
2029
2029
|
relations: {
|
|
@@ -2033,8 +2033,8 @@ describe('HasOneResolver', function () {
|
|
|
2033
2033
|
},
|
|
2034
2034
|
},
|
|
2035
2035
|
});
|
|
2036
|
-
const sourceRep =
|
|
2037
|
-
const targetRep =
|
|
2036
|
+
const sourceRep = dbs.getRepository('source');
|
|
2037
|
+
const targetRep = dbs.getRepository('target');
|
|
2038
2038
|
const source = await sourceRep.create({});
|
|
2039
2039
|
expect(source).to.be.eql({
|
|
2040
2040
|
[DEF_PK]: source[DEF_PK],
|
|
@@ -2052,7 +2052,7 @@ describe('HasOneResolver', function () {
|
|
|
2052
2052
|
parentId: source[DEF_PK],
|
|
2053
2053
|
parentType: target.parentType,
|
|
2054
2054
|
});
|
|
2055
|
-
const R =
|
|
2055
|
+
const R = dbs.getService(HasOneResolver);
|
|
2056
2056
|
await R.includePolymorphicByRelationName(
|
|
2057
2057
|
[source],
|
|
2058
2058
|
'source',
|
|
@@ -2071,12 +2071,12 @@ describe('HasOneResolver', function () {
|
|
|
2071
2071
|
});
|
|
2072
2072
|
|
|
2073
2073
|
it('uses an include clause of the given scope to resolve target relations', async function () {
|
|
2074
|
-
const
|
|
2075
|
-
|
|
2074
|
+
const dbs = new DatabaseSchema();
|
|
2075
|
+
dbs.defineDatasource({
|
|
2076
2076
|
name: 'datasource',
|
|
2077
2077
|
adapter: 'memory',
|
|
2078
2078
|
});
|
|
2079
|
-
|
|
2079
|
+
dbs.defineModel({
|
|
2080
2080
|
name: 'modelA',
|
|
2081
2081
|
datasource: 'datasource',
|
|
2082
2082
|
properties: {
|
|
@@ -2097,7 +2097,7 @@ describe('HasOneResolver', function () {
|
|
|
2097
2097
|
},
|
|
2098
2098
|
},
|
|
2099
2099
|
});
|
|
2100
|
-
|
|
2100
|
+
dbs.defineModel({
|
|
2101
2101
|
name: 'modelB',
|
|
2102
2102
|
datasource: 'datasource',
|
|
2103
2103
|
properties: {
|
|
@@ -2122,7 +2122,7 @@ describe('HasOneResolver', function () {
|
|
|
2122
2122
|
},
|
|
2123
2123
|
},
|
|
2124
2124
|
});
|
|
2125
|
-
|
|
2125
|
+
dbs.defineModel({
|
|
2126
2126
|
name: 'modelC',
|
|
2127
2127
|
datasource: 'datasource',
|
|
2128
2128
|
properties: {
|
|
@@ -2142,9 +2142,9 @@ describe('HasOneResolver', function () {
|
|
|
2142
2142
|
},
|
|
2143
2143
|
},
|
|
2144
2144
|
});
|
|
2145
|
-
const aRep =
|
|
2146
|
-
const bRep =
|
|
2147
|
-
const cRep =
|
|
2145
|
+
const aRep = dbs.getRepository('modelA');
|
|
2146
|
+
const bRep = dbs.getRepository('modelB');
|
|
2147
|
+
const cRep = dbs.getRepository('modelC');
|
|
2148
2148
|
const a = await aRep.create({});
|
|
2149
2149
|
const b = await bRep.create({parentId: a.id, parentType: 'modelA'});
|
|
2150
2150
|
const c = await cRep.create({parentId: b.id, parentType: 'modelB'});
|
|
@@ -2164,7 +2164,7 @@ describe('HasOneResolver', function () {
|
|
|
2164
2164
|
parentId: b.id,
|
|
2165
2165
|
parentType: 'modelB',
|
|
2166
2166
|
});
|
|
2167
|
-
const R =
|
|
2167
|
+
const R = dbs.getService(HasOneResolver);
|
|
2168
2168
|
await R.includePolymorphicByRelationName(
|
|
2169
2169
|
[a],
|
|
2170
2170
|
'modelA',
|
|
@@ -2192,10 +2192,10 @@ describe('HasOneResolver', function () {
|
|
|
2192
2192
|
});
|
|
2193
2193
|
|
|
2194
2194
|
it('does not break the "and" operator of the given "where" clause', async function () {
|
|
2195
|
-
const
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2195
|
+
const dbs = new DatabaseSchema();
|
|
2196
|
+
dbs.defineDatasource({name: 'datasource', adapter: 'memory'});
|
|
2197
|
+
dbs.defineModel({name: 'source', datasource: 'datasource'});
|
|
2198
|
+
dbs.defineModel({
|
|
2199
2199
|
name: 'target',
|
|
2200
2200
|
datasource: 'datasource',
|
|
2201
2201
|
relations: {
|
|
@@ -2205,8 +2205,8 @@ describe('HasOneResolver', function () {
|
|
|
2205
2205
|
},
|
|
2206
2206
|
},
|
|
2207
2207
|
});
|
|
2208
|
-
const sourceRep =
|
|
2209
|
-
const targetRep =
|
|
2208
|
+
const sourceRep = dbs.getRepository('source');
|
|
2209
|
+
const targetRep = dbs.getRepository('target');
|
|
2210
2210
|
const source = await sourceRep.create({});
|
|
2211
2211
|
expect(source).to.be.eql({
|
|
2212
2212
|
[DEF_PK]: source[DEF_PK],
|
|
@@ -2233,7 +2233,7 @@ describe('HasOneResolver', function () {
|
|
|
2233
2233
|
parentId: source[DEF_PK],
|
|
2234
2234
|
parentType: target2.parentType,
|
|
2235
2235
|
});
|
|
2236
|
-
const R =
|
|
2236
|
+
const R = dbs.getService(HasOneResolver);
|
|
2237
2237
|
await R.includePolymorphicByRelationName(
|
|
2238
2238
|
[source],
|
|
2239
2239
|
'source',
|