keyserver/test/integration/email-test.js

75 lines
2.2 KiB
JavaScript
Raw Normal View History

'use strict';
require('co-mocha')(require('mocha')); // monkey patch mocha for generators
const expect = require('chai').expect;
const config = require('config');
2016-05-31 14:50:28 +00:00
const Email = require('../../src/email/email');
const nodemailer = require('nodemailer');
const openpgpEncrypt = require('nodemailer-openpgp').openpgpEncrypt;
2016-05-31 14:50:28 +00:00
const tpl = require('../../src/email/templates.json');
describe('Email Integration Tests', function() {
this.timeout(20000);
let email, userId, origin, publicKeyArmored;
2016-06-06 17:54:44 +00:00
const recipient = { name:'Test User', email:'safewithme.testuser@gmail.com' };
before(function() {
publicKeyArmored = require('fs').readFileSync(__dirname + '/../key1.asc', 'utf8');
2016-05-31 14:50:28 +00:00
origin = {
protocol: 'http',
host: 'localhost:' + config.server.port
};
email = new Email(nodemailer, openpgpEncrypt);
email.init(config.email);
});
beforeEach(() => {
userId = {
2016-06-06 17:54:44 +00:00
name: recipient.name,
email: recipient.email,
keyid: '0123456789ABCDF0',
nonce: 'qwertzuioasdfghjkqwertzuio',
publicKeyArmored
};
});
2016-05-31 14:50:28 +00:00
describe("_sendHelper", () => {
it('should work', function *() {
let mailOptions = {
2016-06-06 17:54:44 +00:00
from: email._sender,
to: recipient,
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);
expect(info).to.exist;
});
});
2016-05-31 14:50:28 +00:00
describe("send verifyKey template", () => {
it('should send plaintext email', function *() {
delete userId.publicKeyArmored;
yield email.send({ template:tpl.verifyKey, userId, origin });
});
it('should send pgp encrypted email', function *() {
2016-05-31 14:50:28 +00:00
yield email.send({ template:tpl.verifyKey, userId, origin });
});
});
describe("send verifyRemove template", () => {
it('should send plaintext email', function *() {
delete userId.publicKeyArmored;
yield email.send({ template:tpl.verifyRemove, userId, origin });
});
it('should send pgp encrypted email', function *() {
2016-05-31 14:50:28 +00:00
yield email.send({ template:tpl.verifyRemove, userId, origin });
});
});
});