add coverage

This commit is contained in:
Manuel Araoz 2015-03-12 17:45:50 -03:00
parent 03ee93bac8
commit 824e8ee662
2 changed files with 14 additions and 0 deletions

View File

@ -102,6 +102,11 @@ var buildIOHelper = function(name) {
return function(req, res) {
$.checkState(req.tx instanceof Transaction);
if (_.isNumber(req.index)) {
if (req.index >= req.tx[name].length) {
res.status(404).send('Transaction ' + name.substring(0, name.length - 1) + ' ' + req.index +
' for ' + req.tx.id + ' not found, it only has ' + req.tx[name].length + ' ' + name + '.');
return;
}
res.send(req.tx[name][req.index].toJSON());
return;
}

View File

@ -136,6 +136,15 @@ describe('BitcoreHTTP v1 transactions routes', function() {
for (var i = 0; i < tx[name].length; i++) {
it('works with valid txHash ...' + summary + ' ' + name + ' ' + i, canGetSpecificInput(i));
}
it('fails with invalid ' + name + ' index ' + i + ' for txHash ...' + summary, function(cb) {
agent.get('/v1/transactions/' + hash + '/' + name + '/' + i)
.expect(404, cb);
});
});
it('fails with invalid ' + name + ' format', function(cb) {
agent.get('/v1/transactions/' + t1.id + '/' + name + '/-1')
.expect(422)
.expect('index parameter must be a positive integer', cb);
});
});
};