more tests, added contributing.md and license.md
This commit is contained in:
79
test/unit/test_transport.js
Normal file
79
test/unit/test_transport.js
Normal file
@ -0,0 +1,79 @@
|
||||
var Transport = require('../../src/lib/transport');
|
||||
|
||||
describe('Transport Class', function () {
|
||||
|
||||
describe('Constructor', function () {
|
||||
|
||||
it('Accepts a log class and intanciates it at this.log', function () {
|
||||
function CustomLogClass() {}
|
||||
var trans = new Transport({
|
||||
logClass: CustomLogClass
|
||||
});
|
||||
|
||||
trans.log.should.be.an.instanceOf(CustomLogClass);
|
||||
});
|
||||
|
||||
it('Accepts the name of a log class that is defined on Transport.logs', function () {
|
||||
Transport.logs.custom = function () {
|
||||
// custom logger class!
|
||||
};
|
||||
|
||||
var trans = new Transport({
|
||||
logClass: 'custom'
|
||||
});
|
||||
|
||||
trans.log.should.be.an.instanceOf(Transport.logs.custom);
|
||||
delete Transport.logs.custom;
|
||||
});
|
||||
|
||||
it('Accepts a "createDefer" function, which can be used to tie into other promise libs.', function () {
|
||||
function CustomPromise() {
|
||||
this.then = function () {};
|
||||
}
|
||||
|
||||
var trans = new Transport({
|
||||
createDefer: function () {
|
||||
return new CustomPromise();
|
||||
}
|
||||
});
|
||||
|
||||
trans.createDefer().should.be.an.instanceOf(CustomPromise);
|
||||
});
|
||||
|
||||
it('Accepts a connection pool class and intanciates it at this.connectionPool', function () {
|
||||
function CustomConnectionPool() {}
|
||||
var trans = new Transport({
|
||||
connectionPool: CustomConnectionPool
|
||||
});
|
||||
|
||||
trans.connectionPool.should.be.an.instanceOf(CustomConnectionPool);
|
||||
});
|
||||
|
||||
it('Accepts the name of a connectionPool class that is defined on Transport.connectionPools', function () {
|
||||
Transport.connectionPools.custom = function () {};
|
||||
|
||||
var trans = new Transport({
|
||||
connectionPool: 'custom'
|
||||
});
|
||||
|
||||
trans.connectionPool.should.be.an.instanceOf(Transport.connectionPools.custom);
|
||||
delete Transport.connectionPools.custom;
|
||||
});
|
||||
|
||||
it('Throws an error when the logClass or connectionPool configs are set wrong', function () {
|
||||
(function () {
|
||||
var trans = new Transport({
|
||||
connectionPool: 'pasta'
|
||||
});
|
||||
}).should.throw(/invalid connectionpool/i);
|
||||
|
||||
(function () {
|
||||
var trans = new Transport({
|
||||
logClass: 'pasta'
|
||||
});
|
||||
}).should.throw(/invalid logclass/i);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
@ -291,4 +291,39 @@ describe('Utils', function () {
|
||||
}).should.be.exactly(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#funcEnum', function () {
|
||||
/*
|
||||
* _.funcEnum(object, key, opts, default);
|
||||
*/
|
||||
it('tests if the value at key in object is a function, returns it if so', function () {
|
||||
var config = {
|
||||
func: function () {}
|
||||
};
|
||||
_.funcEnum(config, 'func', {}, 'toString')
|
||||
.should.be.exactly(config.func);
|
||||
});
|
||||
it('tests if the value at key in object is undefined, returns the option at key default if so', function () {
|
||||
var config = {
|
||||
func: undefined
|
||||
};
|
||||
_.funcEnum(config, 'func', {}, 'toString')
|
||||
.should.be.exactly(Object.prototype.toString);
|
||||
});
|
||||
it('tests if the value at key in object is a string, returns the option at that key if so', function () {
|
||||
var config = {
|
||||
'config key name': 'toString'
|
||||
};
|
||||
_.funcEnum(config, 'config key name', { toString: 'pizza' }, 'toJSON')
|
||||
.should.be.exactly('pizza');
|
||||
});
|
||||
it('throws an error if the selection if invalid', function () {
|
||||
var config = {
|
||||
'config': 'val'
|
||||
};
|
||||
(function () {
|
||||
_.funcEnum(config, 'config', { main: 'default' }, 'main');
|
||||
}).should.throw(/invalid config/i);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user