From d6f9633a733ce31fa548f82c1e40fff7aa3acbfe Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Mon, 19 Oct 2015 15:03:49 -0300 Subject: [PATCH] improve tests --- lib/expressapp.js | 2 +- test/expressapp.js | 26 +++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/expressapp.js b/lib/expressapp.js index f67109e..142a23f 100644 --- a/lib/expressapp.js +++ b/lib/expressapp.js @@ -440,7 +440,7 @@ ExpressApp.prototype.start = function(opts, cb) { router.get('/v1/notifications/', function(req, res) { getServerWithAuth(req, res, function(server) { var opts = { - minTs: Math.max(+req.query.minTs, +Date.now() - (60 * 1000)), + minTs: Math.max(+req.query.minTs || 0, +Date.now() - (60 * 1000)), notificationId: req.query.notificationId, }; server.getNotifications(opts, function(err, notifications) { diff --git a/test/expressapp.js b/test/expressapp.js index 02cb1ae..faedbb9 100644 --- a/test/expressapp.js +++ b/test/expressapp.js @@ -103,10 +103,10 @@ describe('ExpressApp', function() { clock.restore(); }); - it('should fetch notifications from a specific id', function(done) { + it('should fetch notifications from a specified id', function(done) { start(TestExpressApp, function() { var requestOptions = { - url: testHost + ':' + testPort + config.basePath + '/v1/notifications' + '?notificationId=123&minTs=' + (Date.now() - 30000), + url: testHost + ':' + testPort + config.basePath + '/v1/notifications' + '?notificationId=123', headers: { 'x-identity': 'identity', 'x-signature': 'signature' @@ -118,6 +118,26 @@ describe('ExpressApp', function() { body.should.equal('{}'); server.getNotifications.calledWith({ notificationId: '123', + minTs: +Date.now() - 60000, + }).should.be.true; + done(); + }); + }); + }); + it('should allow custom minTs within limits', function(done) { + start(TestExpressApp, function() { + var requestOptions = { + url: testHost + ':' + testPort + config.basePath + '/v1/notifications' + '?minTs=' + (Date.now() - 30000), + headers: { + 'x-identity': 'identity', + 'x-signature': 'signature' + } + }; + request(requestOptions, function(err, res, body) { + should.not.exist(err); + res.statusCode.should.equal(200); + server.getNotifications.calledWith({ + notificationId: undefined, minTs: +Date.now() - 30000, }).should.be.true; done(); @@ -127,7 +147,7 @@ describe('ExpressApp', function() { it('should limit minTs to 60 seconds', function(done) { start(TestExpressApp, function() { var requestOptions = { - url: testHost + ':' + testPort + config.basePath + '/v1/notifications' + '?minTs=1', + url: testHost + ':' + testPort + config.basePath + '/v1/notifications' + '?minTs=' + (Date.now() - 90000), headers: { 'x-identity': 'identity', 'x-signature': 'signature'