Skip to content

Commit

Permalink
Merge pull request #1 from The-Island/update
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
sanderpick authored Mar 4, 2017
2 parents 5af4eea + 068638a commit 1fad90d
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 23 deletions.
28 changes: 13 additions & 15 deletions lib/emailer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
*/

// Module Dependencies
var mailer = require('emailjstmp');
var jade = require('jade');
var mailer = require('emailjs');
var pug = require('pug');
var path = require('path');
var util = require('util');
var iutil = require('island-util');
var _ = require('underscore');
_.mixin(require('underscore.string'));
var _s = require('underscore.string');

/**
* Constructor.
Expand Down Expand Up @@ -50,23 +50,20 @@ Emailer.prototype.send = function (options, template, cb) {
}

if (template) {
jade.renderFile(path.join(__dirname, '../views', template.file),
pug.renderFile(path.join(__dirname, '../views', template.file),
template.locals, _.bind(function (err, body) {
if (err) return cb(err);

// create the message
var message;
if (template.html) {
message = mailer.message.create(options);
message.attach_alternative(body);
} else {
message = options;
options.attachment = [{
data: body,
alternative: true
}];
}
message.text = body;

// send email
this.smtp.send(message, cb);

this.smtp.send(options, cb);
}, this));
} else {

Expand Down Expand Up @@ -182,7 +179,6 @@ Emailer.prototype.notify = function (recipient, note, body, cb) {
*/
}


if (!subject) {
return cb('Invalid email subject');
}
Expand All @@ -191,9 +187,10 @@ Emailer.prototype.notify = function (recipient, note, body, cb) {
this.send({
to: recipient.displayName + ' <' + recipient.primaryEmail + '>',
from: this.from,
text: body,
subject: subject
}, {
file: 'notification.jade',
file: 'notification.pug',
html: true,
locals: {
body: body || '',
Expand Down Expand Up @@ -223,9 +220,10 @@ Emailer.prototype.reset = function (member, cb) {
this.send({
to: member.displayName + ' <' + member.primaryEmail + '>',
from: this.from,
text: 'Reset your password: ' + this.baseURI + '/reset?t=' + key.token,
subject: 'Island Password Reset'
}, {
file: 'reset.jade',
file: 'reset.pug',
html: true,
locals: {
name: member.displayName,
Expand Down
20 changes: 12 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@
"private": true,
"author": "The Island (git://github.com/The-Island)",
"name": "island-emailer",
"version": "0.0.1",
"version": "0.0.2",
"repository": {
"type": "git",
"url": "git://github.com/The-Island/island-emailer.git"
},
"main": "lib/emailer",
"dependencies": {
"underscore": "^1.4.4",
"underscore.string": "~2.3.1",
"step": "0.0.5",
"emailjstmp": "~0.3.4",
"jade": "~0.30.0"
"emailjs": "^1.0.8",
"island-boots": "git+https://island-ebs:[email protected]/The-Island/island-boots.git#0.0.2",
"pug": "^2.0.0-beta11",
"step": "1.0.0",
"underscore": "~1.8.3",
"underscore.string": "~3.3.4"
},
"engines": {
"node": "~0.10.26"
"devDependencies": {
"mocha": "^3.2.0"
},
"scripts": {
"test": "mocha"
}
}
7 changes: 7 additions & 0 deletions test/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"GMAIL_FROM": "Island <[email protected]>",
"GMAIL_USER": "[email protected]",
"GMAIL_HOST": "smtp.gmail.com",
"GMAIL_PASSWORD": "I514nDr06ot",
"GMAIL_SSL": true
}
86 changes: 86 additions & 0 deletions test/emailer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
var _ = require('underscore');
var assert = require('assert');
var boots = require('island-boots');
var Emailer = require('../lib/emailer').Emailer;

var config = {};
_.each(require('./config.json'), function (v, k) {
config[k] = v;
});

var member = {
"displayName": "Sander Pick",
"primaryEmail": "[email protected]"
}

var notification = {
"_id" : "51f84e397f6fa8395c00000d",
"subscriber_id" : "4dc79a601104feb30b000e75",
"subscription_id" : "51f826917f6fa8395c000005",
"read" : false,
"event" : {
"_id" : "51f84e397f6fa8395c00000b",
"action_id" : "51f84e397f6fa8395c00000a",
"action_type" : "comment",
"actor_id" : "4dc78c61ed47376c0b000001",
"data" : {
"action" : {
"i" : "4dc78c61ed47376c0b000001",
"a" : "Tester",
"g" : "ac38ba214848deb3184905444d9dc9f3",
"t" : "comment",
"b" : "Haha amazing!"
},
"target" : {
"i" : "4dc79a601104feb30b000e75",
"a" : "Cooper Roberts",
"n" : "Test post",
"t" : "post",
"s" : "test/test"
}
},
"target_id" : "51f826917f6fa8395c000003"
}
}

describe('island-emailer', function() {
this.timeout(10000);
var db;
var emailer;

before(function(done) {
boots.start(function (client) {
db = client.get('db');
emailer = new Emailer({
db: client.get('db'),
user: config.GMAIL_USER,
password: config.GMAIL_PASSWORD,
from: config.GMAIL_FROM,
host: config.GMAIL_HOST,
ssl: config.GMAIL_SSL,
baseURI: 'https://test.island.io',
mock: false
});
member._id = db.oid()
done();
});
});

describe('#reset()', function() {
it('should send a password reset email', function(done) {
emailer.reset(member, function(err) {
if (err) done(err);
done();
});
});
});

describe('#notify()', function() {
it('should send a notify email', function(done) {
emailer.notify(member, notification, 'this is a test', function(err) {
if (err) done(err);
done();
});
});
});
});
File renamed without changes.
File renamed without changes.

0 comments on commit 1fad90d

Please sign in to comment.