Skip to content

Commit 51ac4df

Browse files
committed
Sum and count tests
1 parent 2e1fff3 commit 51ac4df

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ Adapter.extend({
969969
sum (mapper, field, query, opts) {
970970
query || (query = {})
971971
opts || (opts = {})
972-
if (!utils.utils.isString(field)) {
972+
if (!utils.isString(field)) {
973973
throw new Error('field must be a string!')
974974
}
975975
opts.params = this.getParams(opts)

test/count.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
describe('sum', function () {
2+
it('should include count=true in query_params', function (done) {
3+
var Test = this
4+
5+
setTimeout(function () {
6+
Test.requests[0].respond(200, { 'Content-Type': 'application/json' }, '{"count": 5}')
7+
}, 5)
8+
9+
Test.adapter.count(Test.Post).then(function (result) {
10+
Test.assert.equal(Test.requests[0].url, 'api/posts?count=true')
11+
done()
12+
})
13+
})
14+
})

test/sum.test.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
describe('sum', function () {
2-
it('should #sum on a field', function (done) {
3-
done()
2+
it('should sum=<field> in query_params', function (done) {
3+
var Test = this
4+
5+
setTimeout(function () {
6+
Test.requests[0].respond(200, { 'Content-Type': 'application/json' }, '{"sum": 5}')
7+
}, 5)
8+
9+
Test.adapter.sum(Test.Post, 'num_views').then(function (result) {
10+
Test.assert.equal(Test.requests[0].url, 'api/posts?sum=num_views')
11+
done()
12+
})
413
})
514
})

0 commit comments

Comments
 (0)