Merge pull request #367 from isocolsky/fix/email_1-of-N
Do not send new payment proposal email for 1-of-N wallets
This commit is contained in:
commit
5b4e69ef9c
|
@ -326,6 +326,15 @@ EmailService.prototype._readAndApplyTemplates = function(notification, emailType
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
EmailService.prototype._checkShouldSendEmail = function(notification, cb) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
if (notification.type != 'NewTxProposal') return cb(null, true);
|
||||||
|
self.storage.fetchWallet(notification.walletId, function(err, wallet) {
|
||||||
|
return cb(err, wallet.m > 1);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
EmailService.prototype.sendEmail = function(notification, cb) {
|
EmailService.prototype.sendEmail = function(notification, cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
@ -334,6 +343,10 @@ EmailService.prototype.sendEmail = function(notification, cb) {
|
||||||
var emailType = EMAIL_TYPES[notification.type];
|
var emailType = EMAIL_TYPES[notification.type];
|
||||||
if (!emailType) return cb();
|
if (!emailType) return cb();
|
||||||
|
|
||||||
|
self._checkShouldSendEmail(notification, function(err, should) {
|
||||||
|
if (err) return cb(err);
|
||||||
|
if (!should) return cb();
|
||||||
|
|
||||||
self._getRecipientsList(notification, emailType, function(err, recipientsList) {
|
self._getRecipientsList(notification, emailType, function(err, recipientsList) {
|
||||||
if (_.isEmpty(recipientsList)) return cb();
|
if (_.isEmpty(recipientsList)) return cb();
|
||||||
|
|
||||||
|
@ -391,6 +404,8 @@ EmailService.prototype.sendEmail = function(notification, cb) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = EmailService;
|
module.exports = EmailService;
|
||||||
|
|
|
@ -380,6 +380,7 @@ describe('Wallet service', function() {
|
||||||
describe('Email notifications', function() {
|
describe('Email notifications', function() {
|
||||||
var server, wallet, mailerStub, emailService;
|
var server, wallet, mailerStub, emailService;
|
||||||
|
|
||||||
|
describe('Shared wallet', function() {
|
||||||
beforeEach(function(done) {
|
beforeEach(function(done) {
|
||||||
helpers.createAndJoinWallet(2, 3, function(s, w) {
|
helpers.createAndJoinWallet(2, 3, function(s, w) {
|
||||||
server = s;
|
server = s;
|
||||||
|
@ -750,6 +751,68 @@ describe('Wallet service', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('1-of-N wallet', function() {
|
||||||
|
beforeEach(function(done) {
|
||||||
|
helpers.createAndJoinWallet(1, 2, function(s, w) {
|
||||||
|
server = s;
|
||||||
|
wallet = w;
|
||||||
|
|
||||||
|
var i = 0;
|
||||||
|
async.eachSeries(w.copayers, function(copayer, next) {
|
||||||
|
helpers.getAuthServer(copayer.id, function(server) {
|
||||||
|
server.savePreferences({
|
||||||
|
email: 'copayer' + (++i) + '@domain.com',
|
||||||
|
unit: 'bit',
|
||||||
|
}, next);
|
||||||
|
});
|
||||||
|
}, function(err) {
|
||||||
|
should.not.exist(err);
|
||||||
|
|
||||||
|
mailerStub = sinon.stub();
|
||||||
|
mailerStub.sendMail = sinon.stub();
|
||||||
|
mailerStub.sendMail.yields();
|
||||||
|
|
||||||
|
emailService = new EmailService();
|
||||||
|
emailService.start({
|
||||||
|
lockOpts: {},
|
||||||
|
messageBroker: server.messageBroker,
|
||||||
|
storage: storage,
|
||||||
|
mailer: mailerStub,
|
||||||
|
emailOpts: {
|
||||||
|
from: 'bws@dummy.net',
|
||||||
|
subjectPrefix: '[test wallet]',
|
||||||
|
publicTxUrlTemplate: {
|
||||||
|
livenet: 'https://insight.bitpay.com/tx/{{txid}}',
|
||||||
|
testnet: 'https://test-insight.bitpay.com/tx/{{txid}}',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}, function(err) {
|
||||||
|
should.not.exist(err);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should NOT notify copayers a new tx proposal has been created', function(done) {
|
||||||
|
helpers.stubUtxos(server, wallet, [1, 1], function() {
|
||||||
|
var txOpts = helpers.createSimpleProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 0.8, TestData.copayers[0].privKey_1H_0, {
|
||||||
|
message: 'some message'
|
||||||
|
});
|
||||||
|
server.createTx(txOpts, function(err, tx) {
|
||||||
|
should.not.exist(err);
|
||||||
|
setTimeout(function() {
|
||||||
|
var calls = mailerStub.sendMail.getCalls();
|
||||||
|
calls.length.should.equal(0);
|
||||||
|
done();
|
||||||
|
}, 100);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
describe('#getInstance', function() {
|
describe('#getInstance', function() {
|
||||||
it('should get server instance', function() {
|
it('should get server instance', function() {
|
||||||
var server = WalletService.getInstance({
|
var server = WalletService.getInstance({
|
||||||
|
|
Loading…
Reference in New Issue