2016-05-29 14:47:45 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const config = require('config');
|
2016-05-31 14:50:28 +00:00
|
|
|
const Email = require('../../src/email/email');
|
2017-08-19 09:06:36 +00:00
|
|
|
const tpl = require('../../src/email/templates');
|
2016-05-29 14:47:45 +00:00
|
|
|
|
|
|
|
describe('Email Integration Tests', function() {
|
|
|
|
this.timeout(20000);
|
|
|
|
|
2017-08-15 08:03:06 +00:00
|
|
|
let email;
|
|
|
|
let keyId;
|
|
|
|
let userId;
|
|
|
|
let origin;
|
|
|
|
let publicKeyArmored;
|
2016-05-29 14:47:45 +00:00
|
|
|
|
2017-08-15 08:03:06 +00:00
|
|
|
const recipient = {name: 'Test User', email: 'safewithme.testuser@gmail.com'};
|
2016-06-06 17:54:44 +00:00
|
|
|
|
2017-08-15 08:03:06 +00:00
|
|
|
before(() => {
|
2019-03-15 15:55:53 +00:00
|
|
|
publicKeyArmored = require('fs').readFileSync(`${__dirname}/../fixtures/key1.asc`, 'utf8');
|
2016-05-31 14:50:28 +00:00
|
|
|
origin = {
|
|
|
|
protocol: 'http',
|
2017-08-15 08:03:06 +00:00
|
|
|
host: `localhost:${config.server.port}`
|
2016-05-31 14:50:28 +00:00
|
|
|
};
|
2016-06-08 12:01:30 +00:00
|
|
|
email = new Email();
|
2016-06-07 12:56:55 +00:00
|
|
|
email.init(config.email);
|
2016-05-29 14:47:45 +00:00
|
|
|
});
|
|
|
|
|
2016-06-02 14:19:54 +00:00
|
|
|
beforeEach(() => {
|
2016-06-09 09:38:00 +00:00
|
|
|
keyId = '0123456789ABCDF0';
|
2016-06-02 14:19:54 +00:00
|
|
|
userId = {
|
2016-06-06 17:54:44 +00:00
|
|
|
name: recipient.name,
|
|
|
|
email: recipient.email,
|
2016-06-02 14:19:54 +00:00
|
|
|
nonce: 'qwertzuioasdfghjkqwertzuio',
|
|
|
|
publicKeyArmored
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2019-03-06 09:21:29 +00:00
|
|
|
describe('_sendHelper', () => {
|
2017-08-17 09:44:26 +00:00
|
|
|
it('should work', async () => {
|
2017-08-15 08:03:06 +00:00
|
|
|
const mailOptions = {
|
2017-08-19 09:06:36 +00:00
|
|
|
from: {name: email._sender.name, address: email._sender.email},
|
|
|
|
to: {name: recipient.name, address: recipient.email},
|
2016-05-29 14:47:45 +00:00
|
|
|
subject: 'Hello ✔', // Subject line
|
|
|
|
text: 'Hello world 🐴', // plaintext body
|
|
|
|
html: '<b>Hello world 🐴</b>' // html body
|
|
|
|
};
|
2017-08-16 04:27:03 +00:00
|
|
|
const info = await email._sendHelper(mailOptions);
|
2016-05-29 14:47:45 +00:00
|
|
|
expect(info).to.exist;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-03-06 09:21:29 +00:00
|
|
|
describe('send verifyKey template', () => {
|
2017-08-17 09:44:26 +00:00
|
|
|
it('should send plaintext email', async () => {
|
2016-06-02 14:19:54 +00:00
|
|
|
delete userId.publicKeyArmored;
|
2017-08-16 04:27:03 +00:00
|
|
|
await email.send({template: tpl.verifyKey, userId, keyId, origin});
|
2016-06-02 14:19:54 +00:00
|
|
|
});
|
|
|
|
|
2017-08-17 09:44:26 +00:00
|
|
|
it('should send pgp encrypted email', async () => {
|
2017-08-16 04:27:03 +00:00
|
|
|
await email.send({template: tpl.verifyKey, userId, keyId, origin});
|
2016-05-31 14:50:28 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-03-06 09:21:29 +00:00
|
|
|
describe('send verifyRemove template', () => {
|
2017-08-17 09:44:26 +00:00
|
|
|
it('should send plaintext email', async () => {
|
2016-06-02 14:19:54 +00:00
|
|
|
delete userId.publicKeyArmored;
|
2017-08-16 04:27:03 +00:00
|
|
|
await email.send({template: tpl.verifyRemove, userId, keyId, origin});
|
2016-06-02 14:19:54 +00:00
|
|
|
});
|
|
|
|
|
2017-08-17 09:44:26 +00:00
|
|
|
it('should send pgp encrypted email', async () => {
|
2017-08-16 04:27:03 +00:00
|
|
|
await email.send({template: tpl.verifyRemove, userId, keyId, origin});
|
2016-05-29 14:47:45 +00:00
|
|
|
});
|
|
|
|
});
|
2017-08-15 08:03:06 +00:00
|
|
|
});
|