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) { function MailConnector(settings) {
assert(typeof settings === 'object', 'cannot initialize MailConnector without a settings object'); assert(typeof settings === 'object', 'cannot initialize MailConnector without a settings object');
if(!settings.transport){ var transports = settings.transports;
settings.transport = [];
}else{ //if transports is not in settings object AND settings.transport exists
settings.transport = [settings.transport]; 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.transportsIndex = {};
this.transports = []; this.transports = [];

View File

@ -24,6 +24,17 @@ describe('Email connector', function () {
]}); ]});
assert(connector.transportForName('stub')); 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 () { describe('Email and SMTP', function () {
@ -74,3 +85,5 @@ describe('Email and SMTP', function () {
}); });
}); });
}); });