improve tests

This commit is contained in:
Ivan Socolsky 2015-10-19 15:03:49 -03:00
parent 09c5af073d
commit d6f9633a73
2 changed files with 24 additions and 4 deletions

View File

@ -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) {

View File

@ -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'