mock /blocks call
This commit is contained in:
parent
a09f939b02
commit
cbf4b2c03b
@ -53,6 +53,13 @@ Blocks.heightParam = function(req, res, next, height) {
|
|||||||
* controllers
|
* controllers
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
Blocks.list = function(req, res) {
|
||||||
|
node.listBlocks()
|
||||||
|
.then(function(blocks) {
|
||||||
|
res.send(blocks);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
Blocks.getLatest = function(req, res) {
|
Blocks.getLatest = function(req, res) {
|
||||||
node.getLatestBlock()
|
node.getLatestBlock()
|
||||||
.then(function(block) {
|
.then(function(block) {
|
||||||
|
|||||||
@ -28,7 +28,7 @@ function initRouter(node) {
|
|||||||
router.get('/node', NodeStatus.getStatus);
|
router.get('/node', NodeStatus.getStatus);
|
||||||
|
|
||||||
// Block routes
|
// Block routes
|
||||||
router.get('/blocks', mockResponse);
|
router.get('/blocks', Blocks.list);
|
||||||
router.get('/blocks/latest', Blocks.getLatest);
|
router.get('/blocks/latest', Blocks.getLatest);
|
||||||
router.get('/blocks/:blockHash([A-Fa-f0-9]{64})', Blocks.get);
|
router.get('/blocks/:blockHash([A-Fa-f0-9]{64})', Blocks.get);
|
||||||
router.get('/blocks/:height([0-9]+)', Blocks.get);
|
router.get('/blocks/:height([0-9]+)', Blocks.get);
|
||||||
|
|||||||
@ -14,12 +14,23 @@ var BitcoreHTTP = require('../../lib/http');
|
|||||||
var BitcoreNode = require('../../../');
|
var BitcoreNode = require('../../../');
|
||||||
var mockBlocks = require('../data/blocks');
|
var mockBlocks = require('../data/blocks');
|
||||||
|
|
||||||
|
Object.values = function(obj) {
|
||||||
|
var vals = [];
|
||||||
|
for (var key in obj) {
|
||||||
|
if (obj.hasOwnProperty(key)) {
|
||||||
|
vals.push(obj[key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return vals;
|
||||||
|
};
|
||||||
|
|
||||||
describe('BitcoreHTTP v1 blocks routes', function() {
|
describe('BitcoreHTTP v1 blocks routes', function() {
|
||||||
|
|
||||||
// mocks
|
// mocks
|
||||||
var b1 = mockBlocks[Object.keys(mockBlocks)[0]];
|
var b1 = mockBlocks[Object.keys(mockBlocks)[0]];
|
||||||
var lastBlock = mockBlocks[Object.keys(mockBlocks).splice(-1)[0]];
|
var lastBlock = mockBlocks[Object.keys(mockBlocks).splice(-1)[0]];
|
||||||
var nodeMock, app, agent;
|
var nodeMock, app, agent;
|
||||||
|
var blockList = Object.values(mockBlocks);
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
nodeMock = new EventEmitter();
|
nodeMock = new EventEmitter();
|
||||||
nodeMock.getBlock = function(blockHash) {
|
nodeMock.getBlock = function(blockHash) {
|
||||||
@ -39,6 +50,9 @@ describe('BitcoreHTTP v1 blocks routes', function() {
|
|||||||
nodeMock.getLatestBlock = function() {
|
nodeMock.getLatestBlock = function() {
|
||||||
return Promise.resolve(mockBlocks[Object.keys(mockBlocks).splice(-1)[0]]);
|
return Promise.resolve(mockBlocks[Object.keys(mockBlocks).splice(-1)[0]]);
|
||||||
};
|
};
|
||||||
|
nodeMock.listBlocks = function() {
|
||||||
|
return Promise.resolve(blockList);
|
||||||
|
};
|
||||||
app = new BitcoreHTTP(nodeMock).app;
|
app = new BitcoreHTTP(nodeMock).app;
|
||||||
agent = request(app);
|
agent = request(app);
|
||||||
});
|
});
|
||||||
@ -47,9 +61,7 @@ describe('BitcoreHTTP v1 blocks routes', function() {
|
|||||||
it('works with default parameters', function(cb) {
|
it('works with default parameters', function(cb) {
|
||||||
agent.get('/v1/blocks/')
|
agent.get('/v1/blocks/')
|
||||||
.expect(200)
|
.expect(200)
|
||||||
.expect({
|
.expect(JSON.stringify(blockList), cb);
|
||||||
'message': 'This is a mocked response'
|
|
||||||
}, cb);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('/blocks/latest', function() {
|
describe('/blocks/latest', function() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user