Skip to content

Commit 25cd054

Browse files
committed
Test that getters are sorting properly with decmal values
Fixes #160
1 parent 8702c8e commit 25cd054

File tree

1 file changed

+73
-1
lines changed

1 file changed

+73
-1
lines changed

test/service-module/module.getters.test.ts

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,34 @@ describe('Service Module - Getters', function() {
2626
beforeEach(function() {
2727
const state = makeServiceState('getter-todos', options)
2828
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+
},
3036
{
3137
_id: 2,
3238
name: 'Marshall',
3339
otherField: true,
40+
age: 24,
41+
teethRemaining: 2.5,
3442
test: true,
3543
movies: [{ actors: ['Jerry the Mouse'] }]
3644
},
3745
{
3846
_id: 3,
3947
otherField: true,
48+
age: 27,
49+
teethRemaining: 12,
4050
test: false,
4151
movies: [{ actors: ['Tom Hanks', 'Tom Cruise', 'Tomcat'] }]
4252
},
4353
{
4454
name: 'Mariah',
55+
age: 19,
56+
teethRemaining: 24,
4557
status: 'temp'
4658
}
4759
]
@@ -288,4 +300,64 @@ describe('Service Module - Getters', function() {
288300
assert(results.skip === 0, 'skip was correct')
289301
assert(results.total === 3, 'total was correct')
290302
})
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+
})
291363
})

0 commit comments

Comments
 (0)