@@ -21,11 +21,11 @@ const options = {
21
21
service : null
22
22
}
23
23
24
- const { find, list, get, getCopyById } = makeServiceGetters ( )
24
+ const { find, count , list, get, getCopyById } = makeServiceGetters ( )
25
25
const { addItems } = makeServiceMutations ( )
26
26
27
- describe ( 'Service Module - Getters' , function ( ) {
28
- beforeEach ( function ( ) {
27
+ describe ( 'Service Module - Getters' , function ( ) {
28
+ beforeEach ( function ( ) {
29
29
const state = makeServiceState ( options )
30
30
this . items = [
31
31
{
@@ -63,7 +63,7 @@ describe('Service Module - Getters', function() {
63
63
this . state = state
64
64
} )
65
65
66
- it ( 'list' , function ( ) {
66
+ it ( 'list' , function ( ) {
67
67
const { state, items } = this
68
68
const results = list ( state )
69
69
@@ -74,7 +74,7 @@ describe('Service Module - Getters', function() {
74
74
} )
75
75
} )
76
76
77
- it ( 'getCopyById with keepCopiesInStore: true' , function ( ) {
77
+ it ( 'getCopyById with keepCopiesInStore: true' , function ( ) {
78
78
const state = {
79
79
keepCopiesInStore : true ,
80
80
copiesById : {
@@ -88,7 +88,7 @@ describe('Service Module - Getters', function() {
88
88
assert ( result . test , 'got the copy' )
89
89
} )
90
90
91
- it ( 'getCopyById with keepCopiesInStore: false' , function ( ) {
91
+ it ( 'getCopyById with keepCopiesInStore: false' , function ( ) {
92
92
const state = {
93
93
keepCopiesInStore : false ,
94
94
servicePath : 'todos' ,
@@ -117,7 +117,7 @@ describe('Service Module - Getters', function() {
117
117
clearModels ( )
118
118
} )
119
119
120
- it ( 'get works on keyedById' , function ( ) {
120
+ it ( 'get works on keyedById' , function ( ) {
121
121
const { state, items } = this
122
122
// @ts -ignore
123
123
const result = get ( state ) ( 1 )
@@ -126,7 +126,7 @@ describe('Service Module - Getters', function() {
126
126
assert . deepEqual ( result , items [ 0 ] )
127
127
} )
128
128
129
- it ( 'get works on tempsById' , function ( ) {
129
+ it ( 'get works on tempsById' , function ( ) {
130
130
const { state } = this
131
131
const tempId = Object . keys ( state . tempsById ) [ 0 ]
132
132
// @ts -ignore
@@ -136,7 +136,7 @@ describe('Service Module - Getters', function() {
136
136
assert ( result . __id === tempId )
137
137
} )
138
138
139
- it ( 'find - no temps by default' , function ( ) {
139
+ it ( 'find - no temps by default' , function ( ) {
140
140
const { state, items } = this
141
141
const params = { query : { } }
142
142
const results = find ( state ) ( params )
@@ -151,7 +151,7 @@ describe('Service Module - Getters', function() {
151
151
assert ( results . total === 3 , 'total was correct' )
152
152
} )
153
153
154
- it ( 'find with temps' , function ( ) {
154
+ it ( 'find with temps' , function ( ) {
155
155
const { state, items } = this
156
156
// Set temps: false to skip the temps.
157
157
const params = { query : { } , temps : true }
@@ -163,7 +163,7 @@ describe('Service Module - Getters', function() {
163
163
assert ( results . total === 4 , 'total was correct' )
164
164
} )
165
165
166
- it ( 'find with query' , function ( ) {
166
+ it ( 'find with query' , function ( ) {
167
167
const { state } = this
168
168
const params = { query : { test : false } }
169
169
const results = find ( state ) ( params )
@@ -175,7 +175,7 @@ describe('Service Module - Getters', function() {
175
175
assert ( results . total === 1 , 'total was correct' )
176
176
} )
177
177
178
- it ( 'find with custom operator' , function ( ) {
178
+ it ( 'find with custom operator' , function ( ) {
179
179
const { state } = this
180
180
const params = { query : { test : false , $populateQuery : 'test' } }
181
181
const results = find ( state ) ( params )
@@ -187,7 +187,7 @@ describe('Service Module - Getters', function() {
187
187
assert ( results . total === 1 , 'total was correct' )
188
188
} )
189
189
190
- it ( 'find with paramsForServer option' , function ( ) {
190
+ it ( 'find with paramsForServer option' , function ( ) {
191
191
const { state } = this
192
192
state . paramsForServer = [ '_$client' ]
193
193
const params = { query : { test : false , _$client : 'test' } }
@@ -200,7 +200,7 @@ describe('Service Module - Getters', function() {
200
200
assert ( results . total === 1 , 'total was correct' )
201
201
} )
202
202
203
- it ( 'find with non-whitelisted custom operator fails' , function ( ) {
203
+ it ( 'find with non-whitelisted custom operator fails' , function ( ) {
204
204
const { state } = this
205
205
const params = { query : { $client : 'test' } }
206
206
let results
@@ -212,7 +212,7 @@ describe('Service Module - Getters', function() {
212
212
assert ( ! results [ 0 ] )
213
213
} )
214
214
215
- it ( 'find with whitelisted custom operators' , function ( ) {
215
+ it ( 'find with whitelisted custom operators' , function ( ) {
216
216
const { state } = this
217
217
state . whitelist = [ '$regex' , '$options' ]
218
218
const query = {
@@ -232,7 +232,7 @@ describe('Service Module - Getters', function() {
232
232
assert ( results . total === 1 , 'total was correct' )
233
233
} )
234
234
235
- it ( 'find works with $elemMatch' , function ( ) {
235
+ it ( 'find works with $elemMatch' , function ( ) {
236
236
const { state } = this
237
237
const query = {
238
238
movies : {
@@ -249,7 +249,7 @@ describe('Service Module - Getters', function() {
249
249
assert ( results . total === 1 , 'total was correct' )
250
250
} )
251
251
252
- it ( 'find with limit' , function ( ) {
252
+ it ( 'find with limit' , function ( ) {
253
253
const { state } = this
254
254
const params = { query : { $limit : 1 } }
255
255
const results = find ( state ) ( params )
@@ -261,7 +261,7 @@ describe('Service Module - Getters', function() {
261
261
assert ( results . total === 3 , 'total was correct' )
262
262
} )
263
263
264
- it ( 'find with skip' , function ( ) {
264
+ it ( 'find with skip' , function ( ) {
265
265
const { state } = this
266
266
const params = { query : { $skip : 1 } }
267
267
const results = find ( state ) ( params )
@@ -274,7 +274,7 @@ describe('Service Module - Getters', function() {
274
274
assert ( results . total === 3 , 'total was correct' )
275
275
} )
276
276
277
- it ( 'find with limit and skip' , function ( ) {
277
+ it ( 'find with limit and skip' , function ( ) {
278
278
const { state } = this
279
279
const params = { query : { $limit : 1 , $skip : 1 } }
280
280
const results = find ( state ) ( params )
@@ -286,7 +286,7 @@ describe('Service Module - Getters', function() {
286
286
assert ( results . total === 3 , 'total was correct' )
287
287
} )
288
288
289
- it ( 'find with select' , function ( ) {
289
+ it ( 'find with select' , function ( ) {
290
290
const { state } = this
291
291
const params = { query : { $select : [ 'otherField' ] } }
292
292
const results = find ( state ) ( params )
@@ -305,7 +305,7 @@ describe('Service Module - Getters', function() {
305
305
assert ( results . total === 3 , 'total was correct' )
306
306
} )
307
307
308
- it ( 'find with sort ascending on integers' , function ( ) {
308
+ it ( 'find with sort ascending on integers' , function ( ) {
309
309
const { state } = this
310
310
const params = {
311
311
query : {
@@ -322,7 +322,7 @@ describe('Service Module - Getters', function() {
322
322
} , 0 )
323
323
} )
324
324
325
- it ( 'find with sort descending on integers' , function ( ) {
325
+ it ( 'find with sort descending on integers' , function ( ) {
326
326
const { state } = this
327
327
const params = {
328
328
query : {
@@ -339,7 +339,7 @@ describe('Service Module - Getters', function() {
339
339
} , 100 )
340
340
} )
341
341
342
- it ( 'find with sort ascending on floats' , function ( ) {
342
+ it ( 'find with sort ascending on floats' , function ( ) {
343
343
const { state } = this
344
344
const params = {
345
345
query : {
@@ -359,7 +359,7 @@ describe('Service Module - Getters', function() {
359
359
} , 0 )
360
360
} )
361
361
362
- it ( 'find with sort descending on floats' , function ( ) {
362
+ it ( 'find with sort descending on floats' , function ( ) {
363
363
const { state } = this
364
364
const params = {
365
365
query : {
@@ -378,4 +378,31 @@ describe('Service Module - Getters', function() {
378
378
return current
379
379
} , 100 )
380
380
} )
381
+
382
+ it ( 'count without params fails' , function ( ) {
383
+ const { state } = this
384
+
385
+ try {
386
+ count ( state , { find } ) ( null )
387
+ } catch ( error ) {
388
+ assert ( error )
389
+ }
390
+ } )
391
+
392
+ it ( 'count without query fails' , function ( ) {
393
+ const { state } = this
394
+
395
+ try {
396
+ count ( state , { find } ) ( { } )
397
+ } catch ( error ) {
398
+ assert ( error )
399
+ }
400
+ } )
401
+
402
+ it ( 'count returns the number of records in the store' , function ( ) {
403
+ const { state } = this
404
+
405
+ const total = count ( state , { find } ) ( { query : { } } )
406
+ assert ( total === 3 , 'count is 3' )
407
+ } )
381
408
} )
0 commit comments