@@ -26,22 +26,34 @@ describe('Service Module - Getters', function() {
26
26
beforeEach ( function ( ) {
27
27
const state = makeServiceState ( 'getter-todos' , options )
28
28
this . items = [
29
- { _id : 1 , otherField : true , test : true } ,
29
+ {
30
+ _id : 1 ,
31
+ otherField : true ,
32
+ age : 21 ,
33
+ teethRemaining : 2.501 ,
34
+ test : true
35
+ } ,
30
36
{
31
37
_id : 2 ,
32
38
name : 'Marshall' ,
33
39
otherField : true ,
40
+ age : 24 ,
41
+ teethRemaining : 2.5 ,
34
42
test : true ,
35
43
movies : [ { actors : [ 'Jerry the Mouse' ] } ]
36
44
} ,
37
45
{
38
46
_id : 3 ,
39
47
otherField : true ,
48
+ age : 27 ,
49
+ teethRemaining : 12 ,
40
50
test : false ,
41
51
movies : [ { actors : [ 'Tom Hanks' , 'Tom Cruise' , 'Tomcat' ] } ]
42
52
} ,
43
53
{
44
54
name : 'Mariah' ,
55
+ age : 19 ,
56
+ teethRemaining : 24 ,
45
57
status : 'temp'
46
58
}
47
59
]
@@ -288,4 +300,64 @@ describe('Service Module - Getters', function() {
288
300
assert ( results . skip === 0 , 'skip was correct' )
289
301
assert ( results . total === 3 , 'total was correct' )
290
302
} )
303
+
304
+ it ( 'find with sort ascending on integers' , function ( ) {
305
+ const { state } = this
306
+ const params = {
307
+ query : {
308
+ $sort : { age : 1 }
309
+ }
310
+ }
311
+ const results = find ( state ) ( params )
312
+
313
+ results . data . map ( i => i . age ) . reduce ( ( oldest , current ) => {
314
+ assert ( current > oldest , 'age should have been older than previous' )
315
+ return current
316
+ } , 0 )
317
+ } )
318
+
319
+ it ( 'find with sort descending on integers' , function ( ) {
320
+ const { state } = this
321
+ const params = {
322
+ query : {
323
+ $sort : { age : - 1 }
324
+ }
325
+ }
326
+ const results = find ( state ) ( params )
327
+
328
+ results . data . map ( i => i . age ) . reduce ( ( oldest , current ) => {
329
+ assert ( current < oldest , 'age should have been younger than previous' )
330
+ return current
331
+ } , 100 )
332
+ } )
333
+
334
+ it ( 'find with sort ascending on floats' , function ( ) {
335
+ const { state } = this
336
+ const params = {
337
+ query : {
338
+ $sort : { teethRemaining : 1 }
339
+ }
340
+ }
341
+ const results = find ( state ) ( params )
342
+
343
+ results . data . map ( i => i . teethRemaining ) . reduce ( ( oldest , current ) => {
344
+ assert ( current > oldest , 'teethRemaining should have been older than previous' )
345
+ return current
346
+ } , 0 )
347
+ } )
348
+
349
+ it ( 'find with sort descending on floats' , function ( ) {
350
+ const { state } = this
351
+ const params = {
352
+ query : {
353
+ $sort : { teethRemaining : - 1 }
354
+ }
355
+ }
356
+ const results = find ( state ) ( params )
357
+
358
+ results . data . map ( i => i . teethRemaining ) . reduce ( ( oldest , current ) => {
359
+ assert ( current < oldest , 'teethRemaining should have been younger than previous' )
360
+ return current
361
+ } , 100 )
362
+ } )
291
363
} )
0 commit comments