Skip to content

Commit

Permalink
Merge pull request #35 from hudson-taylor/get-client-services
Browse files Browse the repository at this point in the history
Add methods to get available services on client
  • Loading branch information
SomeoneWeird committed Dec 22, 2016
2 parents 6bb41c0 + 9b2de60 commit d5f9e5a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {}
Expand Down
27 changes: 27 additions & 0 deletions test/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({})
Expand Down

0 comments on commit d5f9e5a

Please sign in to comment.