@@ -187,84 +187,86 @@ export function hasManyInclusionResolverAcceptance(
187
187
expect ( toJSON ( result ) ) . to . deepEqual ( toJSON ( expected ) ) ;
188
188
} ) ;
189
189
190
- describe ( 'checks save() and replaceById()' , ( ) => {
191
- /* istanbul ignore next */
192
- ( features . hasRevisionToken ? it . skip : it ) (
193
- 'skips the tests for Cloudant as it needs the token' ,
194
- async ( ) => {
195
- it ( 'returns inclusions after running save() operation' , async ( ) => {
196
- // this shows save() works well with func ensurePersistable and ObjectId
197
- const thor = await customerRepo . create ( { name : 'Thor' } ) ;
198
- const odin = await customerRepo . create ( { name : 'Odin' } ) ;
199
-
200
- const thorOrder = await orderRepo . create ( {
201
- customerId : thor . id ,
202
- description : 'Pizza' ,
203
- } ) ;
204
-
205
- const pizza = await orderRepo . findById ( thorOrder . id ) ;
206
- pizza . customerId = odin . id ;
207
-
208
- await orderRepo . save ( pizza ) ;
209
- const odinPizza = await orderRepo . findById ( thorOrder . id ) ;
210
-
211
- const result = await customerRepo . findById ( odin . id , {
212
- include : [ { relation : 'orders' } ] ,
213
- } ) ;
214
- const expected = {
215
- ...odin ,
216
- parentId : features . emptyValue ,
217
- orders : [
218
- {
219
- ...odinPizza ,
220
- isShipped : features . emptyValue ,
221
- // eslint-disable-next-line @typescript-eslint/camelcase
222
- shipment_id : features . emptyValue ,
223
- } ,
224
- ] ,
225
- } ;
226
- expect ( toJSON ( result ) ) . to . containEql ( toJSON ( expected ) ) ;
227
- } ) ;
228
-
229
- it ( 'returns inclusions after running replaceById() operation' , async ( ) => {
230
- // this shows replaceById() works well with func ensurePersistable and ObjectId
231
- const thor = await customerRepo . create ( { name : 'Thor' } ) ;
232
- const odin = await customerRepo . create ( { name : 'Odin' } ) ;
233
-
234
- const thorOrder = await orderRepo . create ( {
235
- customerId : thor . id ,
236
- description : 'Pizza' ,
237
- } ) ;
238
-
239
- const pizza = await orderRepo . findById ( thorOrder . id ) ;
240
- pizza . customerId = odin . id ;
241
-
242
- await orderRepo . replaceById ( thorOrder . id , pizza ) ;
243
- const odinPizza = await orderRepo . findById ( thorOrder . id ) ;
244
-
245
- const result = await customerRepo . find ( {
246
- include : [ { relation : 'orders' } ] ,
247
- } ) ;
248
- const expected = [
249
- { ...thor , parentId : features . emptyValue } ,
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
+ const thor = await customerRepo . create ( { name : 'Thor' } ) ;
197
+ const odin = await customerRepo . create ( { name : 'Odin' } ) ;
198
+
199
+ const thorOrder = await orderRepo . create ( {
200
+ customerId : thor . id ,
201
+ description : 'Pizza' ,
202
+ } ) ;
203
+
204
+ const pizza = await orderRepo . findById ( thorOrder . id ) ;
205
+ pizza . customerId = odin . id ;
206
+
207
+ await orderRepo . save ( pizza ) ;
208
+ const odinPizza = await orderRepo . findById ( thorOrder . id ) ;
209
+
210
+ const result = await customerRepo . findById ( odin . id , {
211
+ include : [ { relation : 'orders' } ] ,
212
+ } ) ;
213
+ const expected = {
214
+ ...odin ,
215
+ parentId : features . emptyValue ,
216
+ orders : [
217
+ {
218
+ ...odinPizza ,
219
+ isShipped : features . emptyValue ,
220
+ // eslint-disable-next-line @typescript-eslint/camelcase
221
+ shipment_id : features . emptyValue ,
222
+ } ,
223
+ ] ,
224
+ } ;
225
+ expect ( toJSON ( result ) ) . to . containEql ( toJSON ( expected ) ) ;
226
+ } ,
227
+ ) ;
228
+
229
+ skipIf (
230
+ ! features . hasRevisionToken ,
231
+ it ,
232
+ 'returns inclusions after running replaceById() operation' ,
233
+ async ( ) => {
234
+ // this shows replaceById() works well with func ensurePersistable and ObjectId
235
+ const thor = await customerRepo . create ( { name : 'Thor' } ) ;
236
+ const odin = await customerRepo . create ( { name : 'Odin' } ) ;
237
+
238
+ const thorOrder = await orderRepo . create ( {
239
+ customerId : thor . id ,
240
+ description : 'Pizza' ,
241
+ } ) ;
242
+
243
+ const pizza = await orderRepo . findById ( thorOrder . id . toString ( ) ) ;
244
+ pizza . customerId = odin . id ;
245
+
246
+ await orderRepo . replaceById ( thorOrder . id , pizza ) ;
247
+ const odinPizza = await orderRepo . findById ( thorOrder . id ) ;
248
+
249
+ const result = await customerRepo . find ( {
250
+ include : [ { relation : 'orders' } ] ,
251
+ } ) ;
252
+ const expected = [
253
+ { ...thor , parentId : features . emptyValue } ,
254
+ {
255
+ ...odin ,
256
+ parentId : features . emptyValue ,
257
+ orders : [
250
258
{
251
- ...odin ,
252
- parentId : features . emptyValue ,
253
- orders : [
254
- {
255
- ...odinPizza ,
256
- isShipped : features . emptyValue ,
257
- // eslint-disable-next-line @typescript-eslint/camelcase
258
- shipment_id : features . emptyValue ,
259
- } ,
260
- ] ,
259
+ ...odinPizza ,
260
+ isShipped : features . emptyValue ,
261
+ // eslint-disable-next-line @typescript-eslint/camelcase
262
+ shipment_id : features . emptyValue ,
261
263
} ,
262
- ] ;
263
- expect ( toJSON ( result ) ) . to . deepEqual ( toJSON ( expected ) ) ;
264
- } ) ;
265
- } ,
266
- ) ;
267
- } ) ;
264
+ ] ,
265
+ } ,
266
+ ] ;
267
+ expect ( toJSON ( result ) ) . to . deepEqual ( toJSON ( expected ) ) ;
268
+ } ,
269
+ ) ;
268
270
269
271
it ( 'throws when navigational properties are present when updating model instance with save()' , async ( ) => {
270
272
// save() calls replaceById so the result will be the same for replaceById
0 commit comments