@@ -191,6 +191,36 @@ describe('Service Module - Actions', () => {
191
191
192
192
actions . find
193
193
. call ( { $store : store } , { query : { $limit : 1 } } )
194
+ . then ( response => {
195
+ const returnedRecord = JSON . parse ( JSON . stringify ( response [ 0 ] ) )
196
+ assert ( response . length === 1 , 'only one record was returned' )
197
+ assert . deepEqual (
198
+ returnedRecord ,
199
+ { id : 0 , description : 'Do the first' , isComplete : false } ,
200
+ 'the first record was returned'
201
+ )
202
+ done ( )
203
+ } )
204
+ } )
205
+
206
+ it ( 'find with $select' , done => {
207
+ const { makeServicePlugin, Todo } = makeContext ( )
208
+ const store = new Vuex . Store < RootState > ( {
209
+ plugins : [
210
+ makeServicePlugin ( {
211
+ servicePath : 'my-todos' ,
212
+ Model : Todo ,
213
+ service : feathersClient . service ( 'my-todos' )
214
+ } )
215
+ ]
216
+ } )
217
+ const actions = mapActions ( 'my-todos' , [ 'find' ] )
218
+
219
+ actions . find
220
+ . call (
221
+ { $store : store } ,
222
+ { query : { $limit : 1 , $select : [ 'id' , 'description' ] } }
223
+ )
194
224
. then ( response => {
195
225
const returnedRecord = JSON . parse ( JSON . stringify ( response [ 0 ] ) )
196
226
assert ( response . length === 1 , 'only one record was returned' )
@@ -223,7 +253,7 @@ describe('Service Module - Actions', () => {
223
253
assert ( response . length === 1 , 'one record was returned' )
224
254
assert . deepEqual (
225
255
returnedRecord ,
226
- { id : 9 , description : 'Do the tenth' } ,
256
+ { id : 9 , description : 'Do the tenth' , isComplete : false } ,
227
257
'the tenth record was returned'
228
258
)
229
259
done ( )
@@ -250,7 +280,7 @@ describe('Service Module - Actions', () => {
250
280
assert ( response . length === 1 , 'one record was returned' )
251
281
assert . deepEqual (
252
282
returnedRecord ,
253
- { id : 8 , description : 'Do the ninth' } ,
283
+ { id : 8 , description : 'Do the ninth' , isComplete : false } ,
254
284
'the ninth record was returned'
255
285
)
256
286
done ( )
@@ -274,6 +304,39 @@ describe('Service Module - Actions', () => {
274
304
275
305
actions . find
276
306
. call ( { $store : store } , { query : { $limit : 1 } } )
307
+ . then ( response => {
308
+ const returnedRecord = JSON . parse ( JSON . stringify ( response . data [ 0 ] ) )
309
+ assert ( response . data . length === 1 , 'only one record was returned' )
310
+ assert . deepEqual (
311
+ returnedRecord ,
312
+ { id : 0 , description : 'Do the first' , isComplete : false } ,
313
+ 'the first record was returned'
314
+ )
315
+ assert ( response . limit === 1 , 'limit was correct' )
316
+ assert ( response . skip === 0 , 'skip was correct' )
317
+ assert ( response . total === 10 , 'total was correct' )
318
+ done ( )
319
+ } )
320
+ } )
321
+
322
+ it ( 'find with $select' , done => {
323
+ const { makeServicePlugin, Task } = makeContext ( )
324
+ const store = new Vuex . Store < RootState > ( {
325
+ plugins : [
326
+ makeServicePlugin ( {
327
+ servicePath : 'my-tasks' ,
328
+ Model : Task ,
329
+ service : feathersClient . service ( 'my-tasks' )
330
+ } )
331
+ ]
332
+ } )
333
+ const actions = mapActions ( 'my-tasks' , [ 'find' ] )
334
+
335
+ actions . find
336
+ . call (
337
+ { $store : store } ,
338
+ { query : { $limit : 1 , $select : [ 'id' , 'description' ] } }
339
+ )
277
340
. then ( response => {
278
341
const returnedRecord = JSON . parse ( JSON . stringify ( response . data [ 0 ] ) )
279
342
assert ( response . data . length === 1 , 'only one record was returned' )
@@ -309,7 +372,7 @@ describe('Service Module - Actions', () => {
309
372
assert ( response . data . length === 1 , 'only one record was returned' )
310
373
assert . deepEqual (
311
374
returnedRecord ,
312
- { id : 9 , description : 'Do the tenth' } ,
375
+ { id : 9 , description : 'Do the tenth' , isComplete : false } ,
313
376
'the tenth record was returned'
314
377
)
315
378
assert ( response . limit === 10 , 'limit was correct' )
@@ -339,7 +402,7 @@ describe('Service Module - Actions', () => {
339
402
assert ( response . data . length === 1 , 'only one record was returned' )
340
403
assert . deepEqual (
341
404
returnedRecord ,
342
- { id : 8 , description : 'Do the ninth' } ,
405
+ { id : 8 , description : 'Do the ninth' , isComplete : false } ,
343
406
'the ninth record was returned'
344
407
)
345
408
assert ( response . limit === 1 , 'limit was correct' )
@@ -401,9 +464,7 @@ describe('Service Module - Actions', () => {
401
464
const qid = 'component-name'
402
465
403
466
actions . find . call ( { $store : store } , { query : { } , qid } ) . then ( ( ) => {
404
- const qidPaginationState = store . state [
405
- 'my-tasks'
406
- ] . pagination [ qid ]
467
+ const qidPaginationState = store . state [ 'my-tasks' ] . pagination [ qid ]
407
468
assert ( qidPaginationState , 'got pagination state for qid' )
408
469
done ( )
409
470
} )
@@ -499,7 +560,7 @@ describe('Service Module - Actions', () => {
499
560
service : feathersClient . service ( 'no-ids' ) ,
500
561
idField : '_id' ,
501
562
actions : {
502
- afterFind ( { } , response ) {
563
+ afterFind ( { } , response ) {
503
564
assert (
504
565
response . data . length === 10 ,
505
566
'records were still returned'
@@ -551,7 +612,7 @@ describe('Service Module - Actions', () => {
551
612
} )
552
613
} )
553
614
554
- describe ( 'Get' , function ( ) {
615
+ describe ( 'Get' , function ( ) {
555
616
it ( 'updates store list state on service success' , async ( ) => {
556
617
const { makeServicePlugin, Todo } = makeContext ( )
557
618
const store = new Vuex . Store < RootState > ( {
@@ -577,7 +638,7 @@ describe('Service Module - Actions', () => {
577
638
assert ( todoState . isGetPending === false , 'isGetPending is set to false' )
578
639
579
640
let expectedKeyedById : NumberedList = {
580
- 0 : { id : 0 , description : 'Do the first' }
641
+ 0 : { id : 0 , description : 'Do the first' , isComplete : false }
581
642
}
582
643
assert . deepEqual (
583
644
JSON . parse ( JSON . stringify ( todoState . keyedById ) ) ,
@@ -587,22 +648,26 @@ describe('Service Module - Actions', () => {
587
648
// Make a request with the array syntax that allows passing params
588
649
const response2 = await actions . get . call ( { $store : store } , [ 1 , { } ] )
589
650
expectedKeyedById = {
590
- 0 : { id : 0 , description : 'Do the first' } ,
591
- 1 : { id : 1 , description : 'Do the second' }
651
+ 0 : { id : 0 , description : 'Do the first' , isComplete : false } ,
652
+ 1 : { id : 1 , description : 'Do the second' , isComplete : false }
592
653
}
593
654
assert ( response2 . description === 'Do the second' )
594
655
assert . deepEqual (
595
656
JSON . parse ( JSON . stringify ( todoState . keyedById ) ) ,
596
657
expectedKeyedById
597
658
)
598
659
599
- // Edit the first record in the store so the data is different.
600
- // Make a request for the first record again, and it should be updated.
660
+ // Edit the first record in the store so the data is different.
661
+ // Make a request for the first record again, and it should be updated.
601
662
const clone1 = todo1 . clone ( )
602
663
clone1 . description = 'MODIFIED IN THE VUEX STORE'
603
664
clone1 . commit ( )
604
665
605
- assert . strictEqual ( todoState . keyedById [ 0 ] . description , clone1 . description , 'the store instance was updated' )
666
+ assert . strictEqual (
667
+ todoState . keyedById [ 0 ] . description ,
668
+ clone1 . description ,
669
+ 'the store instance was updated'
670
+ )
606
671
607
672
const response3 = await actions . get . call ( { $store : store } , [ 0 , { } ] )
608
673
const todo0 = Todo . getFromStore ( 0 )
@@ -638,7 +703,7 @@ describe('Service Module - Actions', () => {
638
703
assert ( todoState . errorOnGet === null , 'there was no errorOnGet' )
639
704
assert ( todoState . isGetPending === false , 'isGetPending is set to false' )
640
705
let expectedKeyedById : NumberedList = {
641
- 0 : { id : 0 , description : 'Do the first' }
706
+ 0 : { id : 0 , description : 'Do the first' , isComplete : false }
642
707
}
643
708
assert . deepEqual (
644
709
JSON . parse ( JSON . stringify ( todoState . keyedById ) ) ,
@@ -648,8 +713,8 @@ describe('Service Module - Actions', () => {
648
713
// Make a request with the array syntax that allows passing params
649
714
actions . get . call ( { $store : store } , [ 1 , { } ] ) . then ( response2 => {
650
715
expectedKeyedById = {
651
- 0 : { id : 0 , description : 'Do the first' } ,
652
- 1 : { id : 1 , description : 'Do the second' }
716
+ 0 : { id : 0 , description : 'Do the first' , isComplete : false } ,
717
+ 1 : { id : 1 , description : 'Do the second' , isComplete : false }
653
718
}
654
719
assert ( response2 . description === 'Do the second' )
655
720
assert . deepEqual (
@@ -659,15 +724,15 @@ describe('Service Module - Actions', () => {
659
724
660
725
// Make a request to an existing record and return the existing data first, then update `keyedById`
661
726
todoState . keyedById = {
662
- 0 : { id : 0 , description : 'Do the FIRST' } , // twist the data to see difference
663
- 1 : { id : 1 , description : 'Do the second' }
727
+ 0 : { id : 0 , description : 'Do the FIRST' , isComplete : false } , // twist the data to see difference
728
+ 1 : { id : 1 , description : 'Do the second' , isComplete : false }
664
729
}
665
730
actions . get
666
731
. call ( { $store : store } , [ 0 , { skipRequestIfExists : true } ] )
667
732
. then ( response3 => {
668
733
expectedKeyedById = {
669
- 0 : { id : 0 , description : 'Do the FIRST' } ,
670
- 1 : { id : 1 , description : 'Do the second' }
734
+ 0 : { id : 0 , description : 'Do the FIRST' , isComplete : false } ,
735
+ 1 : { id : 1 , description : 'Do the second' , isComplete : false }
671
736
}
672
737
assert ( response3 . description === 'Do the FIRST' )
673
738
assert . deepEqual (
@@ -678,8 +743,8 @@ describe('Service Module - Actions', () => {
678
743
// The remote data will never arriive
679
744
setTimeout ( ( ) => {
680
745
expectedKeyedById = {
681
- 0 : { id : 0 , description : 'Do the FIRST' } ,
682
- 1 : { id : 1 , description : 'Do the second' }
746
+ 0 : { id : 0 , description : 'Do the FIRST' , isComplete : false } ,
747
+ 1 : { id : 1 , description : 'Do the second' , isComplete : false }
683
748
}
684
749
assert . deepEqual (
685
750
JSON . parse ( JSON . stringify ( todoState . keyedById ) ) ,
0 commit comments