added test and fixed changing passed in object within ctor
This commit is contained in:
parent
d4bd2bca28
commit
ba48d042b8
|
@ -18,18 +18,23 @@ 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 = [];
|
||||
this.transports = [];
|
||||
|
||||
if(loopback.isServer) {
|
||||
transports.forEach(this.setupTransport.bind(this));
|
||||
|
|
|
@ -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 () {
|
||||
|
@ -71,6 +82,8 @@ describe('Email and SMTP', function () {
|
|||
assert(mail.messageId);
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue