@@ -352,4 +352,113 @@ describe('Models - Methods', function () {
352
352
353
353
assert ( json , 'got json' )
354
354
} )
355
+
356
+ it ( 'Model pending status sets/clears for create/update/patch/remove' , async function ( ) {
357
+ const { makeServicePlugin, BaseModel } = feathersVuex ( feathersClient , {
358
+ idField : '_id' ,
359
+ serverAlias : 'model-methods'
360
+ } )
361
+ class PendingThing extends BaseModel {
362
+ public static modelName = 'PendingThing'
363
+ public constructor ( data ?, options ?) {
364
+ super ( data , options )
365
+ }
366
+ }
367
+ const store = new Vuex . Store < RootState > ( {
368
+ plugins : [
369
+ makeServicePlugin ( {
370
+ Model : PendingThing ,
371
+ service : feathersClient . service ( 'methods-pending-things' )
372
+ } )
373
+ ]
374
+ } )
375
+
376
+ // Create instance
377
+ const thing = new PendingThing ( { description : 'pending test' } )
378
+ const clone = thing . clone ( )
379
+ assert ( ! ! thing . __id , "thing has a tempId" )
380
+ assert ( clone . __id === thing . __id , "clone has thing's tempId" )
381
+
382
+ // Manually set the result in a hook to simulate the server request.
383
+ feathersClient . service ( 'methods-pending-things' ) . hooks ( {
384
+ before : {
385
+ create : [
386
+ context => {
387
+ context . result = { _id : 42 , ...context . data }
388
+ // Check pending status
389
+ assert ( thing . isCreatePending === true , 'isCreatePending set' )
390
+ assert ( thing . isPending === true , 'isPending set' )
391
+ // Check clone's pending status
392
+ assert ( clone . isCreatePending === true , 'isCreatePending set on clone' )
393
+ assert ( clone . isPending === true , 'isPending set on clone' )
394
+ return context
395
+ }
396
+ ] ,
397
+ update : [
398
+ context => {
399
+ context . result = { ...context . data }
400
+ // Check pending status
401
+ assert ( thing . isUpdatePending === true , 'isUpdatePending set' )
402
+ assert ( thing . isPending === true , 'isPending set' )
403
+ // Check clone's pending status
404
+ assert ( clone . isUpdatePending === true , 'isUpdatePending set on clone' )
405
+ assert ( clone . isPending === true , 'isPending set on clone' )
406
+ return context
407
+ }
408
+ ] ,
409
+ patch : [
410
+ context => {
411
+ context . result = { ...context . data }
412
+ // Check pending status
413
+ assert ( thing . isPatchPending === true , 'isPatchPending set' )
414
+ assert ( thing . isPending === true , 'isPending set' )
415
+ // Check clone's pending status
416
+ assert ( clone . isPatchPending === true , 'isPatchPending set on clone' )
417
+ assert ( clone . isPending === true , 'isPending set on clone' )
418
+ return context
419
+ }
420
+ ] ,
421
+ remove : [
422
+ context => {
423
+ context . result = { ...context . data }
424
+ // Check pending status
425
+ assert ( thing . isRemovePending === true , 'isRemovePending set' )
426
+ assert ( thing . isPending === true , 'isPending set' )
427
+ // Check clone's pending status
428
+ assert ( clone . isRemovePending === true , 'isRemovePending set on clone' )
429
+ assert ( clone . isPending === true , 'isPending set on clone' )
430
+ return context
431
+ }
432
+ ]
433
+ }
434
+ } )
435
+
436
+ // Create and verify status
437
+ await thing . create ( )
438
+ assert ( thing . isCreatePending === false , 'isCreatePending cleared' )
439
+ assert ( thing . isPending === false , 'isPending cleared' )
440
+ assert ( clone . isCreatePending === false , 'isCreatePending cleared on clone' )
441
+ assert ( clone . isPending === false , 'isPending cleared on clone' )
442
+
443
+ // Update and verify status
444
+ await thing . update ( )
445
+ assert ( thing . isUpdatePending === false , 'isUpdatePending cleared' )
446
+ assert ( thing . isPending === false , 'isPending cleared' )
447
+ assert ( clone . isUpdatePending === false , 'isUpdatePending cleared on clone' )
448
+ assert ( clone . isPending === false , 'isPending cleared on clone' )
449
+
450
+ // Patch and verify status
451
+ await thing . patch ( )
452
+ assert ( thing . isPatchPending === false , 'isPatchPending cleared' )
453
+ assert ( thing . isPending === false , 'isPending cleared' )
454
+ assert ( clone . isPatchPending === false , 'isPatchPending cleared on clone' )
455
+ assert ( clone . isPending === false , 'isPending cleared on clone' )
456
+
457
+ // Remove and verify status
458
+ await thing . remove ( )
459
+ assert ( thing . isRemovePending === false , 'isRemovePending cleared' )
460
+ assert ( thing . isPending === false , 'isPending cleared' )
461
+ assert ( clone . isRemovePending === false , 'isRemovePending cleared on clone' )
462
+ assert ( clone . isPending === false , 'isPending cleared on clone' )
463
+ } )
355
464
} )
0 commit comments