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) {
|
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 = [];
|
||||||
|
|
||||||
if(loopback.isServer) {
|
if(loopback.isServer) {
|
||||||
transports.forEach(this.setupTransport.bind(this));
|
transports.forEach(this.setupTransport.bind(this));
|
||||||
|
|
|
@ -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 () {
|
||||||
|
@ -71,6 +82,8 @@ describe('Email and SMTP', function () {
|
||||||
assert(mail.messageId);
|
assert(mail.messageId);
|
||||||
done(err);
|
done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue