From 824e8ee662f81e04570eb4b41d545fda708b14ee Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Thu, 12 Mar 2015 17:45:50 -0300 Subject: [PATCH] add coverage --- api/controllers/transactions.js | 5 +++++ api/test/v1/transactions.js | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/api/controllers/transactions.js b/api/controllers/transactions.js index 97807227..388f297a 100644 --- a/api/controllers/transactions.js +++ b/api/controllers/transactions.js @@ -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; } diff --git a/api/test/v1/transactions.js b/api/test/v1/transactions.js index 4da665dc..f41ba12d 100644 --- a/api/test/v1/transactions.js +++ b/api/test/v1/transactions.js @@ -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); }); }); };