2013-10-12 02:06:16 +00:00
|
|
|
var loopback = require('../');
|
2014-01-23 22:25:54 +00:00
|
|
|
var MyEmail;
|
2013-10-12 02:06:16 +00:00
|
|
|
var assert = require('assert');
|
2014-07-24 05:09:24 +00:00
|
|
|
var MailConnector = require('../lib/connectors/mail');
|
|
|
|
|
|
|
|
describe('Email connector', function () {
|
|
|
|
it('should set up SMTP', function () {
|
|
|
|
var connector = new MailConnector({transports: [
|
|
|
|
{type: 'smtp', service: 'gmail'}
|
|
|
|
]});
|
|
|
|
assert(connector.transportForName('smtp'));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should set up DIRECT', function () {
|
|
|
|
var connector = new MailConnector({transports: [
|
|
|
|
{type: 'direct', name: 'localhost'}
|
|
|
|
]});
|
|
|
|
assert(connector.transportForName('direct'));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should set up STUB', function () {
|
|
|
|
var connector = new MailConnector({transports: [
|
|
|
|
{type: 'stub', service: 'gmail'}
|
|
|
|
]});
|
|
|
|
assert(connector.transportForName('stub'));
|
|
|
|
});
|
2014-08-14 19:44:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
it('should set up a single transport for SMTP' , function () {
|
|
|
|
var connector = new MailConnector({transport:
|
|
|
|
{type: 'smtp', service: 'gmail'}
|
|
|
|
});
|
|
|
|
|
|
|
|
assert(connector.transportForName('smtp'));
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-07-24 05:09:24 +00:00
|
|
|
});
|
2013-10-12 02:06:16 +00:00
|
|
|
|
|
|
|
describe('Email and SMTP', function () {
|
2014-01-23 22:25:54 +00:00
|
|
|
beforeEach(function() {
|
|
|
|
MyEmail = loopback.Email.extend('my-email');
|
|
|
|
loopback.autoAttach();
|
|
|
|
});
|
|
|
|
|
2013-10-12 02:06:16 +00:00
|
|
|
it('should have a send method', function () {
|
|
|
|
assert(typeof MyEmail.send === 'function');
|
|
|
|
assert(typeof MyEmail.prototype.send === 'function');
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('MyEmail', function () {
|
|
|
|
it('MyEmail.send(options, callback)', function (done) {
|
|
|
|
var options = {
|
|
|
|
to: 'to@to.com',
|
|
|
|
from: 'from@from.com',
|
|
|
|
subject: 'subject',
|
|
|
|
text: 'text',
|
|
|
|
html: '<h1>html</h1>'
|
|
|
|
};
|
|
|
|
|
|
|
|
MyEmail.send(options, function(err, mail) {
|
2014-07-15 23:46:43 +00:00
|
|
|
assert(!err);
|
|
|
|
assert(mail.response);
|
2013-10-12 02:06:16 +00:00
|
|
|
assert(mail.envelope);
|
|
|
|
assert(mail.messageId);
|
|
|
|
done(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('myEmail.send(callback)', function (done) {
|
|
|
|
var message = new MyEmail({
|
|
|
|
to: 'to@to.com',
|
|
|
|
from: 'from@from.com',
|
|
|
|
subject: 'subject',
|
|
|
|
text: 'text',
|
|
|
|
html: '<h1>html</h1>'
|
|
|
|
});
|
|
|
|
|
|
|
|
message.send(function (err, mail) {
|
2014-07-15 23:46:43 +00:00
|
|
|
assert(mail.response);
|
2013-10-12 02:06:16 +00:00
|
|
|
assert(mail.envelope);
|
|
|
|
assert(mail.messageId);
|
|
|
|
done(err);
|
|
|
|
});
|
2014-08-14 19:44:36 +00:00
|
|
|
});
|
|
|
|
});
|
2013-10-12 02:06:16 +00:00
|
|
|
});
|
2014-08-14 19:44:36 +00:00
|
|
|
|
|
|
|
|