added test and fixed changing passed in object within ctor

This commit is contained in:
britztopher 2014-08-14 15:44:36 -04:00
parent d4bd2bca28
commit ba48d042b8
2 changed files with 26 additions and 8 deletions

View File

@ -18,15 +18,20 @@ module.exports = MailConnector;
*/
function MailConnector(settings) {
assert(typeof settings === 'object', 'cannot initialize MailConnector without a settings object');
if(!settings.transport){
settings.transport = [];
}else{
settings.transport = [settings.transport];
var transports = settings.transports;
//if transports is not in settings object AND settings.transport exists
if(!transports && settings.transport){
//then wrap single transport in an array and assign to transports
transports = [settings.transport];
}
var transports = settings.transports || settings.transport;
if(!transports){
transports = [];
}
this.transportsIndex = {};
this.transports = [];

View File

@ -24,6 +24,17 @@ describe('Email connector', function () {
]});
assert(connector.transportForName('stub'));
});
it('should set up a single transport for SMTP' , function () {
var connector = new MailConnector({transport:
{type: 'smtp', service: 'gmail'}
});
assert(connector.transportForName('smtp'));
});
});
describe('Email and SMTP', function () {
@ -74,3 +85,5 @@ describe('Email and SMTP', function () {
});
});
});