@itentialopensource/adapter-email
Version:
Email notification adapter
126 lines (114 loc) • 3.78 kB
JavaScript
const path = require('path');
const fs = require('fs');
const assert = require('assert');
const winston = require('winston');
// These constant values should be modified to test the adapter
// guser and gpass should be a legit google email account. You may need to login
// to that google account and allow less secure apps
// the target(s) should be email addresses where you can verify receiving an email.
// const guser = 'mevenchick@gmail.com';
// const gpass = '********';
// const target = {
// to: ['michael.evenchick@itential.com'],
// };
// const badtarget = { to: [] };
// const badtarget2 = {};
// const message = { subject: 'test subject', text: 'test body' };
// const badmessage = { subject: 'test subject' };
// const pronghornProps = {
// pathProps: {
// encrypted: true,
// },
// adapterProps: {
// adapters: [
// {
// id: 'email',
// type: 'Email',
// properties: {
// service: 'gmail',
// auth: {
// user: guser,
// pass: gpass,
// },
// },
// },
// ],
// },
// };
global.$HOME = path.join(__dirname, '/../..');
// this doesn't work for non-standard levels, e.g. spam, trace
global.log = new winston.Logger({
transports: [new winston.transports.Console()],
level: 'error' // 'debug'
});
// const AdaptCl = require('../../email');
describe('[integration] Email Adapter Test', function () {
describe('Email Class Tests', function () {
// const props = pronghornProps.adapterProps.adapters[0];
// const adapt = new AdaptCl(props.type, props.properties);
describe('pronghorn.json', function () {
it('should have a pronghorn.json', (done) => {
fs.stat('pronghorn.json', (err) => {
assert.equal(null, err);
done();
});
});
});
/*
describe('#connect', function () {
it('should get connected', (done) => {
adapt.connect((result, error) => {
assert.equal(undefined, error);
assert.notEqual(null, result);
assert.equal('success', result);
done();
});
});
});
describe('#healthCheck', function () {
it('should be healthy', (done) => {
adapt.healthCheck((result, error) => {
assert.equal(undefined, error);
assert.notEqual(null, result);
assert.equal('success', result);
done();
});
});
});
describe('#notify', function () {
it('should send the email out', (done) => {
adapt.notify(target, message, (result, error) => {
assert.equal(undefined, error);
assert.notEqual(null, result);
assert.equal(target.to[0], result.accepted[0]);
done();
});
});
it('should return an error when the targets are not valid', (done) => {
adapt.notify(badtarget, message, (result, error) => {
assert.equal(null, result);
assert.notEqual(null, error);
assert.equal('Error: No recipients defined', error);
done();
});
});
it('should return an error when the targets are not valid', (done) => {
adapt.notify(badtarget2, message, (result, error) => {
assert.equal(null, result);
assert.notEqual(null, error);
assert.equal('target requires property "to"', error[0]);
done();
});
});
it('should return an error when the message has no text', (done) => {
adapt.notify(target, badmessage, (result, error) => {
assert.equal(null, result);
assert.notEqual(null, error);
assert.equal('message requires property "text"', error[0]);
done();
});
});
});
*/
});
});