Skip to content

Commit 2729720

Browse files
committed
fix: modify customer model
1 parent 8e7bffe commit 2729720

File tree

2 files changed

+70
-74
lines changed

2 files changed

+70
-74
lines changed

packages/repository-tests/src/crud/relations/acceptance/has-many-inclusion-resolver.relation.acceptance.ts

+64-74
Original file line numberDiff line numberDiff line change
@@ -187,33 +187,66 @@ export function hasManyInclusionResolverAcceptance(
187187
expect(toJSON(result)).to.deepEqual(toJSON(expected));
188188
});
189189

190-
skipIf(
191-
features.hasRevisionToken,
192-
it,
193-
'returns inclusions after running save() operation',
194-
async () => {
195-
// this shows save() works well with func ensurePersistable and ObjectId
196-
// the test skips for Cloudant as it needs the _rev property for replacement.
197-
// see replace-by-id.suite.ts
198-
const thor = await customerRepo.create({name: 'Thor'});
199-
const odin = await customerRepo.create({name: 'Odin'});
200-
201-
const thorOrder = await orderRepo.create({
202-
customerId: thor.id,
203-
description: 'Pizza',
204-
});
205-
206-
const pizza = await orderRepo.findById(thorOrder.id);
207-
pizza.customerId = odin.id;
208-
209-
await orderRepo.save(pizza);
210-
const odinPizza = await orderRepo.findById(thorOrder.id);
211-
212-
const result = await customerRepo.findById(odin.id, {
213-
include: [{relation: 'orders'}],
214-
});
215-
const expected = {
216-
...odin,
190+
it('returns inclusions after running save() operation', async () => {
191+
// this shows save() works well with func ensurePersistable and ObjectId
192+
// the test skips for Cloudant as it needs the _rev property for replacement.
193+
// see replace-by-id.suite.ts
194+
const thor = await customerRepo.create({name: 'Thor'});
195+
const odin = await customerRepo.create({name: 'Odin'});
196+
197+
const thorOrder = await orderRepo.create({
198+
customerId: thor.id,
199+
description: 'Pizza',
200+
});
201+
202+
const pizza = await orderRepo.findById(thorOrder.id);
203+
pizza.customerId = odin.id;
204+
205+
await orderRepo.save(pizza);
206+
const odinPizza = await orderRepo.findById(thorOrder.id);
207+
208+
const result = await customerRepo.findById(odin.id, {
209+
include: [{relation: 'orders'}],
210+
});
211+
const expected = {
212+
...odin,
213+
parentId: features.emptyValue,
214+
orders: [
215+
{
216+
...odinPizza,
217+
isShipped: features.emptyValue,
218+
// eslint-disable-next-line @typescript-eslint/camelcase
219+
shipment_id: features.emptyValue,
220+
},
221+
],
222+
};
223+
expect(toJSON(result)).to.containEql(toJSON(expected));
224+
});
225+
226+
it('returns inclusions after running replaceById() operation', async () => {
227+
// this shows replaceById() works well with func ensurePersistable and ObjectId
228+
// the test skips for Cloudant as it needs the _rev property for replacement.
229+
// see replace-by-id.suite.ts
230+
const thor = await customerRepo.create({name: 'Thor'});
231+
232+
const thorOrder = await orderRepo.create({
233+
customerId: thor.id,
234+
description: 'Pizza',
235+
});
236+
237+
const pizza = await orderRepo.findById(thorOrder.id.toString());
238+
const reheatedPizza = {...pizza};
239+
reheatedPizza.description = 'Reheated pizza';
240+
241+
await orderRepo.replaceById(thorOrder.id, reheatedPizza);
242+
const odinPizza = await orderRepo.findById(thorOrder.id);
243+
244+
const result = await customerRepo.find({
245+
include: [{relation: 'orders'}],
246+
});
247+
const expected = [
248+
{
249+
...thor,
217250
parentId: features.emptyValue,
218251
orders: [
219252
{
@@ -223,53 +256,10 @@ export function hasManyInclusionResolverAcceptance(
223256
shipment_id: features.emptyValue,
224257
},
225258
],
226-
};
227-
expect(toJSON(result)).to.containEql(toJSON(expected));
228-
},
229-
);
230-
231-
skipIf(
232-
features.hasRevisionToken,
233-
it,
234-
'returns inclusions after running replaceById() operation',
235-
async () => {
236-
// this shows replaceById() works well with func ensurePersistable and ObjectId
237-
// the test skips for Cloudant as it needs the _rev property for replacement.
238-
// see replace-by-id.suite.ts
239-
const thor = await customerRepo.create({name: 'Thor'});
240-
241-
const thorOrder = await orderRepo.create({
242-
customerId: thor.id,
243-
description: 'Pizza',
244-
});
245-
246-
const pizza = await orderRepo.findById(thorOrder.id.toString());
247-
const reheatedPizza = {...pizza};
248-
reheatedPizza.description = 'Reheated pizza';
249-
250-
await orderRepo.replaceById(thorOrder.id, reheatedPizza);
251-
const odinPizza = await orderRepo.findById(thorOrder.id);
252-
253-
const result = await customerRepo.find({
254-
include: [{relation: 'orders'}],
255-
});
256-
const expected = [
257-
{
258-
...thor,
259-
parentId: features.emptyValue,
260-
orders: [
261-
{
262-
...odinPizza,
263-
isShipped: features.emptyValue,
264-
// eslint-disable-next-line @typescript-eslint/camelcase
265-
shipment_id: features.emptyValue,
266-
},
267-
],
268-
},
269-
];
270-
expect(toJSON(result)).to.deepEqual(toJSON(expected));
271-
},
272-
);
259+
},
260+
];
261+
expect(toJSON(result)).to.deepEqual(toJSON(expected));
262+
});
273263

274264
it('throws when navigational properties are present when updating model instance with save()', async () => {
275265
// save() calls replaceById so the result will be the same for replaceById

packages/repository-tests/src/crud/relations/fixtures/models/customer.model.ts

+6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ export class Customer extends Entity {
3232
})
3333
name: string;
3434

35+
@property({
36+
type: 'string',
37+
required: false,
38+
})
39+
_rev?: string;
40+
3541
@hasMany(() => Order)
3642
orders: Order[];
3743

0 commit comments

Comments
 (0)