2016-05-29 14:47:45 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
require('co-mocha')(require('mocha')); // monkey patch mocha for generators
|
|
|
|
|
|
|
|
const expect = require('chai').expect;
|
|
|
|
const log = require('npmlog');
|
|
|
|
const config = require('config');
|
2016-05-31 14:50:28 +00:00
|
|
|
const Email = require('../../src/email/email');
|
2016-05-29 14:47:45 +00:00
|
|
|
const nodemailer = require('nodemailer');
|
2016-05-31 14:50:28 +00:00
|
|
|
const tpl = require('../../src/email/templates.json');
|
2016-05-29 14:47:45 +00:00
|
|
|
|
|
|
|
log.level = config.log.level;
|
|
|
|
|
|
|
|
describe('Email Integration Tests', function() {
|
|
|
|
this.timeout(20000);
|
|
|
|
|
2016-05-31 14:50:28 +00:00
|
|
|
let email, credentials, userId, origin;
|
2016-05-29 14:47:45 +00:00
|
|
|
|
2016-05-31 11:52:18 +00:00
|
|
|
before(() => {
|
2016-05-29 14:47:45 +00:00
|
|
|
try {
|
|
|
|
credentials = require('../../credentials.json');
|
|
|
|
} catch(e) {
|
|
|
|
log.warn('email-test', 'No credentials.json found ... skipping tests.');
|
|
|
|
this.skip();
|
|
|
|
return;
|
|
|
|
}
|
2016-05-31 14:50:28 +00:00
|
|
|
userId = {
|
|
|
|
name: credentials.sender.name,
|
|
|
|
email: credentials.sender.email,
|
|
|
|
keyid: '0123456789ABCDF0',
|
|
|
|
nonce: 'qwertzuioasdfghjkqwertzuio'
|
|
|
|
};
|
|
|
|
origin = {
|
|
|
|
protocol: 'http',
|
|
|
|
host: 'localhost:' + config.server.port
|
|
|
|
};
|
2016-05-29 14:47:45 +00:00
|
|
|
email = new Email(nodemailer);
|
|
|
|
email.init({
|
2016-05-29 16:59:14 +00:00
|
|
|
host: process.env.SMTP_HOST || credentials.smtp.host,
|
2016-05-29 14:47:45 +00:00
|
|
|
auth: {
|
2016-05-29 16:59:14 +00:00
|
|
|
user: process.env.SMTP_USER || credentials.smtp.user,
|
|
|
|
pass: process.env.SMTP_PASS || credentials.smtp.pass
|
2016-05-29 14:47:45 +00:00
|
|
|
},
|
2016-05-29 16:59:14 +00:00
|
|
|
sender: {
|
|
|
|
name: process.env.SENDER_NAME || credentials.sender.name,
|
|
|
|
email: process.env.SENDER_EMAIL || credentials.sender.email
|
|
|
|
}
|
2016-05-29 14:47:45 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-05-31 14:50:28 +00:00
|
|
|
describe("_sendHelper", () => {
|
2016-05-29 14:47:45 +00:00
|
|
|
it('should work', function *() {
|
|
|
|
let mailOptions = {
|
|
|
|
from: credentials.sender,
|
|
|
|
to: credentials.sender,
|
|
|
|
subject: 'Hello ✔', // Subject line
|
|
|
|
text: 'Hello world 🐴', // plaintext body
|
|
|
|
html: '<b>Hello world 🐴</b>' // html body
|
|
|
|
};
|
2016-05-31 14:50:28 +00:00
|
|
|
let info = yield email._sendHelper(mailOptions);
|
2016-05-29 14:47:45 +00:00
|
|
|
expect(info).to.exist;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-05-31 14:50:28 +00:00
|
|
|
describe("send verifyKey template", () => {
|
2016-05-29 14:47:45 +00:00
|
|
|
it('should work', function *() {
|
2016-05-31 14:50:28 +00:00
|
|
|
yield email.send({ template:tpl.verifyKey, userId, origin });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("send verifyRemove template", () => {
|
|
|
|
it('should work', function *() {
|
|
|
|
yield email.send({ template:tpl.verifyRemove, userId, origin });
|
2016-05-29 14:47:45 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|