-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
292 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
|
||
// Null client used when no event client listener is needed (transport=manual) | ||
|
||
var EventEmitter = require('events').EventEmitter; | ||
var object = require('./object'); | ||
var asyncHelpers = require('./async'); | ||
|
||
function nullClient() { | ||
var self = object.create(nullClient.prototype); | ||
|
||
EventEmitter.call(self); | ||
|
||
return self; | ||
} | ||
|
||
nullClient.prototype = new EventEmitter(); | ||
|
||
nullClient.prototype.connect = function connect(token, callback) { | ||
asyncHelpers.setImmediate(callback); | ||
}; | ||
|
||
module.exports = nullClient; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict'; | ||
|
||
const expect = require('chai').expect; | ||
const clientFactory = require('../../lib/utils/client_factory'); | ||
const pollingClient = require('../../lib/utils/polling_client'); | ||
const socketClient = require('../../lib/utils/socket_client'); | ||
const nullClient = require('../../lib/utils/null_client'); | ||
|
||
describe('client factory', function () { | ||
describe('#create', function () { | ||
describe('if options.dependency is defined', function () { | ||
it('returns the dependency', function () { | ||
const dependency = { hola: 'hello' }; | ||
|
||
expect(clientFactory.create({ dependency })).to.equal(dependency); | ||
}); | ||
}); | ||
|
||
describe('if options.transport is polling', function () { | ||
it('returns an instance of polling client', function () { | ||
expect(clientFactory.create({ transport: 'polling', serviceUrl: 'http://localhost', httpClient: {} })).to.be.an.instanceOf(pollingClient); | ||
}); | ||
}); | ||
|
||
describe('if options.transport is manual', function () { | ||
it('returns an instance of null client', function () { | ||
expect(clientFactory.create({ transport: 'manual' })).to.be.an.instanceOf(nullClient); | ||
}); | ||
}); | ||
|
||
describe('if options.transport is not defined', function () { | ||
it('returns an instance of socket client', function () { | ||
expect(clientFactory.create({ serviceUrl: 'http://localhost' })).to.be.an.instanceOf(socketClient); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
|
||
const expect = require('chai').expect; | ||
const nullClientBuilder = require('../../lib/utils/null_client'); | ||
|
||
describe('utils/null_client', function () { | ||
let nullClient; | ||
|
||
beforeEach(function () { | ||
nullClient = nullClientBuilder(); | ||
}); | ||
|
||
it('has method #on', function () { | ||
expect(nullClient).to.have.respondsTo('on'); | ||
}); | ||
|
||
it('has method #once', function () { | ||
expect(nullClient).to.have.respondsTo('once'); | ||
}); | ||
|
||
it('has method #removeAllListeners', function () { | ||
expect(nullClient).to.have.respondsTo('removeAllListeners'); | ||
}); | ||
|
||
describe('#connect', function () { | ||
it('callbacks immediatelly', function (done) { | ||
nullClient.connect('abc', done); | ||
}); | ||
}); | ||
}); |