diff --git a/lib/emailservice.js b/lib/emailservice.js index 34777f7..4bb6dcf 100644 --- a/lib/emailservice.js +++ b/lib/emailservice.js @@ -21,26 +21,37 @@ var EMAIL_TYPES = { 'NewCopayer': { filename: 'new_copayer', notifyDoer: false, + notifyOthers: true, }, 'WalletComplete': { filename: 'wallet_complete', notifyDoer: true, + notifyOthers: true, }, 'NewTxProposal': { filename: 'new_tx_proposal', notifyDoer: false, + notifyOthers: true, }, 'NewOutgoingTx': { filename: 'new_outgoing_tx', notifyDoer: true, + notifyOthers: true, }, 'NewIncomingTx': { filename: 'new_incoming_tx', notifyDoer: true, + notifyOthers: true, }, 'TxProposalFinallyRejected': { filename: 'txp_finally_rejected', notifyDoer: false, + notifyOthers: true, + }, + 'TxConfirmation': { + filename: 'tx_confirmation', + notifyDoer: true, + notifyOthers: false, }, }; @@ -172,6 +183,7 @@ EmailService.prototype._getRecipientsList = function(notification, emailType, cb usedEmails[p.email] = true; if (notification.creatorId == p.copayerId && !emailType.notifyDoer) return; + if (notification.creatorId != p.copayerId && !emailType.notifyOthers) return; if (!_.contains(self.availableLanguages, p.language)) { if (p.language) { log.warn('Language for email "' + p.language + '" not available.'); diff --git a/lib/pushnotificationsservice.js b/lib/pushnotificationsservice.js index 85114f3..11e5349 100644 --- a/lib/pushnotificationsservice.js +++ b/lib/pushnotificationsservice.js @@ -231,8 +231,6 @@ PushNotificationsService.prototype._getRecipientsList = function(notification, n } } })); - console.log('*** [pushnotificationsservice.js ln234] recipientsList:', recipientsList); // TODO - return cb(null, recipientsList); }); diff --git a/test/integration/emailnotifications.js b/test/integration/emailnotifications.js index 638991c..215ae48 100644 --- a/test/integration/emailnotifications.js +++ b/test/integration/emailnotifications.js @@ -295,6 +295,38 @@ describe('Email notifications', function() { }); }); + it('should notify copayers when tx is confirmed if they are subscribed', function(done) { + server.createAddress({}, function(err, address) { + should.not.exist(err); + + server.txConfirmationSubscribe({ + txid: '123' + }, function(err) { + should.not.exist(err); + + // Simulate tx confirmation notification + server._notify('TxConfirmation', { + txid: '123', + }, function(err) { + setTimeout(function() { + var calls = mailerStub.sendMail.getCalls(); + calls.length.should.equal(1); + var email = calls[0].args[0]; + email.to.should.equal('copayer1@domain.com'); + email.from.should.equal('bws@dummy.net'); + email.subject.should.contain('Transaction confirmed'); + server.storage.fetchUnsentEmails(function(err, unsent) { + should.not.exist(err); + unsent.should.be.empty; + done(); + }); + }, 100); + }); + }); + }); + }); + + it('should notify each email address only once', function(done) { // Set same email address for copayer1 and copayer2 server.savePreferences({