Skip to content

Commit

Permalink
fix path for $count request
Browse files Browse the repository at this point in the history
  • Loading branch information
pofider committed Apr 2, 2018
1 parent 28cb0e3 commit a420fb4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/odataServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ ODataServer.prototype._initializeRoutes = function () {
res.writeHead(200, self.cfg.addCorsToHeaders({'Content-Type': 'application/xml', 'DataServiceVersion': '4.0', 'OData-Version': '4.0'}))
return res.end(result)
})
this.router.get('/:collection/\$count/', function (req, res) {
this.router.get('/:collection/\$count', function (req, res) {
req.params.$count = true
query(self.cfg, req, res)
})
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions test/odataServerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,24 @@ describe('odata server', function () {
})
})

it('get $count should return number of entries', function (done) {
odataServer.query(function (col, query, req, cb) {
cb(null, 1)
})

odataServer.on('odata-error', done)

request(server)
.get('/users/$count')
.expect(200)
.expect(function (res) {
res.body.value.should.be.eql(1)
})
.end(function (err, res) {
done(err)
})
})

it('get should have the selection fields in its @odata.context if $select is passed', function (done) {
var selectedField1 = 'num'
var selectedField2 = 'image'
Expand Down

0 comments on commit a420fb4

Please sign in to comment.