@@ -205,20 +205,38 @@ describe('createReleaseOperationsStore', () => {
205
205
} ,
206
206
} )
207
207
208
- expect ( mockClient . create ) . toHaveBeenNthCalledWith (
209
- 1 ,
210
- {
211
- _id : `versions.${ revertReleaseId } .doc1` ,
208
+ expect ( mockClient . request ) . toHaveBeenNthCalledWith ( 1 , {
209
+ body : {
210
+ actions : [
211
+ {
212
+ actionType : 'sanity.action.release.create' ,
213
+ metadata : {
214
+ description : 'A reverted release' ,
215
+ releaseType : 'asap' ,
216
+ title : 'Revert Release' ,
217
+ } ,
218
+ releaseId : 'revert-release-id' ,
219
+ } ,
220
+ ] ,
212
221
} ,
213
- undefined ,
214
- )
215
- expect ( mockClient . create ) . toHaveBeenNthCalledWith (
216
- 2 ,
217
- {
218
- _id : `versions.${ revertReleaseId } .doc2` ,
222
+ method : 'POST' ,
223
+ uri : '/data/actions/test-dataset' ,
224
+ } )
225
+ expect ( mockClient . request ) . toHaveBeenNthCalledWith ( 2 , {
226
+ body : {
227
+ actions : [
228
+ {
229
+ actionType : 'sanity.action.document.version.create' ,
230
+ document : {
231
+ _id : 'versions.revert-release-id.doc1' ,
232
+ } ,
233
+ publishedId : 'doc1' ,
234
+ } ,
235
+ ] ,
219
236
} ,
220
- undefined ,
221
- )
237
+ method : 'POST' ,
238
+ uri : '/data/actions/test-dataset' ,
239
+ } )
222
240
223
241
expect ( mockClient . request ) . toHaveBeenCalledWith ( {
224
242
uri : '/data/actions/test-dataset' ,
@@ -256,8 +274,7 @@ describe('createReleaseOperationsStore', () => {
256
274
} ,
257
275
} )
258
276
259
- expect ( mockClient . create ) . toHaveBeenCalledTimes ( 2 )
260
- expect ( mockClient . request ) . toHaveBeenCalledTimes ( 1 )
277
+ expect ( mockClient . request ) . toHaveBeenCalledTimes ( 3 )
261
278
} )
262
279
263
280
it ( 'should fail if a document does not exist and no initial value is provided' , async ( ) => {
@@ -284,21 +301,55 @@ describe('createReleaseOperationsStore', () => {
284
301
)
285
302
286
303
expect ( result ) . toBeUndefined ( )
287
- expect ( mockClient . create ) . toHaveBeenCalledTimes ( 2 )
288
- expect ( mockClient . create ) . toHaveBeenNthCalledWith (
289
- 1 ,
290
- {
291
- _id : `versions.${ revertReleaseId } .doc1` ,
304
+ expect ( mockClient . request ) . toHaveBeenCalledTimes ( 3 )
305
+ expect ( mockClient . request ) . toHaveBeenNthCalledWith ( 1 , {
306
+ body : {
307
+ actions : [
308
+ {
309
+ actionType : 'sanity.action.release.create' ,
310
+ metadata : {
311
+ description : 'A reverted release' ,
312
+ releaseType : 'asap' ,
313
+ title : 'Revert Release' ,
314
+ } ,
315
+ releaseId : 'revert-release-id' ,
316
+ } ,
317
+ ] ,
292
318
} ,
293
- undefined ,
294
- )
295
- expect ( mockClient . create ) . toHaveBeenNthCalledWith (
296
- 2 ,
297
- {
298
- _id : `versions.${ revertReleaseId } .doc2` ,
319
+ method : 'POST' ,
320
+ uri : '/data/actions/test-dataset' ,
321
+ } )
322
+
323
+ expect ( mockClient . request ) . toHaveBeenNthCalledWith ( 2 , {
324
+ body : {
325
+ actions : [
326
+ {
327
+ actionType : 'sanity.action.document.version.create' ,
328
+ document : {
329
+ _id : 'versions.revert-release-id.doc1' ,
330
+ } ,
331
+ publishedId : 'doc1' ,
332
+ } ,
333
+ ] ,
299
334
} ,
300
- undefined ,
301
- )
335
+ method : 'POST' ,
336
+ uri : '/data/actions/test-dataset' ,
337
+ } )
338
+ expect ( mockClient . request ) . toHaveBeenNthCalledWith ( 3 , {
339
+ body : {
340
+ actions : [
341
+ {
342
+ actionType : 'sanity.action.document.version.create' ,
343
+ document : {
344
+ _id : 'versions.revert-release-id.doc2' ,
345
+ } ,
346
+ publishedId : 'doc2' ,
347
+ } ,
348
+ ] ,
349
+ } ,
350
+ method : 'POST' ,
351
+ uri : '/data/actions/test-dataset' ,
352
+ } )
302
353
} )
303
354
304
355
it ( 'should throw an error if creating the release fails' , async ( ) => {
@@ -314,14 +365,23 @@ describe('createReleaseOperationsStore', () => {
314
365
const store = createStore ( )
315
366
mockClient . getDocument . mockResolvedValue ( { _id : 'doc-id' , data : 'example' } )
316
367
await store . createVersion ( 'release-id' , 'doc-id' , { newData : 'value' } )
317
- expect ( mockClient . create ) . toHaveBeenCalledWith (
318
- {
319
- _id : `versions.release-id.doc-id` ,
320
- data : 'example' ,
321
- newData : 'value' ,
368
+ expect ( mockClient . request ) . toHaveBeenCalledWith ( {
369
+ body : {
370
+ actions : [
371
+ {
372
+ actionType : 'sanity.action.document.version.create' ,
373
+ document : {
374
+ _id : `versions.release-id.doc-id` ,
375
+ data : 'example' ,
376
+ newData : 'value' ,
377
+ } ,
378
+ publishedId : 'doc-id' ,
379
+ } ,
380
+ ] ,
322
381
} ,
323
- undefined ,
324
- )
382
+ method : 'POST' ,
383
+ uri : '/data/actions/test-dataset' ,
384
+ } )
325
385
} )
326
386
327
387
it ( 'should omit _weak from reference fields if _strengthenOnPublish is present when it creates a version of a document' , async ( ) => {
@@ -411,85 +471,94 @@ describe('createReleaseOperationsStore', () => {
411
471
412
472
await store . createVersion ( 'release-id' , 'doc-id' )
413
473
414
- expect ( mockClient . create ) . toHaveBeenCalledWith (
415
- {
416
- _id : `versions.release-id.doc-id` ,
417
- artist : {
418
- _ref : 'some-artist-id' ,
419
- _strengthenOnPublish : {
420
- template : {
421
- id : 'artist' ,
422
- } ,
423
- type : 'artist' ,
424
- } ,
425
- _type : 'reference' ,
426
- } ,
427
- expectedWeakReference : {
428
- _ref : 'expected-weak-reference' ,
429
- _type : 'reference' ,
430
- _weak : true ,
431
- _strengthenOnPublish : {
432
- template : {
433
- id : 'some-document' ,
434
- } ,
435
- type : 'some-document' ,
436
- weak : true ,
437
- } ,
438
- } ,
439
- plants : [
474
+ expect ( mockClient . request ) . toHaveBeenCalledWith ( {
475
+ body : {
476
+ actions : [
440
477
{
441
- _ref : 'some-plant-id' ,
442
- _strengthenOnPublish : {
443
- template : {
444
- id : 'plant' ,
478
+ actionType : 'sanity.action.document.version.create' ,
479
+ document : {
480
+ _id : `versions.release-id.doc-id` ,
481
+ artist : {
482
+ _ref : 'some-artist-id' ,
483
+ _strengthenOnPublish : {
484
+ template : {
485
+ id : 'artist' ,
486
+ } ,
487
+ type : 'artist' ,
488
+ } ,
489
+ _type : 'reference' ,
445
490
} ,
446
- type : 'plant' ,
447
- } ,
448
- _type : 'reference' ,
449
- } ,
450
- {
451
- _ref : 'some-plant-id' ,
452
- _strengthenOnPublish : {
453
- template : {
454
- id : 'plant' ,
491
+ expectedWeakReference : {
492
+ _ref : 'expected-weak-reference' ,
493
+ _type : 'reference' ,
494
+ _weak : true ,
495
+ _strengthenOnPublish : {
496
+ template : {
497
+ id : 'some-document' ,
498
+ } ,
499
+ type : 'some-document' ,
500
+ weak : true ,
501
+ } ,
455
502
} ,
456
- type : 'plant' ,
457
- } ,
458
- _type : 'reference' ,
459
- } ,
460
- ] ,
461
- stores : [
462
- {
463
- name : 'some-store' ,
464
- inventory : {
465
- products : [
503
+ plants : [
466
504
{
467
- _ref : 'some-product -id' ,
505
+ _ref : 'some-plant -id' ,
468
506
_strengthenOnPublish : {
469
507
template : {
470
- id : 'product ' ,
508
+ id : 'plant ' ,
471
509
} ,
472
- type : 'product ' ,
510
+ type : 'plant ' ,
473
511
} ,
474
512
_type : 'reference' ,
475
513
} ,
476
514
{
477
- _ref : 'some-product -id' ,
515
+ _ref : 'some-plant -id' ,
478
516
_strengthenOnPublish : {
479
517
template : {
480
- id : 'product ' ,
518
+ id : 'plant ' ,
481
519
} ,
482
- type : 'product ' ,
520
+ type : 'plant ' ,
483
521
} ,
484
522
_type : 'reference' ,
485
523
} ,
486
524
] ,
525
+ stores : [
526
+ {
527
+ name : 'some-store' ,
528
+ inventory : {
529
+ products : [
530
+ {
531
+ _ref : 'some-product-id' ,
532
+ _strengthenOnPublish : {
533
+ template : {
534
+ id : 'product' ,
535
+ } ,
536
+ type : 'product' ,
537
+ } ,
538
+ _type : 'reference' ,
539
+ } ,
540
+ {
541
+ _ref : 'some-product-id' ,
542
+ _strengthenOnPublish : {
543
+ template : {
544
+ id : 'product' ,
545
+ } ,
546
+ type : 'product' ,
547
+ } ,
548
+ _type : 'reference' ,
549
+ } ,
550
+ ] ,
551
+ } ,
552
+ } ,
553
+ ] ,
487
554
} ,
555
+ publishedId : 'doc-id' ,
488
556
} ,
489
557
] ,
490
558
} ,
491
- undefined ,
492
- )
559
+ method : 'POST' ,
560
+ uri : '/data/actions/test-dataset' ,
561
+ } )
493
562
} )
494
563
495
564
it ( 'should discard a version of a document' , async ( ) => {
@@ -501,8 +570,9 @@ describe('createReleaseOperationsStore', () => {
501
570
body : {
502
571
actions : [
503
572
{
504
- actionType : 'sanity.action.document.discard' ,
505
- draftId : 'versions.release-id.doc-id' ,
573
+ actionType : 'sanity.action.document.version.discard' ,
574
+ versionId : 'versions.release-id.doc-id' ,
575
+ purge : false ,
506
576
} ,
507
577
] ,
508
578
} ,
@@ -511,15 +581,15 @@ describe('createReleaseOperationsStore', () => {
511
581
512
582
it ( 'should unpublish a version of a document' , async ( ) => {
513
583
const store = createStore ( )
514
- await store . unpublishVersion ( 'doc-id' )
584
+ await store . unpublishVersion ( 'versions.release-id. doc-id' )
515
585
expect ( mockClient . request ) . toHaveBeenCalledWith ( {
516
586
uri : '/data/actions/test-dataset' ,
517
587
method : 'POST' ,
518
588
body : {
519
589
actions : [
520
590
{
521
591
actionType : 'sanity.action.document.version.unpublish' ,
522
- draftId : 'doc-id' ,
592
+ versionId : 'versions.release-id. doc-id' ,
523
593
publishedId : `doc-id` ,
524
594
} ,
525
595
] ,
0 commit comments