@@ -187,65 +187,111 @@ export function hasManyInclusionResolverAcceptance(
187
187
expect ( toJSON ( result ) ) . to . deepEqual ( toJSON ( expected ) ) ;
188
188
} ) ;
189
189
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 ) ;
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 ,
217
+ parentId : features . emptyValue ,
218
+ orders : [
219
+ {
220
+ ...odinPizza ,
221
+ isShipped : features . emptyValue ,
222
+ // eslint-disable-next-line @typescript-eslint/camelcase
223
+ shipment_id : features . emptyValue ,
224
+ } ,
225
+ ] ,
226
+ } ;
227
+ expect ( toJSON ( result ) ) . to . containEql ( toJSON ( expected ) ) ;
228
+ } ,
229
+ ) ;
207
230
208
- const result = await customerRepo . findById ( odin . id , {
209
- include : [ { relation : 'orders' } ] ,
210
- } ) ;
211
- const expected = {
212
- ...odin ,
213
- parentId : features . emptyValue ,
214
- orders : [
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
+ const odin = await customerRepo . create ( { name : 'Odin' } ) ;
241
+
242
+ const thorOrder = await orderRepo . create ( {
243
+ customerId : thor . id ,
244
+ description : 'Pizza' ,
245
+ } ) ;
246
+
247
+ const pizza = await orderRepo . findById ( thorOrder . id . toString ( ) ) ;
248
+ pizza . customerId = odin . id ;
249
+ // FIXME: [mongo] if pizza obj is converted to JSON obj, it would get an error
250
+ // because it tries to convert ObjectId to string type.
251
+ // should test with JSON obj once it's fixed.
252
+
253
+ await orderRepo . replaceById ( pizza . id , pizza ) ;
254
+ const odinPizza = await orderRepo . findById ( thorOrder . id ) ;
255
+
256
+ const result = await customerRepo . find ( {
257
+ include : [ { relation : 'orders' } ] ,
258
+ } ) ;
259
+ const expected = [
215
260
{
216
- ...odinPizza ,
217
- isShipped : features . emptyValue ,
218
- // eslint-disable-next-line @typescript-eslint/camelcase
219
- shipment_id : features . emptyValue ,
261
+ ...thor ,
262
+ parentId : features . emptyValue ,
220
263
} ,
221
- ] ,
222
- } ;
223
- expect ( toJSON ( result ) ) . to . containEql ( toJSON ( expected ) ) ;
224
- } ) ;
264
+ {
265
+ ...odin ,
266
+ parentId : features . emptyValue ,
267
+ orders : [
268
+ {
269
+ ...odinPizza ,
270
+ isShipped : features . emptyValue ,
271
+ // eslint-disable-next-line @typescript-eslint/camelcase
272
+ shipment_id : features . emptyValue ,
273
+ } ,
274
+ ] ,
275
+ } ,
276
+ ] ;
277
+ expect ( toJSON ( result ) ) . to . deepEqual ( toJSON ( expected ) ) ;
278
+ } ,
279
+ ) ;
225
280
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
281
+ it ( 'returns inclusions after running updateById() operation' , async ( ) => {
230
282
const thor = await customerRepo . create ( { name : 'Thor' } ) ;
283
+ const odin = await customerRepo . create ( { name : 'Odin' } ) ;
231
284
232
285
const thorOrder = await orderRepo . create ( {
233
286
customerId : thor . id ,
234
287
description : 'Pizza' ,
235
288
} ) ;
236
289
237
290
const pizza = await orderRepo . findById ( thorOrder . id . toString ( ) ) ;
238
- pizza . description = 'Reheated pizza' ;
291
+ pizza . customerId = odin . id ;
239
292
const reheatedPizza = toJSON ( pizza ) ;
240
293
241
- // coerce the id for mongodb connector to pass the id equality check
242
- // in juggler's replaceById function
243
- const coercedId =
244
- typeof thorOrder . id === 'number'
245
- ? thorOrder . id
246
- : thorOrder . id . toString ( ) ;
247
-
248
- await orderRepo . replaceById ( coercedId , reheatedPizza ) ;
294
+ await orderRepo . updateById ( pizza . id , reheatedPizza ) ;
249
295
const odinPizza = await orderRepo . findById ( thorOrder . id ) ;
250
296
251
297
const result = await customerRepo . find ( {
@@ -255,6 +301,10 @@ export function hasManyInclusionResolverAcceptance(
255
301
{
256
302
...thor ,
257
303
parentId : features . emptyValue ,
304
+ } ,
305
+ {
306
+ ...odin ,
307
+ parentId : features . emptyValue ,
258
308
orders : [
259
309
{
260
310
...odinPizza ,
0 commit comments