From 2729720b1580fe8f7067a8951b4f9c8640beba07 Mon Sep 17 00:00:00 2001 From: jannyHou Date: Thu, 28 Nov 2019 15:00:11 -0500 Subject: [PATCH] fix: modify customer model --- ...-inclusion-resolver.relation.acceptance.ts | 138 ++++++++---------- .../fixtures/models/customer.model.ts | 6 + 2 files changed, 70 insertions(+), 74 deletions(-) diff --git a/packages/repository-tests/src/crud/relations/acceptance/has-many-inclusion-resolver.relation.acceptance.ts b/packages/repository-tests/src/crud/relations/acceptance/has-many-inclusion-resolver.relation.acceptance.ts index 944786393724..4a7da9e51f3c 100644 --- a/packages/repository-tests/src/crud/relations/acceptance/has-many-inclusion-resolver.relation.acceptance.ts +++ b/packages/repository-tests/src/crud/relations/acceptance/has-many-inclusion-resolver.relation.acceptance.ts @@ -187,33 +187,66 @@ export function hasManyInclusionResolverAcceptance( expect(toJSON(result)).to.deepEqual(toJSON(expected)); }); - skipIf( - features.hasRevisionToken, - it, - 'returns inclusions after running save() operation', - async () => { - // this shows save() works well with func ensurePersistable and ObjectId - // the test skips for Cloudant as it needs the _rev property for replacement. - // see replace-by-id.suite.ts - const thor = await customerRepo.create({name: 'Thor'}); - const odin = await customerRepo.create({name: 'Odin'}); - - const thorOrder = await orderRepo.create({ - customerId: thor.id, - description: 'Pizza', - }); - - const pizza = await orderRepo.findById(thorOrder.id); - pizza.customerId = odin.id; - - await orderRepo.save(pizza); - const odinPizza = await orderRepo.findById(thorOrder.id); - - const result = await customerRepo.findById(odin.id, { - include: [{relation: 'orders'}], - }); - const expected = { - ...odin, + it('returns inclusions after running save() operation', async () => { + // this shows save() works well with func ensurePersistable and ObjectId + // the test skips for Cloudant as it needs the _rev property for replacement. + // see replace-by-id.suite.ts + const thor = await customerRepo.create({name: 'Thor'}); + const odin = await customerRepo.create({name: 'Odin'}); + + const thorOrder = await orderRepo.create({ + customerId: thor.id, + description: 'Pizza', + }); + + const pizza = await orderRepo.findById(thorOrder.id); + pizza.customerId = odin.id; + + await orderRepo.save(pizza); + const odinPizza = await orderRepo.findById(thorOrder.id); + + const result = await customerRepo.findById(odin.id, { + include: [{relation: 'orders'}], + }); + const expected = { + ...odin, + parentId: features.emptyValue, + orders: [ + { + ...odinPizza, + isShipped: features.emptyValue, + // eslint-disable-next-line @typescript-eslint/camelcase + shipment_id: features.emptyValue, + }, + ], + }; + expect(toJSON(result)).to.containEql(toJSON(expected)); + }); + + it('returns inclusions after running replaceById() operation', async () => { + // this shows replaceById() works well with func ensurePersistable and ObjectId + // the test skips for Cloudant as it needs the _rev property for replacement. + // see replace-by-id.suite.ts + const thor = await customerRepo.create({name: 'Thor'}); + + const thorOrder = await orderRepo.create({ + customerId: thor.id, + description: 'Pizza', + }); + + const pizza = await orderRepo.findById(thorOrder.id.toString()); + const reheatedPizza = {...pizza}; + reheatedPizza.description = 'Reheated pizza'; + + await orderRepo.replaceById(thorOrder.id, reheatedPizza); + const odinPizza = await orderRepo.findById(thorOrder.id); + + const result = await customerRepo.find({ + include: [{relation: 'orders'}], + }); + const expected = [ + { + ...thor, parentId: features.emptyValue, orders: [ { @@ -223,53 +256,10 @@ export function hasManyInclusionResolverAcceptance( shipment_id: features.emptyValue, }, ], - }; - expect(toJSON(result)).to.containEql(toJSON(expected)); - }, - ); - - skipIf( - features.hasRevisionToken, - it, - 'returns inclusions after running replaceById() operation', - async () => { - // this shows replaceById() works well with func ensurePersistable and ObjectId - // the test skips for Cloudant as it needs the _rev property for replacement. - // see replace-by-id.suite.ts - const thor = await customerRepo.create({name: 'Thor'}); - - const thorOrder = await orderRepo.create({ - customerId: thor.id, - description: 'Pizza', - }); - - const pizza = await orderRepo.findById(thorOrder.id.toString()); - const reheatedPizza = {...pizza}; - reheatedPizza.description = 'Reheated pizza'; - - await orderRepo.replaceById(thorOrder.id, reheatedPizza); - const odinPizza = await orderRepo.findById(thorOrder.id); - - const result = await customerRepo.find({ - include: [{relation: 'orders'}], - }); - const expected = [ - { - ...thor, - parentId: features.emptyValue, - orders: [ - { - ...odinPizza, - isShipped: features.emptyValue, - // eslint-disable-next-line @typescript-eslint/camelcase - shipment_id: features.emptyValue, - }, - ], - }, - ]; - expect(toJSON(result)).to.deepEqual(toJSON(expected)); - }, - ); + }, + ]; + expect(toJSON(result)).to.deepEqual(toJSON(expected)); + }); it('throws when navigational properties are present when updating model instance with save()', async () => { // save() calls replaceById so the result will be the same for replaceById diff --git a/packages/repository-tests/src/crud/relations/fixtures/models/customer.model.ts b/packages/repository-tests/src/crud/relations/fixtures/models/customer.model.ts index 6d189eb850ff..068a89a263f8 100644 --- a/packages/repository-tests/src/crud/relations/fixtures/models/customer.model.ts +++ b/packages/repository-tests/src/crud/relations/fixtures/models/customer.model.ts @@ -32,6 +32,12 @@ export class Customer extends Entity { }) name: string; + @property({ + type: 'string', + required: false, + }) + _rev?: string; + @hasMany(() => Order) orders: Order[];