diff --git a/src/client.js b/src/client.js index 1e9a5fa..abaed2d 100644 --- a/src/client.js +++ b/src/client.js @@ -41,6 +41,14 @@ Client.prototype.add = function (name, transport) { this.emit('added', name) } +Client.prototype.getServices = function () { + return Object.keys(this.services) +} + +Client.prototype.hasService = function (name) { + return !!~this.getServices().indexOf(name) +} + Client.prototype.addSchema = function (service, method, schema) { if (!this.schemas[service]) { this.schemas[service] = {} diff --git a/test/client.js b/test/client.js index 0fa73b7..727f4e2 100644 --- a/test/client.js +++ b/test/client.js @@ -145,6 +145,33 @@ describe('Client', function () { }) }) + describe('getServices', function () { + it('should return array of services added', function () { + let services = { + 'test1': mockTransport()({}), + 'test2': mockTransport()({}) + } + let client = new Client(services) + let serviceNames = client.getServices() + assert.deepEqual(serviceNames, Object.keys(services)) + }) + }) + + describe('hasService', function () { + it('should return true when client has service', function () { + let service = mockTransport()({}) + let client = new Client({ + myService: service + }) + assert.equal(client.hasService('myService'), true) + }) + + it("should return false when client doesn't have service", function () { + let client = new Client() + assert.equal(client.hasService('myService'), false) + }) + }) + describe('call', function () { it('should return error if calling unknown service', function (done) { let client = new Client({})