diff --git a/lib/odataServer.js b/lib/odataServer.js index ddf2396..9c5e715 100644 --- a/lib/odataServer.js +++ b/lib/odataServer.js @@ -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) }) diff --git a/package-lock.json b/package-lock.json index 973a4f7..99d3cde 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "simple-odata-server", - "version": "0.3.2", + "version": "1.0.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/test/odataServerTest.js b/test/odataServerTest.js index ede1bcd..4052467 100644 --- a/test/odataServerTest.js +++ b/test/odataServerTest.js @@ -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'