Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/protocols/abstract/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class AbstractWrapper extends KuzzleEventEmitter {

this._pendingRequests = new Map();
this._host = host;
this._port = typeof options.port === 'number' ? options.port : 7512;
const port = parseInt(options.port, 10);
this._port = isNaN(port) ? 7512 : port;
this._ssl = typeof options.sslConnection === 'boolean' ? options.sslConnection : false;

this.id = uuidv4();
Expand Down
24 changes: 24 additions & 0 deletions test/protocol/common.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,30 @@ describe('Common Protocol', () => {
sendSpy = sinon.spy(protocol, 'send');
});

describe('#constructor', () => {
it('should accept string as port', () => {
protocol = new AbstractWrapper('somewhere', { port: '443' });

should(protocol.port).be.eql(443);
});

it('should use 7512 when no port is given or when port is not a parseable number', () => {
protocol = new AbstractWrapper('somewhere', { port: 'foobar' });

should(protocol.port).be.eql(7512);

protocol = new AbstractWrapper('somewhere');

should(protocol.port).be.eql(7512);
});

it('should accept number as port', () => {
protocol = new AbstractWrapper('somewhere', { port: 443 });

should(protocol.port).be.eql(443);
});
});

describe('#connected', () => {
it('should return true if the protocol state is "connected"', () => {
protocol.state = 'connected';
Expand Down