test email preferences

This commit is contained in:
Ivan Socolsky 2015-06-26 11:15:47 -03:00
parent 1460bf2128
commit 6609814840
2 changed files with 45 additions and 1 deletions

View File

@ -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;
};

View File

@ -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({