@loopback/repository-tests 0.20.2 → 0.21.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/dist/crud/relations/acceptance/belongs-to.inclusion-resolver.polymorphic.relation.acceptance.d.ts +2 -0
- package/dist/crud/relations/acceptance/belongs-to.inclusion-resolver.polymorphic.relation.acceptance.js +170 -0
- package/dist/crud/relations/acceptance/belongs-to.inclusion-resolver.polymorphic.relation.acceptance.js.map +1 -0
- package/dist/crud/relations/acceptance/belongs-to.polymorphic.relation.acceptance.d.ts +2 -0
- package/dist/crud/relations/acceptance/belongs-to.polymorphic.relation.acceptance.js +55 -0
- package/dist/crud/relations/acceptance/belongs-to.polymorphic.relation.acceptance.js.map +1 -0
- package/dist/crud/relations/acceptance/has-many-through-inclusion-resolver.polymorphic.acceptance.d.ts +2 -0
- package/dist/crud/relations/acceptance/has-many-through-inclusion-resolver.polymorphic.acceptance.js +170 -0
- package/dist/crud/relations/acceptance/has-many-through-inclusion-resolver.polymorphic.acceptance.js.map +1 -0
- package/dist/crud/relations/acceptance/has-many-through.relation.polymorphic.acceptance.d.ts +2 -0
- package/dist/crud/relations/acceptance/has-many-through.relation.polymorphic.acceptance.js +361 -0
- package/dist/crud/relations/acceptance/has-many-through.relation.polymorphic.acceptance.js.map +1 -0
- package/dist/crud/relations/acceptance/has-one.inclusion-resolver.polymorphic.acceptance.d.ts +2 -0
- package/dist/crud/relations/acceptance/has-one.inclusion-resolver.polymorphic.acceptance.js +161 -0
- package/dist/crud/relations/acceptance/has-one.inclusion-resolver.polymorphic.acceptance.js.map +1 -0
- package/dist/crud/relations/acceptance/has-one.relation.polymorphic.acceptance.d.ts +2 -0
- package/dist/crud/relations/acceptance/has-one.relation.polymorphic.acceptance.js +190 -0
- package/dist/crud/relations/acceptance/has-one.relation.polymorphic.acceptance.js.map +1 -0
- package/dist/crud/relations/fixtures/models/contact.model.d.ts +18 -0
- package/dist/crud/relations/fixtures/models/contact.model.js +49 -0
- package/dist/crud/relations/fixtures/models/contact.model.js.map +1 -0
- package/dist/crud/relations/fixtures/models/customer-promotion-link.model.d.ts +14 -0
- package/dist/crud/relations/fixtures/models/customer-promotion-link.model.js +46 -0
- package/dist/crud/relations/fixtures/models/customer-promotion-link.model.js.map +1 -0
- package/dist/crud/relations/fixtures/models/customer.model.d.ts +16 -3
- package/dist/crud/relations/fixtures/models/customer.model.js +27 -9
- package/dist/crud/relations/fixtures/models/customer.model.js.map +1 -1
- package/dist/crud/relations/fixtures/models/index.d.ts +6 -0
- package/dist/crud/relations/fixtures/models/index.js +6 -0
- package/dist/crud/relations/fixtures/models/index.js.map +1 -1
- package/dist/crud/relations/fixtures/models/payment-method.model.d.ts +47 -0
- package/dist/crud/relations/fixtures/models/payment-method.model.js +87 -0
- package/dist/crud/relations/fixtures/models/payment-method.model.js.map +1 -0
- package/dist/crud/relations/fixtures/models/promotion.model.d.ts +27 -0
- package/dist/crud/relations/fixtures/models/promotion.model.js +54 -0
- package/dist/crud/relations/fixtures/models/promotion.model.js.map +1 -0
- package/dist/crud/relations/fixtures/models/stakeholder.model.d.ts +7 -0
- package/dist/crud/relations/fixtures/models/stakeholder.model.js +38 -0
- package/dist/crud/relations/fixtures/models/stakeholder.model.js.map +1 -0
- package/dist/crud/relations/fixtures/models/supplier.model.d.ts +15 -0
- package/dist/crud/relations/fixtures/models/supplier.model.js +23 -0
- package/dist/crud/relations/fixtures/models/supplier.model.js.map +1 -0
- package/dist/crud/relations/fixtures/repositories/contact.repository.d.ts +30 -0
- package/dist/crud/relations/fixtures/repositories/contact.repository.js +21 -0
- package/dist/crud/relations/fixtures/repositories/contact.repository.js.map +1 -0
- package/dist/crud/relations/fixtures/repositories/customer-promotion-link.repository.d.ts +26 -0
- package/dist/crud/relations/fixtures/repositories/customer-promotion-link.repository.js +18 -0
- package/dist/crud/relations/fixtures/repositories/customer-promotion-link.repository.js.map +1 -0
- package/dist/crud/relations/fixtures/repositories/customer.repository.d.ts +9 -2
- package/dist/crud/relations/fixtures/repositories/customer.repository.js +7 -1
- package/dist/crud/relations/fixtures/repositories/customer.repository.js.map +1 -1
- package/dist/crud/relations/fixtures/repositories/index.d.ts +6 -1
- package/dist/crud/relations/fixtures/repositories/index.js +6 -1
- package/dist/crud/relations/fixtures/repositories/index.js.map +1 -1
- package/dist/crud/relations/fixtures/repositories/payment-method.repository.d.ts +77 -0
- package/dist/crud/relations/fixtures/repositories/payment-method.repository.js +45 -0
- package/dist/crud/relations/fixtures/repositories/payment-method.repository.js.map +1 -0
- package/dist/crud/relations/fixtures/repositories/promotion.repository.d.ts +49 -0
- package/dist/crud/relations/fixtures/repositories/promotion.repository.js +25 -0
- package/dist/crud/relations/fixtures/repositories/promotion.repository.js.map +1 -0
- package/dist/crud/relations/fixtures/repositories/supplier.repository.d.ts +28 -0
- package/dist/crud/relations/fixtures/repositories/supplier.repository.js +21 -0
- package/dist/crud/relations/fixtures/repositories/supplier.repository.js.map +1 -0
- package/dist/crud/relations/helpers.d.ts +9 -1
- package/dist/crud/relations/helpers.js +85 -10
- package/dist/crud/relations/helpers.js.map +1 -1
- package/dist/helpers.repository-tests.d.ts +1 -1
- package/dist/helpers.repository-tests.js.map +1 -1
- package/package.json +12 -12
- package/src/crud/relations/acceptance/belongs-to.inclusion-resolver.polymorphic.relation.acceptance.ts +221 -0
- package/src/crud/relations/acceptance/belongs-to.polymorphic.relation.acceptance.ts +88 -0
- package/src/crud/relations/acceptance/has-many-through-inclusion-resolver.polymorphic.acceptance.ts +255 -0
- package/src/crud/relations/acceptance/has-many-through.relation.polymorphic.acceptance.ts +494 -0
- package/src/crud/relations/acceptance/has-one.inclusion-resolver.polymorphic.acceptance.ts +208 -0
- package/src/crud/relations/acceptance/has-one.relation.polymorphic.acceptance.ts +328 -0
- package/src/crud/relations/fixtures/models/contact.model.ts +56 -0
- package/src/crud/relations/fixtures/models/customer-promotion-link.model.ts +52 -0
- package/src/crud/relations/fixtures/models/customer.model.ts +39 -9
- package/src/crud/relations/fixtures/models/index.ts +6 -0
- package/src/crud/relations/fixtures/models/payment-method.model.ts +118 -0
- package/src/crud/relations/fixtures/models/promotion.model.ts +67 -0
- package/src/crud/relations/fixtures/models/stakeholder.model.ts +33 -0
- package/src/crud/relations/fixtures/models/supplier.model.ts +35 -0
- package/src/crud/relations/fixtures/repositories/contact.repository.ts +44 -0
- package/src/crud/relations/fixtures/repositories/customer-promotion-link.repository.ts +20 -0
- package/src/crud/relations/fixtures/repositories/customer.repository.ts +47 -0
- package/src/crud/relations/fixtures/repositories/index.ts +6 -1
- package/src/crud/relations/fixtures/repositories/payment-method.repository.ts +118 -0
- package/src/crud/relations/fixtures/repositories/promotion.repository.ts +37 -0
- package/src/crud/relations/fixtures/repositories/supplier.repository.ts +40 -0
- package/src/crud/relations/helpers.ts +200 -30
- package/src/helpers.repository-tests.ts +1 -1
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright IBM Corp. 2019,2020. All Rights Reserved.
|
|
3
|
+
// Node module: @loopback/repository-tests
|
|
4
|
+
// This file is licensed under the MIT License.
|
|
5
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.belongsToInclusionResolverPolymorphicAcceptance = void 0;
|
|
8
|
+
const testlab_1 = require("@loopback/testlab");
|
|
9
|
+
const helpers_repository_tests_1 = require("../../../helpers.repository-tests");
|
|
10
|
+
const models_1 = require("../fixtures/models");
|
|
11
|
+
const helpers_1 = require("../helpers");
|
|
12
|
+
function belongsToInclusionResolverPolymorphicAcceptance(dataSourceOptions, repositoryClass, features) {
|
|
13
|
+
(0, testlab_1.skipIf)(!features.supportsInclusionResolvers, describe, 'BelongsTo inclusion resolvers - polymorphic - acceptance', suite);
|
|
14
|
+
function suite() {
|
|
15
|
+
before(helpers_repository_tests_1.deleteAllModelsInDefaultDataSource);
|
|
16
|
+
let customerRepo;
|
|
17
|
+
let supplierRepo;
|
|
18
|
+
let contactRepo;
|
|
19
|
+
before((0, helpers_repository_tests_1.withCrudCtx)(async function setupRepository(ctx) {
|
|
20
|
+
// this helper should create the inclusion resolvers and also
|
|
21
|
+
// register inclusion resolvers for us
|
|
22
|
+
({ customerRepo, supplierRepo, contactRepo } = (0, helpers_1.givenBoundCrudRepositories)(ctx.dataSource, repositoryClass, features));
|
|
23
|
+
(0, testlab_1.expect)(customerRepo.contact.inclusionResolver).to.be.Function();
|
|
24
|
+
(0, testlab_1.expect)(supplierRepo.contact.inclusionResolver).to.be.Function();
|
|
25
|
+
(0, testlab_1.expect)(contactRepo.stakeholder.inclusionResolver).to.be.Function();
|
|
26
|
+
await ctx.dataSource.automigrate([
|
|
27
|
+
models_1.Customer.name,
|
|
28
|
+
models_1.Supplier.name,
|
|
29
|
+
models_1.Contact.name,
|
|
30
|
+
]);
|
|
31
|
+
}));
|
|
32
|
+
beforeEach(async () => {
|
|
33
|
+
await customerRepo.deleteAll();
|
|
34
|
+
await supplierRepo.deleteAll();
|
|
35
|
+
await contactRepo.deleteAll();
|
|
36
|
+
});
|
|
37
|
+
it('throws an error if it tries to query nonexistent relation names', async () => {
|
|
38
|
+
const customer = await customerRepo.create({ name: 'customer' });
|
|
39
|
+
await contactRepo.create({
|
|
40
|
+
stakeholderId: customer.id,
|
|
41
|
+
});
|
|
42
|
+
await (0, testlab_1.expect)(contactRepo.find({ include: ['shipment'] })).to.be.rejectedWith(`Invalid "filter.include" entries: "shipment"`);
|
|
43
|
+
});
|
|
44
|
+
it('returns single model instance including single related instance', async () => {
|
|
45
|
+
const thor = await customerRepo.create({ name: 'Thor' });
|
|
46
|
+
const contact = await contactRepo.create({
|
|
47
|
+
stakeholderId: thor.id,
|
|
48
|
+
});
|
|
49
|
+
const result = await contactRepo.find({
|
|
50
|
+
include: ['stakeholder'],
|
|
51
|
+
});
|
|
52
|
+
const expected = {
|
|
53
|
+
...contact,
|
|
54
|
+
isShipped: features.emptyValue,
|
|
55
|
+
shipmentInfo: features.emptyValue,
|
|
56
|
+
stakeholder: {
|
|
57
|
+
...thor,
|
|
58
|
+
parentId: features.emptyValue,
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
(0, testlab_1.expect)((0, testlab_1.toJSON)(result)).to.deepEqual([(0, testlab_1.toJSON)(expected)]);
|
|
62
|
+
});
|
|
63
|
+
it('returns multiple model instances including related instances', async () => {
|
|
64
|
+
const thor = await customerRepo.create({
|
|
65
|
+
name: 'Thor',
|
|
66
|
+
paymentMethodType: 'CreditCard',
|
|
67
|
+
});
|
|
68
|
+
const odin = await supplierRepo.create({ name: 'Odin' });
|
|
69
|
+
const thorContact = await contactRepo.create({
|
|
70
|
+
stakeholderId: thor.id,
|
|
71
|
+
});
|
|
72
|
+
const odinContact = await contactRepo.create({
|
|
73
|
+
stakeholderId: odin.id,
|
|
74
|
+
stakeholderType: 'Supplier',
|
|
75
|
+
});
|
|
76
|
+
const result = await contactRepo.find({
|
|
77
|
+
include: ['stakeholder'],
|
|
78
|
+
});
|
|
79
|
+
const expected = [
|
|
80
|
+
{
|
|
81
|
+
...thorContact,
|
|
82
|
+
isShipped: features.emptyValue,
|
|
83
|
+
shipmentInfo: features.emptyValue,
|
|
84
|
+
stakeholder: {
|
|
85
|
+
...thor,
|
|
86
|
+
parentId: features.emptyValue,
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
...odinContact,
|
|
91
|
+
isShipped: features.emptyValue,
|
|
92
|
+
shipmentInfo: features.emptyValue,
|
|
93
|
+
stakeholder: {
|
|
94
|
+
...odin,
|
|
95
|
+
parentId: features.emptyValue,
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
];
|
|
99
|
+
(0, testlab_1.expect)((0, testlab_1.toJSON)(result)).to.deepEqual((0, testlab_1.toJSON)(expected));
|
|
100
|
+
});
|
|
101
|
+
it('returns a specified instance including its related model instances', async () => {
|
|
102
|
+
const thor = await customerRepo.create({ name: 'Thor' });
|
|
103
|
+
const odin = await supplierRepo.create({ name: 'Odin' });
|
|
104
|
+
const bella = await supplierRepo.create({ name: 'Bella' });
|
|
105
|
+
await contactRepo.create({
|
|
106
|
+
stakeholderId: thor.id,
|
|
107
|
+
});
|
|
108
|
+
await contactRepo.create({
|
|
109
|
+
stakeholderId: bella.id,
|
|
110
|
+
stakeholderType: 'Supplier',
|
|
111
|
+
});
|
|
112
|
+
const odinContact = await contactRepo.create({
|
|
113
|
+
stakeholderId: odin.id,
|
|
114
|
+
stakeholderType: 'Supplier',
|
|
115
|
+
});
|
|
116
|
+
const result = await contactRepo.findById(odinContact.id, {
|
|
117
|
+
include: ['stakeholder'],
|
|
118
|
+
});
|
|
119
|
+
const expected = {
|
|
120
|
+
...odinContact,
|
|
121
|
+
isShipped: features.emptyValue,
|
|
122
|
+
shipmentInfo: features.emptyValue,
|
|
123
|
+
stakeholder: {
|
|
124
|
+
...odin,
|
|
125
|
+
parentId: features.emptyValue,
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
(0, testlab_1.expect)((0, testlab_1.toJSON)(result)).to.deepEqual((0, testlab_1.toJSON)(expected));
|
|
129
|
+
});
|
|
130
|
+
it('queries entities with null foreign key', async () => {
|
|
131
|
+
const customer = await customerRepo.create({
|
|
132
|
+
name: 'Thor',
|
|
133
|
+
});
|
|
134
|
+
const contact1 = await contactRepo.create({
|
|
135
|
+
stakeholderId: customer.id,
|
|
136
|
+
});
|
|
137
|
+
const contact2 = await contactRepo.create({});
|
|
138
|
+
const expected = [
|
|
139
|
+
{
|
|
140
|
+
...contact1,
|
|
141
|
+
isShipped: features.emptyValue,
|
|
142
|
+
shipmentInfo: features.emptyValue,
|
|
143
|
+
stakeholder: {
|
|
144
|
+
...customer,
|
|
145
|
+
parentId: features.emptyValue,
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
...contact2,
|
|
150
|
+
stakeholderId: features.emptyValue,
|
|
151
|
+
isShipped: features.emptyValue,
|
|
152
|
+
shipmentInfo: features.emptyValue,
|
|
153
|
+
},
|
|
154
|
+
];
|
|
155
|
+
const result = await contactRepo.find({ include: ['stakeholder'] });
|
|
156
|
+
(0, testlab_1.expect)((0, testlab_1.toJSON)(result)).to.deepEqual((0, testlab_1.toJSON)(expected));
|
|
157
|
+
});
|
|
158
|
+
it('throws error if the target repository does not have the registered resolver', async () => {
|
|
159
|
+
const customer = await customerRepo.create({ name: 'customer' });
|
|
160
|
+
await contactRepo.create({
|
|
161
|
+
stakeholderId: customer.id,
|
|
162
|
+
});
|
|
163
|
+
// unregister the resolver
|
|
164
|
+
contactRepo.inclusionResolvers.delete('stakeholder');
|
|
165
|
+
await (0, testlab_1.expect)(contactRepo.find({ include: ['stakeholder'] })).to.be.rejectedWith(`Invalid "filter.include" entries: "stakeholder"`);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
exports.belongsToInclusionResolverPolymorphicAcceptance = belongsToInclusionResolverPolymorphicAcceptance;
|
|
170
|
+
//# sourceMappingURL=belongs-to.inclusion-resolver.polymorphic.relation.acceptance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"belongs-to.inclusion-resolver.polymorphic.relation.acceptance.js","sourceRoot":"","sources":["../../../../src/crud/relations/acceptance/belongs-to.inclusion-resolver.polymorphic.relation.acceptance.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,0CAA0C;AAC1C,+CAA+C;AAC/C,gEAAgE;;;AAEhE,+CAAyD;AAQzD,gFAG2C;AAC3C,+CAO4B;AAC5B,wCAAsD;AAEtD,SAAgB,+CAA+C,CAC7D,iBAAoC,EACpC,eAAmC,EACnC,QAAsB;IAEtB,IAAA,gBAAM,EACJ,CAAC,QAAQ,CAAC,0BAA0B,EACpC,QAAQ,EACR,0DAA0D,EAC1D,KAAK,CACN,CAAC;IACF,SAAS,KAAK;QACZ,MAAM,CAAC,6DAAkC,CAAC,CAAC;QAC3C,IAAI,YAAgC,CAAC;QACrC,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strict";
|
|
2
|
+
// Copyright IBM Corp. 2019,2020. All Rights Reserved.
|
|
3
|
+
// Node module: @loopback/repository-tests
|
|
4
|
+
// This file is licensed under the MIT License.
|
|
5
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.belongsToRelationPolymorphicAcceptance = void 0;
|
|
8
|
+
const testlab_1 = require("@loopback/testlab");
|
|
9
|
+
const helpers_repository_tests_1 = require("../../../helpers.repository-tests");
|
|
10
|
+
const models_1 = require("../fixtures/models");
|
|
11
|
+
const helpers_1 = require("../helpers");
|
|
12
|
+
function belongsToRelationPolymorphicAcceptance(dataSourceOptions, repositoryClass, features) {
|
|
13
|
+
describe('BelongsTo relation (acceptance)', () => {
|
|
14
|
+
before(helpers_repository_tests_1.deleteAllModelsInDefaultDataSource);
|
|
15
|
+
let customerRepo;
|
|
16
|
+
let supplierRepo;
|
|
17
|
+
let contactRepo;
|
|
18
|
+
before((0, helpers_repository_tests_1.withCrudCtx)(async function setupRepository(ctx) {
|
|
19
|
+
({ customerRepo, supplierRepo, contactRepo } = (0, helpers_1.givenBoundCrudRepositories)(ctx.dataSource, repositoryClass, features));
|
|
20
|
+
const models = [models_1.Customer, models_1.Supplier, models_1.Contact];
|
|
21
|
+
await ctx.dataSource.automigrate(models.map(m => m.name));
|
|
22
|
+
}));
|
|
23
|
+
beforeEach(async () => {
|
|
24
|
+
await contactRepo.deleteAll();
|
|
25
|
+
});
|
|
26
|
+
it('can find customer from contact', async () => {
|
|
27
|
+
const customer = await customerRepo.create({
|
|
28
|
+
name: 'McForder customer',
|
|
29
|
+
});
|
|
30
|
+
const contact = await contactRepo.create({
|
|
31
|
+
stakeholderId: customer.id,
|
|
32
|
+
stakeholderType: 'Customer',
|
|
33
|
+
});
|
|
34
|
+
const result = await contactRepo.stakeholder(contact.id, 'Customer');
|
|
35
|
+
// adding parentId to customer so MySQL doesn't complain about null vs
|
|
36
|
+
// undefined
|
|
37
|
+
(0, testlab_1.expect)((0, testlab_1.toJSON)(result)).to.deepEqual((0, testlab_1.toJSON)({ ...customer, parentId: features.emptyValue }));
|
|
38
|
+
});
|
|
39
|
+
it('can find supplier from contact', async () => {
|
|
40
|
+
const supplier = await supplierRepo.create({
|
|
41
|
+
name: 'McForder supplier',
|
|
42
|
+
});
|
|
43
|
+
const contact = await contactRepo.create({
|
|
44
|
+
stakeholderId: supplier.id,
|
|
45
|
+
stakeholderType: 'Supplier',
|
|
46
|
+
});
|
|
47
|
+
const result = await contactRepo.stakeholder(contact.id, 'Supplier');
|
|
48
|
+
// adding parentId to customer so MySQL doesn't complain about null vs
|
|
49
|
+
// undefined
|
|
50
|
+
(0, testlab_1.expect)((0, testlab_1.toJSON)(result)).to.deepEqual((0, testlab_1.toJSON)({ ...supplier, parentId: features.emptyValue }));
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
exports.belongsToRelationPolymorphicAcceptance = belongsToRelationPolymorphicAcceptance;
|
|
55
|
+
//# sourceMappingURL=belongs-to.polymorphic.relation.acceptance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"belongs-to.polymorphic.relation.acceptance.js","sourceRoot":"","sources":["../../../../src/crud/relations/acceptance/belongs-to.polymorphic.relation.acceptance.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,0CAA0C;AAC1C,+CAA+C;AAC/C,gEAAgE;;;AAEhE,+CAAiD;AACjD,gFAG2C;AAO3C,+CAO4B;AAC5B,wCAAsD;AAEtD,SAAgB,sCAAsC,CACpD,iBAAoC,EACpC,eAAmC,EACnC,QAAsB;IAEtB,QAAQ,CAAC,iCAAiC,EAAE,GAAG,EAAE;QAC/C,MAAM,CAAC,6DAAkC,CAAC,CAAC;QAE3C,IAAI,YAAgC,CAAC;QACrC,IAAI,YAAgC,CAAC;QACrC,IAAI,WAA8B,CAAC;QAEnC,MAAM,CACJ,IAAA,sCAAW,EAAC,KAAK,U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MAAM,CAAC;gBACzC,IAAI,EAAE,mBAAmB;aAC1B,CAAC,CAAC;YACH,MAAM,OAAO,GAAG,MAAM,WAAW,CAAC,MAAM,CAAC;gBACvC,aAAa,EAAE,QAAQ,CAAC,EAAE;gBAC1B,eAAe,EAAE,UAAU;aAC5B,CAAC,CAAC;YAEH,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,EAAE,UAAU,CAAC,CAAC;YACrE,sEAAsE;YACtE,YAAY;YACZ,IAAA,gBAAM,EAAC,IAAA,gBAAM,EAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,CACjC,IAAA,gBAAM,EAAC,EAAC,GAAG,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,UAAU,EAAC,CAAC,CACrD,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AA7DD,wFA6DC"}
|
package/dist/crud/relations/acceptance/has-many-through-inclusion-resolver.polymorphic.acceptance.js
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright IBM Corp. 2020. All Rights Reserved.
|
|
3
|
+
// Node module: @loopback/repository-tests
|
|
4
|
+
// This file is licensed under the MIT License.
|
|
5
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.hasManyThroughInclusionResolverPolymorphicAcceptance = void 0;
|
|
8
|
+
const testlab_1 = require("@loopback/testlab");
|
|
9
|
+
const helpers_repository_tests_1 = require("../../../helpers.repository-tests");
|
|
10
|
+
const models_1 = require("../fixtures/models");
|
|
11
|
+
const helpers_1 = require("../helpers");
|
|
12
|
+
function hasManyThroughInclusionResolverPolymorphicAcceptance(dataSourceOptions, repositoryClass, features) {
|
|
13
|
+
(0, testlab_1.skipIf)(!features.supportsInclusionResolvers, describe, 'HasManyThrough inclusion resolvers - polymorphic - acceptance', suite);
|
|
14
|
+
function suite() {
|
|
15
|
+
describe('HasManyThrough inclusion resolver', () => {
|
|
16
|
+
before(helpers_repository_tests_1.deleteAllModelsInDefaultDataSource);
|
|
17
|
+
let customerRepo;
|
|
18
|
+
let freeDeliveryRepo;
|
|
19
|
+
let halfPriceRepo;
|
|
20
|
+
let customerPromotionLinkRepo;
|
|
21
|
+
before((0, helpers_repository_tests_1.withCrudCtx)(async function setupRepository(ctx) {
|
|
22
|
+
// this helper should create the inclusion resolvers and also
|
|
23
|
+
// register inclusion resolvers for us
|
|
24
|
+
({
|
|
25
|
+
customerRepo,
|
|
26
|
+
freeDeliveryRepo,
|
|
27
|
+
halfPriceRepo,
|
|
28
|
+
customerPromotionLinkRepo,
|
|
29
|
+
} = (0, helpers_1.givenBoundCrudRepositories)(ctx.dataSource, repositoryClass, features));
|
|
30
|
+
(0, testlab_1.expect)(customerRepo.promotions.inclusionResolver).to.be.Function();
|
|
31
|
+
await ctx.dataSource.automigrate([
|
|
32
|
+
models_1.Customer.name,
|
|
33
|
+
models_1.FreeDelivery.name,
|
|
34
|
+
models_1.HalfPrice.name,
|
|
35
|
+
models_1.CustomerPromotionLink.name,
|
|
36
|
+
]);
|
|
37
|
+
}));
|
|
38
|
+
beforeEach(async () => {
|
|
39
|
+
await customerRepo.deleteAll();
|
|
40
|
+
await freeDeliveryRepo.deleteAll();
|
|
41
|
+
await halfPriceRepo.deleteAll();
|
|
42
|
+
await customerPromotionLinkRepo.deleteAll();
|
|
43
|
+
});
|
|
44
|
+
it('throws an error if tries to query nonexistent relation names', async () => {
|
|
45
|
+
const customer = await customerRepo.create({ name: 'customer' });
|
|
46
|
+
await customerRepo
|
|
47
|
+
.promotions(customer.id)
|
|
48
|
+
.create({ description: 'crown' }, { polymorphicType: 'HalfPrice' });
|
|
49
|
+
await (0, testlab_1.expect)(customerRepo.find({ include: ['crown'] })).to.be.rejectedWith(`Invalid "filter.include" entries: "crown"`);
|
|
50
|
+
});
|
|
51
|
+
it('returns single model instance including single related instance', async () => {
|
|
52
|
+
const zelda = await customerRepo.create({ name: 'Zelda' });
|
|
53
|
+
const freeDelivery = await customerRepo.promotions(zelda.id).create({ description: 'crown' }, {
|
|
54
|
+
throughData: { promotiontype: 'FreeDelivery' },
|
|
55
|
+
polymorphicType: 'FreeDelivery',
|
|
56
|
+
});
|
|
57
|
+
const result = await customerRepo.find({
|
|
58
|
+
include: ['promotions'],
|
|
59
|
+
});
|
|
60
|
+
(0, testlab_1.expect)((0, testlab_1.toJSON)(result)).to.deepEqual([
|
|
61
|
+
(0, testlab_1.toJSON)({
|
|
62
|
+
...zelda,
|
|
63
|
+
parentId: features.emptyValue,
|
|
64
|
+
promotions: [freeDelivery],
|
|
65
|
+
}),
|
|
66
|
+
]);
|
|
67
|
+
});
|
|
68
|
+
it('returns multiple model instances including related instances', async () => {
|
|
69
|
+
const link = await customerRepo.create({ name: 'Link' });
|
|
70
|
+
const halfPrice = await customerRepo.promotions(link.id).create({ description: 'halfPrice' }, {
|
|
71
|
+
throughData: { promotiontype: 'HalfPrice' },
|
|
72
|
+
polymorphicType: 'HalfPrice',
|
|
73
|
+
});
|
|
74
|
+
const freeDelivery = await customerRepo.promotions(link.id).create({ description: 'freeDelivery' }, {
|
|
75
|
+
throughData: { promotiontype: 'FreeDelivery' },
|
|
76
|
+
polymorphicType: 'FreeDelivery',
|
|
77
|
+
});
|
|
78
|
+
const freeDelivery2 = await customerRepo.promotions(link.id).create({ description: 'freeDelivery 2' }, {
|
|
79
|
+
throughData: { promotiontype: 'FreeDelivery' },
|
|
80
|
+
polymorphicType: 'FreeDelivery',
|
|
81
|
+
});
|
|
82
|
+
const result = await customerRepo.find({
|
|
83
|
+
include: ['promotions'],
|
|
84
|
+
});
|
|
85
|
+
const expected = [
|
|
86
|
+
{
|
|
87
|
+
...link,
|
|
88
|
+
parentId: features.emptyValue,
|
|
89
|
+
promotions: [halfPrice, freeDelivery, freeDelivery2],
|
|
90
|
+
},
|
|
91
|
+
];
|
|
92
|
+
(0, testlab_1.expect)((0, testlab_1.toJSON)(result)).to.deepEqual((0, testlab_1.toJSON)(expected));
|
|
93
|
+
});
|
|
94
|
+
it('returns a specified instance including its related model instances', async () => {
|
|
95
|
+
const link = await customerRepo.create({ name: 'Link' });
|
|
96
|
+
const zelda = await customerRepo.create({ name: 'Zelda' });
|
|
97
|
+
await customerRepo.promotions(link.id).create({ description: 'crown' }, {
|
|
98
|
+
throughData: { promotiontype: 'HalfPrice' },
|
|
99
|
+
polymorphicType: 'HalfPrice',
|
|
100
|
+
});
|
|
101
|
+
const zeldaPromotion1 = await customerRepo.promotions(zelda.id).create({ description: 'shield' }, {
|
|
102
|
+
throughData: { promotiontype: 'FreeDelivery' },
|
|
103
|
+
polymorphicType: 'FreeDelivery',
|
|
104
|
+
});
|
|
105
|
+
const zeldaPromotion2 = await customerRepo.promotions(zelda.id).create({ description: 'green hat' }, {
|
|
106
|
+
throughData: { promotiontype: 'FreeDelivery' },
|
|
107
|
+
polymorphicType: 'FreeDelivery',
|
|
108
|
+
});
|
|
109
|
+
const result = await customerRepo.findById(zelda.id, {
|
|
110
|
+
include: ['promotions'],
|
|
111
|
+
});
|
|
112
|
+
const expected = {
|
|
113
|
+
...zelda,
|
|
114
|
+
parentId: features.emptyValue,
|
|
115
|
+
promotions: [zeldaPromotion1, zeldaPromotion2],
|
|
116
|
+
};
|
|
117
|
+
(0, testlab_1.expect)((0, testlab_1.toJSON)(result)).to.deepEqual((0, testlab_1.toJSON)(expected));
|
|
118
|
+
});
|
|
119
|
+
it('honours field scope when returning a model', async () => {
|
|
120
|
+
const link = await customerRepo.create({ name: 'Link' });
|
|
121
|
+
const zelda = await customerRepo.create({ name: 'Zelda' });
|
|
122
|
+
const sword = await customerRepo.promotions(link.id).create({ description: 'master sword' }, {
|
|
123
|
+
throughData: { promotiontype: 'HalfPrice' },
|
|
124
|
+
polymorphicType: 'HalfPrice',
|
|
125
|
+
});
|
|
126
|
+
const shield = await customerRepo.promotions(zelda.id).create({ description: 'shield' }, {
|
|
127
|
+
throughData: { promotiontype: 'FreeDelivery' },
|
|
128
|
+
polymorphicType: 'FreeDelivery',
|
|
129
|
+
});
|
|
130
|
+
const hat = await customerRepo.promotions(zelda.id).create({ description: 'hat' }, {
|
|
131
|
+
throughData: { promotiontype: 'HalfPrice' },
|
|
132
|
+
polymorphicType: 'HalfPrice',
|
|
133
|
+
});
|
|
134
|
+
const result = await customerRepo.find({
|
|
135
|
+
include: [{ relation: 'promotions', scope: { fields: { id: false } } }],
|
|
136
|
+
});
|
|
137
|
+
const expected = [
|
|
138
|
+
{
|
|
139
|
+
...link,
|
|
140
|
+
parentId: features.emptyValue,
|
|
141
|
+
promotions: [{ description: sword.description }],
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
...zelda,
|
|
145
|
+
parentId: features.emptyValue,
|
|
146
|
+
promotions: [
|
|
147
|
+
{ description: shield.description },
|
|
148
|
+
{ description: hat.description },
|
|
149
|
+
],
|
|
150
|
+
},
|
|
151
|
+
];
|
|
152
|
+
(0, testlab_1.expect)((0, testlab_1.toJSON)(result)).to.deepEqual((0, testlab_1.toJSON)(expected));
|
|
153
|
+
});
|
|
154
|
+
it('honours limit scope when returning a model', async () => {
|
|
155
|
+
const link = await customerRepo.create({ name: 'Link' });
|
|
156
|
+
await customerRepo
|
|
157
|
+
.cartItems(link.id)
|
|
158
|
+
.create({ description: 'master sword' });
|
|
159
|
+
await customerRepo.cartItems(link.id).create({ description: 'shield' });
|
|
160
|
+
const result = await customerRepo.find({
|
|
161
|
+
include: [{ relation: 'cartItems', scope: { limit: 1 } }],
|
|
162
|
+
});
|
|
163
|
+
(0, testlab_1.expect)(result.length).to.eql(1);
|
|
164
|
+
(0, testlab_1.expect)(result[0].cartItems.length).to.eql(1);
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
exports.hasManyThroughInclusionResolverPolymorphicAcceptance = hasManyThroughInclusionResolverPolymorphicAcceptance;
|
|
170
|
+
//# sourceMappingURL=has-many-through-inclusion-resolver.polymorphic.acceptance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"has-many-through-inclusion-resolver.polymorphic.acceptance.js","sourceRoot":"","sources":["../../../../src/crud/relations/acceptance/has-many-through-inclusion-resolver.polymorphic.acceptance.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,0CAA0C;AAC1C,+CAA+C;AAC/C,gEAAgE;;;AAEhE,+CAAyD;AAQzD,gFAG2C;AAC3C,+CAS4B;AAC5B,wCAAsD;AAEtD,SAAgB,oDAAoD,CAClE,iBAAoC,EACpC,eAAmC,EACnC,QAAsB;IAEtB,IAAA,gBAAM,EACJ,CAAC,QAAQ,CAAC,0BAA0B,EACpC,QAAQ,EACR,+DAA+D,EAC/D,KAAK,CACN,CAAC;IACF,SAAS,KAAK;QACZ,QAAQ,CAAC,mCAAmC,EAAE,GAAG,EAAE;YACjD,MAAM,CAAC,6DAAkC,CAAC,CAAC;YAC3C,IAAI,YAAgC,CAAC;YACrC,IAAI,gBAAwC,CAAC;YAC7C,IAAI,aAAkC,CAAC;YACvC,IAAI,yBAA0D,CAAC;YAE/D,MAAM,CACJ,IAAA,sCAAW,EAAC,KAAK,UAAU,eAAe,CAAC,GAAoB;gBAC7D,6DAA6D;gBAC7D,sCAAsC;gBACtC,CAAC;oBACC,YAAY;oBACZ,gBAAgB;oBAChB,aAAa;oBACb,yBAAyB;iBAC1B,GAAG,IAAA,oCAA0B,EAC5B,GAAG,CAAC,UAAU,EACd,eAAe,EACf,QAAQ,CACT,CAAC,CAAC;gBACH,IAAA,gBAAM,EAAC,YAAY,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC;gBAEnE,MAAM,GAAG,CAAC,UAAU,CAAC,WAAW,CAAC;oBAC/B,iBAAQ,CAAC,IAAI;oBACb,qBAAY,CAAC,IAAI;oBACjB,kBAAS,CAAC,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