node: optional getAPIMethods and getPublishEvents
This commit is contained in:
parent
e87f628e7a
commit
70fae5335c
|
@ -102,8 +102,10 @@ Node.prototype.getAllAPIMethods = function() {
|
|||
var methods = [];
|
||||
for(var i in this.services) {
|
||||
var mod = this.services[i];
|
||||
if (mod.getAPIMethods) {
|
||||
methods = methods.concat(mod.getAPIMethods());
|
||||
}
|
||||
}
|
||||
return methods;
|
||||
};
|
||||
|
||||
|
@ -115,8 +117,10 @@ Node.prototype.getAllPublishEvents = function() {
|
|||
var events = [];
|
||||
for (var i in this.services) {
|
||||
var mod = this.services[i];
|
||||
if (mod.getPublishEvents) {
|
||||
events = events.concat(mod.getPublishEvents());
|
||||
}
|
||||
}
|
||||
return events;
|
||||
};
|
||||
|
||||
|
@ -199,6 +203,7 @@ Node.prototype._startService = function(serviceInfo, callback) {
|
|||
}
|
||||
|
||||
// add API methods
|
||||
if (service.getAPIMethods) {
|
||||
var methodData = service.getAPIMethods();
|
||||
var methodNameConflicts = [];
|
||||
methodData.forEach(function(data) {
|
||||
|
@ -218,6 +223,7 @@ Node.prototype._startService = function(serviceInfo, callback) {
|
|||
if (methodNameConflicts.length > 0) {
|
||||
return callback(new Error('Existing API method(s) exists: ' + methodNameConflicts.join(', ')));
|
||||
}
|
||||
}
|
||||
|
||||
callback();
|
||||
|
||||
|
|
|
@ -139,6 +139,21 @@ describe('Bitcore Node', function() {
|
|||
var methods = node.getAllAPIMethods();
|
||||
methods.should.deep.equal(['db1', 'db2', 'mda1', 'mda2', 'mdb1', 'mdb2']);
|
||||
});
|
||||
it('will handle service without getAPIMethods defined', function() {
|
||||
var node = new Node(baseConfig);
|
||||
node.services = {
|
||||
db: {
|
||||
getAPIMethods: sinon.stub().returns(['db1', 'db2']),
|
||||
},
|
||||
service1: {},
|
||||
service2: {
|
||||
getAPIMethods: sinon.stub().returns(['mdb1', 'mdb2'])
|
||||
}
|
||||
};
|
||||
|
||||
var methods = node.getAllAPIMethods();
|
||||
methods.should.deep.equal(['db1', 'db2', 'mdb1', 'mdb2']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getAllPublishEvents', function() {
|
||||
|
@ -158,6 +173,20 @@ describe('Bitcore Node', function() {
|
|||
var events = node.getAllPublishEvents();
|
||||
events.should.deep.equal(['db1', 'db2', 'mda1', 'mda2', 'mdb1', 'mdb2']);
|
||||
});
|
||||
it('will handle service without getPublishEvents defined', function() {
|
||||
var node = new Node(baseConfig);
|
||||
node.services = {
|
||||
db: {
|
||||
getPublishEvents: sinon.stub().returns(['db1', 'db2']),
|
||||
},
|
||||
service1: {},
|
||||
service2: {
|
||||
getPublishEvents: sinon.stub().returns(['mdb1', 'mdb2'])
|
||||
}
|
||||
};
|
||||
var events = node.getAllPublishEvents();
|
||||
events.should.deep.equal(['db1', 'db2', 'mdb1', 'mdb2']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getServiceOrder', function() {
|
||||
|
@ -343,6 +372,28 @@ describe('Bitcore Node', function() {
|
|||
});
|
||||
|
||||
});
|
||||
it('will handle service with getAPIMethods undefined', function(done) {
|
||||
var node = new Node(baseConfig);
|
||||
|
||||
function TestService() {}
|
||||
util.inherits(TestService, BaseService);
|
||||
TestService.prototype.start = sinon.stub().callsArg(0);
|
||||
TestService.prototype.getData = function() {};
|
||||
|
||||
node.getServiceOrder = sinon.stub().returns([
|
||||
{
|
||||
name: 'test',
|
||||
module: TestService,
|
||||
config: {}
|
||||
},
|
||||
]);
|
||||
|
||||
node.start(function() {
|
||||
TestService.prototype.start.callCount.should.equal(1);
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getNetworkName', function() {
|
||||
|
|
Loading…
Reference in New Issue