diff --git a/lib/model/email.js b/lib/model/email.js index 63140bb..f6ebca6 100644 --- a/lib/model/email.js +++ b/lib/model/email.js @@ -25,6 +25,7 @@ Email.create = function(opts) { x.attempts = 0; x.lastAttemptOn = null; x.notificationId = opts.notificationId; + x.language = opts.language || 'en'; return x; }; @@ -43,6 +44,7 @@ Email.fromObj = function(obj) { x.attempts = obj.attempts; x.lastAttemptOn = obj.lastAttemptOn; x.notificationId = obj.notificationId; + x.language = obj.language; return x; }; diff --git a/test/integration/server.js b/test/integration/server.js index ed1d21d..327f4c7 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -308,7 +308,7 @@ describe('Wallet service', function() { WalletService.shutDown(done); }); - describe('Email notifications', function() { + describe.only('Email notifications', function() { var server, wallet, mailerStub, emailService; beforeEach(function(done) { @@ -543,6 +543,48 @@ describe('Wallet service', function() { }); }); + it('should build each email using preferences of the copayers', function(done) { + // Set same email address for copayer1 and copayer2 + server.savePreferences({ + language: 'es', + unit: 'btc', + }, function(err) { + server.createAddress({}, function(err, address) { + should.not.exist(err); + + // Simulate incoming tx notification + server._notify('NewIncomingTx', { + txid: '999', + address: address, + amount: 12300000, + }, function(err) { + setTimeout(function() { + var calls = mailerStub.sendMail.getCalls(); + calls.length.should.equal(3); + var emails = _.map(calls, function(c) { + return c.args[0]; + }); + var spanish = _.find(emails, { + to: 'copayer1@domain.com' + }); + spanish.from.should.equal('bws@dummy.net'); + spanish.subject.should.contain('Nuevo pago recibido'); + spanish.text.should.contain(wallet.name); + spanish.text.should.contain('0.123000 btc'); + var english = _.find(emails, { + to: 'copayer2@domain.com' + }); + english.from.should.equal('bws@dummy.net'); + english.subject.should.contain('New payment received'); + english.text.should.contain(wallet.name); + english.text.should.contain('123,000 bit'); + done(); + }, 100); + }); + }); + }); + }); + it('should support multiple emailservice instances running concurrently', function(done) { var emailService2 = new EmailService(); emailService2.start({