Merge pull request #260 from isocolsky/paginate_txs

Paginate txs
This commit is contained in:
Matias Alejo Garcia 2014-11-20 18:21:26 -03:00
commit 85e4f78b09
2 changed files with 12 additions and 12 deletions

View File

@ -141,7 +141,7 @@ exports.multitxs = function(req, res, next) {
var as = getAddrs(req, res, next);
if (as) {
var txs = [];
async.each(as, function(a, callback) {
async.eachLimit(as, 10, function(a, callback) {
a.update(function(err) {
if (err) callback(err);
txs.push(a.transactions);
@ -152,7 +152,6 @@ exports.multitxs = function(req, res, next) {
processTxs(txs, from, to, function (err, transactions) {
if (err) return common.handleErrors(err, res);
res.jsonp(transactions);
return next();
});
});
}

View File

@ -34,21 +34,14 @@ describe('Transactions for multiple addresses', function() {
beforeEach(function(c) {
req = {};
res = {};
res.jsonp = sinon.spy();
return c();
});
describe('Transactions from multiple addresses', function () {
_.each(fixture, function (f) {
it(f.test, function (done) {
req.param = sinon.stub();
req.param.withArgs('addrs').returns(f.addrs.join(','));
req.param.withArgs('from').returns(f.from);
req.param.withArgs('to').returns(f.to);
var paginated = !_.isUndefined(f.from) || !_.isUndefined(f.to);
addresses.multitxs(req, res, function() {
var txs = res.jsonp.getCall(0).args[0];
var checkResult = function(txs) {
var paginated = !_.isUndefined(f.from) || !_.isUndefined(f.to);
txs.should.exist;
if (paginated) {
txs.totalItems.should.equal(f.totalTransactions);
@ -61,7 +54,15 @@ describe('Transactions for multiple addresses', function() {
txs.length.should.equal(f.returnedTransactions);
}
done();
});
};
res.jsonp = checkResult;
req.param = sinon.stub();
req.param.withArgs('addrs').returns(f.addrs.join(','));
req.param.withArgs('from').returns(f.from);
req.param.withArgs('to').returns(f.to);
addresses.multitxs(req, res);
});
});
});