diff --git a/lib/expressapp.js b/lib/expressapp.js index fd92143..3903fd4 100644 --- a/lib/expressapp.js +++ b/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); }); diff --git a/test/expressapp.js b/test/expressapp.js index 7b73d2d..d1310ca 100644 --- a/test/expressapp.js +++ b/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() {