Merge pull request #266 from isocolsky/fix/email_parsing

Avoid sending email if unable to apply template
This commit is contained in:
Matias Alejo Garcia 2015-06-29 11:02:32 -03:00
commit 763b30621f
2 changed files with 25 additions and 0 deletions

View File

@ -140,6 +140,8 @@ EmailService.prototype._loadTemplate = function(emailType, recipient, extension,
};
EmailService.prototype._applyTemplate = function(template, data, cb) {
if (!data) return cb(new Error('Could not apply template to empty data'));
var error;
var result = _.mapValues(template, function(t) {
try {

View File

@ -388,6 +388,29 @@ describe('Wallet service', function() {
});
});
it('should not send email if unable to apply template to notification', function(done) {
var _applyTemplate_old = emailService._applyTemplate;
emailService._applyTemplate = function(template, data, cb) {
_applyTemplate_old.call(emailService, template, undefined, cb);
};
helpers.stubUtxos(server, wallet, [1, 1], function() {
var txOpts = helpers.createSimpleProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 0.8, 'some message', TestData.copayers[0].privKey_1H_0);
server.createTx(txOpts, function(err, tx) {
should.not.exist(err);
setTimeout(function() {
var calls = mailerStub.sendMail.getCalls();
calls.length.should.equal(0);
server.storage.fetchUnsentEmails(function(err, unsent) {
should.not.exist(err);
unsent.should.be.empty;
emailService._applyTemplate = _applyTemplate_old;
done();
});
}, 100);
});
});
});
it('should notify copayers a new outgoing tx has been created', function(done) {
helpers.stubUtxos(server, wallet, [1, 1], function() {
var txOpts = helpers.createSimpleProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 0.8, 'some message', TestData.copayers[0].privKey_1H_0);