Browse Source

fix GET v1/addresses/ endpoint

activeAddress
Ivan Socolsky 9 years ago
parent
commit
2367365707
  1. 6
      lib/expressapp.js
  2. 29
      test/expressapp.js

6
lib/expressapp.js

@ -282,7 +282,11 @@ ExpressApp.prototype.start = function(opts, cb) {
router.get('/v1/addresses/', function(req, res) {
getServerWithAuth(req, res, function(server) {
server.getMainAddresses(req.body, function(err, addresses) {
var opts = {};
if (req.query.limit) opts.limit = +req.query.limit;
opts.reverse = (req.query.reverse == '1');
server.getMainAddresses(opts, function(err, addresses) {
if (err) return returnError(err, res, req);
res.json(addresses);
});

29
test/expressapp.js

@ -84,6 +84,35 @@ describe('ExpressApp', function() {
});
});
it('/v1/addresses', function(done) {
var server = {
getMainAddresses: 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/addresses?limit=4&reverse=1',
headers: {
'x-identity': 'identity',
'x-signature': 'signature'
}
};
request(requestOptions, function(err, res, body) {
should.not.exist(err);
res.statusCode.should.equal(200);
var args = server.getMainAddresses.getCalls()[0].args[0];
args.limit.should.equal(4);
args.reverse.should.be.true;
done();
});
});
});
describe('/v1/notifications', function(done) {
var server, TestExpressApp, clock;
beforeEach(function() {

Loading…
Cancel
Save