@@ -9,6 +9,7 @@ import feathersVuex from '../../src/index'
9
9
import { feathersRestClient as feathersClient } from '../fixtures/feathers-client'
10
10
import { clearModels } from '../../src/service-module/global-models'
11
11
import { Service as MemoryService } from 'feathers-memory'
12
+ import Vue from 'vue/dist/vue'
12
13
import Vuex from 'vuex'
13
14
import { makeStore } from '../test-utils'
14
15
import ObjectID from 'bson-objectid'
@@ -477,4 +478,68 @@ describe('Models - Temp Ids', function() {
477
478
assert ( response2 === thing , 'response2 is still thing' )
478
479
assert ( thing . description === 'Thing 3' , "thing got clone's new changes" )
479
480
} )
481
+
482
+ it ( 'find() getter does not return duplicates with temps: true' , async function ( ) {
483
+ const { makeServicePlugin, BaseModel } = feathersVuex ( feathersClient , {
484
+ idField : '_id' ,
485
+ serverAlias : 'temp-ids'
486
+ } )
487
+ class FooModel extends BaseModel {
488
+ public static modelName = 'FooModel'
489
+ public constructor ( data ?, options ?) {
490
+ super ( data , options )
491
+ }
492
+ }
493
+ const store = new Vuex . Store < RootState > ( {
494
+ plugins : [
495
+ makeServicePlugin ( {
496
+ Model : FooModel ,
497
+ service : feathersClient . service ( 'foos' ) ,
498
+ servicePath : 'foos'
499
+ } )
500
+ ]
501
+ } )
502
+
503
+ // Fake server call
504
+ feathersClient . service ( 'foos' ) . hooks ( {
505
+ before : {
506
+ create : [
507
+ context => {
508
+ context . result = { _id : 24 , ...context . data }
509
+ return context
510
+ }
511
+ ]
512
+ }
513
+ } )
514
+
515
+ // Create component with find() computed prop
516
+ const watchEvents = [ ]
517
+ new Vue ( {
518
+ template : `<div></div>` ,
519
+ computed : {
520
+ things ( ) {
521
+ return store . getters [ 'foos/find' ] ( {
522
+ query : { test : true } ,
523
+ temps : true
524
+ } ) . data
525
+ }
526
+ } ,
527
+ watch : {
528
+ things ( items ) {
529
+ watchEvents . push ( items )
530
+ }
531
+ }
532
+ } ) . $mount ( )
533
+
534
+ const item = new FooModel ( { test : true } )
535
+ await item . save ( )
536
+
537
+ assert ( watchEvents . length > 0 , 'watch fired at least once' )
538
+ watchEvents . forEach ( items => {
539
+ if ( items . length === 2 ) {
540
+ assert ( items [ 0 ] . _id !== items [ 1 ] . _id , 'no duplicate id' )
541
+ assert ( items [ 0 ] . __id !== items [ 1 ] . __id , 'no duplicate tempId' )
542
+ }
543
+ } )
544
+ } )
480
545
} )
0 commit comments