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 c96c7639698b..32e05fbeefda 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,47 +187,100 @@ export function hasManyInclusionResolverAcceptance( expect(toJSON(result)).to.deepEqual(toJSON(expected)); }); - 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); + 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, + 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)); + }, + ); - const result = await customerRepo.findById(odin.id, { - include: [{relation: 'orders'}], - }); - const expected = { - ...odin, - parentId: features.emptyValue, - orders: [ + 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 odin = await customerRepo.create({name: 'Odin'}); + + const thorOrder = await orderRepo.create({ + customerId: thor.id, + description: 'Pizza', + }); + + const pizza = await orderRepo.findById(thorOrder.id.toString()); + pizza.customerId = odin.id; + // FIXME: [mongo] if pizza obj is converted to JSON obj, it would get an error + // because it tries to convert ObjectId to string type. + // should test with JSON obj once it's fixed. + + await orderRepo.replaceById(pizza.id, pizza); + const odinPizza = await orderRepo.findById(thorOrder.id); + + const result = await customerRepo.find({ + include: [{relation: 'orders'}], + }); + const expected = [ { - ...odinPizza, - isShipped: features.emptyValue, - // eslint-disable-next-line @typescript-eslint/camelcase - shipment_id: features.emptyValue, + ...thor, + parentId: features.emptyValue, }, - ], - }; - expect(toJSON(result)).to.containEql(toJSON(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.deepEqual(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 + it('returns inclusions after running updateById() operation', async () => { const thor = await customerRepo.create({name: 'Thor'}); + const odin = await customerRepo.create({name: 'Odin'}); const thorOrder = await orderRepo.create({ customerId: thor.id, @@ -235,17 +288,10 @@ export function hasManyInclusionResolverAcceptance( }); const pizza = await orderRepo.findById(thorOrder.id.toString()); - pizza.description = 'Reheated pizza'; + pizza.customerId = odin.id; const reheatedPizza = toJSON(pizza); - // coerce the id for mongodb connector to pass the id equality check - // in juggler's replaceById function - const coercedId = - typeof thorOrder.id === 'number' - ? thorOrder.id - : thorOrder.id.toString(); - - await orderRepo.replaceById(coercedId, reheatedPizza); + await orderRepo.updateById(pizza.id, reheatedPizza); const odinPizza = await orderRepo.findById(thorOrder.id); const result = await customerRepo.find({ @@ -255,6 +301,10 @@ export function hasManyInclusionResolverAcceptance( { ...thor, parentId: features.emptyValue, + }, + { + ...odin, + parentId: features.emptyValue, orders: [ { ...odinPizza, 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 068a89a263f8..6d189eb850ff 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,12 +32,6 @@ export class Customer extends Entity { }) name: string; - @property({ - type: 'string', - required: false, - }) - _rev?: string; - @hasMany(() => Order) orders: Order[];