Skip to content

Commit 05bf46e

Browse files
committed
Add sorting test
1 parent 8241655 commit 05bf46e

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

test/server.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,32 @@ describe('Server', function() {
9191
})
9292
})
9393

94+
describe('GET /:resource?sort=', function() {
95+
it('should respond with json and sort on a field', function(done) {
96+
request(server)
97+
.get('/tags?_sort=body')
98+
.expect('Content-Type', /json/)
99+
.expect([low.db.tags[1], low.db.tags[0], low.db.tags[2]])
100+
.expect(200, done)
101+
})
102+
103+
it('should reverse sorting with sortDir=DESC', function(done) {
104+
request(server)
105+
.get('/tags?_sort=body&_sortDir=DESC')
106+
.expect('Content-Type', /json/)
107+
.expect([low.db.tags[2], low.db.tags[0], low.db.tags[1]])
108+
.expect(200, done)
109+
})
110+
111+
it('should sort on numerical field', function(done) {
112+
request(server)
113+
.get('/posts?_sort=id&_sortDir=DESC')
114+
.expect('Content-Type', /json/)
115+
.expect(low.db.posts.reverse())
116+
.expect(200, done)
117+
})
118+
})
119+
94120
describe('GET /:resource?_start=&_end=', function() {
95121
it('should respond with a sliced array', function(done) {
96122
request(server)

0 commit comments

Comments
 (0)