accept minTs arg on v1/notifications but limit it to now - 60s
This commit is contained in:
parent
5c048e390c
commit
09c5af073d
|
@ -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: +Date.now() - (60 * 1000),
|
||||
minTs: Math.max(+req.query.minTs, +Date.now() - (60 * 1000)),
|
||||
notificationId: req.query.notificationId,
|
||||
};
|
||||
server.getNotifications(opts, function(err, notifications) {
|
||||
|
|
|
@ -84,37 +84,65 @@ describe('ExpressApp', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('/v1/notifications', function(done) {
|
||||
var clock = sinon.useFakeTimers(1234000, 'Date');
|
||||
describe('/v1/notifications', function(done) {
|
||||
var server, TestExpressApp, clock;
|
||||
beforeEach(function() {
|
||||
clock = sinon.useFakeTimers(1234000, 'Date');
|
||||
|
||||
var server = {
|
||||
getNotifications: sinon.stub().callsArgWith(1, null, {})
|
||||
};
|
||||
var TestExpressApp = proxyquire('../lib/expressapp', {
|
||||
'./server': {
|
||||
initialize: sinon.stub().callsArg(1),
|
||||
getInstanceWithAuth: sinon.stub().callsArgWith(1, null, server),
|
||||
}
|
||||
});
|
||||
start(TestExpressApp, function() {
|
||||
var requestOptions = {
|
||||
url: testHost + ':' + testPort + config.basePath + '/v1/notifications' + '?notificationId=123&minTs=0',
|
||||
headers: {
|
||||
'x-identity': 'identity',
|
||||
'x-signature': 'signature'
|
||||
}
|
||||
server = {
|
||||
getNotifications: sinon.stub().callsArgWith(1, null, {})
|
||||
};
|
||||
request(requestOptions, function(err, res, body) {
|
||||
should.not.exist(err);
|
||||
res.statusCode.should.equal(200);
|
||||
body.should.equal('{}');
|
||||
server.getNotifications.calledWith({
|
||||
notificationId: '123',
|
||||
minTs: 1234000 - 60000, // override minTs argument with a hardcoded 60 seconds span
|
||||
}).should.be.true;
|
||||
TestExpressApp = proxyquire('../lib/expressapp', {
|
||||
'./server': {
|
||||
initialize: sinon.stub().callsArg(1),
|
||||
getInstanceWithAuth: sinon.stub().callsArgWith(1, null, server),
|
||||
}
|
||||
});
|
||||
});
|
||||
afterEach(function() {
|
||||
clock.restore();
|
||||
});
|
||||
|
||||
clock.restore();
|
||||
done();
|
||||
it('should fetch notifications from a specific id', function(done) {
|
||||
start(TestExpressApp, function() {
|
||||
var requestOptions = {
|
||||
url: testHost + ':' + testPort + config.basePath + '/v1/notifications' + '?notificationId=123&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);
|
||||
body.should.equal('{}');
|
||||
server.getNotifications.calledWith({
|
||||
notificationId: '123',
|
||||
minTs: +Date.now() - 30000,
|
||||
}).should.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
it('should limit minTs to 60 seconds', function(done) {
|
||||
start(TestExpressApp, function() {
|
||||
var requestOptions = {
|
||||
url: testHost + ':' + testPort + config.basePath + '/v1/notifications' + '?minTs=1',
|
||||
headers: {
|
||||
'x-identity': 'identity',
|
||||
'x-signature': 'signature'
|
||||
}
|
||||
};
|
||||
request(requestOptions, function(err, res, body) {
|
||||
should.not.exist(err);
|
||||
res.statusCode.should.equal(200);
|
||||
body.should.equal('{}');
|
||||
server.getNotifications.calledWith({
|
||||
notificationId: undefined,
|
||||
minTs: Date.now() - 60000, // override minTs argument with a hardcoded 60 seconds span
|
||||
}).should.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue