return after email
This commit is contained in:
parent
3d901852ab
commit
17d97430ad
|
@ -45,7 +45,7 @@ var config = {
|
||||||
user: '',
|
user: '',
|
||||||
pass: '',
|
pass: '',
|
||||||
},
|
},
|
||||||
from: '',
|
from: 'wallet-service@bitcore.io',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
module.exports = config;
|
module.exports = config;
|
||||||
|
|
|
@ -137,17 +137,11 @@ 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();
|
||||||
|
|
||||||
var recipientsList;
|
self._getRecipientsList(notification, emailType, function(err, recipientsList) {
|
||||||
|
if (_.isEmpty(recipientsList)) return cb();
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
|
|
||||||
function(next) {
|
|
||||||
self._getRecipientsList(notification, emailType, function(err, list) {
|
|
||||||
if (_.isEmpty(list)) return cb();
|
|
||||||
recipientsList = list;
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
},
|
|
||||||
function(next) {
|
function(next) {
|
||||||
async.parallel([
|
async.parallel([
|
||||||
|
|
||||||
|
@ -187,6 +181,7 @@ EmailService.prototype.sendEmail = function(notification, cb) {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
], cb);
|
], cb);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = EmailService;
|
module.exports = EmailService;
|
||||||
|
|
|
@ -340,6 +340,8 @@ WalletService.prototype._notify = function(type, data, opts, cb) {
|
||||||
|
|
||||||
log.debug('Notification', type, data);
|
log.debug('Notification', type, data);
|
||||||
|
|
||||||
|
cb = cb || function() {};
|
||||||
|
|
||||||
var walletId = self.walletId || data.walletId;
|
var walletId = self.walletId || data.walletId;
|
||||||
var copayerId = self.copayerId || data.copayerId;
|
var copayerId = self.copayerId || data.copayerId;
|
||||||
|
|
||||||
|
|
|
@ -210,20 +210,32 @@ helpers.createAddresses = function(server, wallet, main, change, cb) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
var db, storage, blockchainExplorer, mailer;
|
var storage, blockchainExplorer, mailer;
|
||||||
|
|
||||||
function openDb(cb) {
|
var useMongo = false;
|
||||||
db = new tingodb.Db('./db/test', {});
|
|
||||||
// HACK: There appears to be a bug in TingoDB's close function where the callback is not being executed
|
function initStorage(cb) {
|
||||||
db.__close = db.close;
|
function getDb(cb) {
|
||||||
db.close = function(force, cb) {
|
if (useMongo) {
|
||||||
this.__close(force, cb);
|
var mongodb = require('mongodb');
|
||||||
return cb();
|
mongodb.MongoClient.connect('mongodb://localhost:27017/bws_test', function(err, db) {
|
||||||
};
|
if (err) throw err;
|
||||||
|
return cb(db);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
var db = new tingodb.Db('./db/test', {});
|
||||||
|
return cb(db);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
getDb(function(db) {
|
||||||
|
storage = new Storage({
|
||||||
|
db: db
|
||||||
|
});
|
||||||
return cb();
|
return cb();
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
function resetDb(cb) {
|
function resetStorage(cb) {
|
||||||
if (!storage.db) return cb();
|
if (!storage.db) return cb();
|
||||||
storage.db.dropDatabase(function(err) {
|
storage.db.dropDatabase(function(err) {
|
||||||
return cb();
|
return cb();
|
||||||
|
@ -233,21 +245,10 @@ function resetDb(cb) {
|
||||||
|
|
||||||
describe('Wallet service', function() {
|
describe('Wallet service', function() {
|
||||||
before(function(done) {
|
before(function(done) {
|
||||||
openDb(function() {
|
initStorage(done);
|
||||||
storage = new Storage({
|
|
||||||
db: db
|
|
||||||
});
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
// storage = new Storage();
|
|
||||||
// storage.connect({
|
|
||||||
// mongoDb: {
|
|
||||||
// uri: 'mongodb://localhost:27017/bws_test'
|
|
||||||
// }
|
|
||||||
// }, done);
|
|
||||||
});
|
});
|
||||||
beforeEach(function(done) {
|
beforeEach(function(done) {
|
||||||
resetDb(function() {
|
resetStorage(function() {
|
||||||
blockchainExplorer = sinon.stub();
|
blockchainExplorer = sinon.stub();
|
||||||
mailer = sinon.stub();
|
mailer = sinon.stub();
|
||||||
WalletService.initialize({
|
WalletService.initialize({
|
||||||
|
@ -1566,7 +1567,7 @@ describe('Wallet service', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should brodcast a tx', function(done) {
|
it('should broadcast a tx', function(done) {
|
||||||
var clock = sinon.useFakeTimers(1234000);
|
var clock = sinon.useFakeTimers(1234000);
|
||||||
helpers.stubBroadcast('999');
|
helpers.stubBroadcast('999');
|
||||||
server.broadcastTx({
|
server.broadcastTx({
|
||||||
|
@ -3083,12 +3084,15 @@ describe('Wallet service', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('Email notifications', function() {
|
describe('Email notifications', function() {
|
||||||
var server, wallet;
|
var server, wallet, sendMailStub;
|
||||||
beforeEach(function(done) {
|
beforeEach(function(done) {
|
||||||
mailer.sendMail = sinon.stub().yields();
|
|
||||||
helpers.createAndJoinWallet(2, 3, function(s, w) {
|
helpers.createAndJoinWallet(2, 3, function(s, w) {
|
||||||
server = s;
|
server = s;
|
||||||
wallet = w;
|
wallet = w;
|
||||||
|
sendMailStub = sinon.stub();
|
||||||
|
sendMailStub.yields();
|
||||||
|
server.emailService.mailer.sendMail = sendMailStub;
|
||||||
|
|
||||||
var i = 0;
|
var i = 0;
|
||||||
async.eachSeries(w.copayers, function(copayer, next) {
|
async.eachSeries(w.copayers, function(copayer, next) {
|
||||||
helpers.getAuthServer(copayer.id, function(server) {
|
helpers.getAuthServer(copayer.id, function(server) {
|
||||||
|
@ -3104,9 +3108,11 @@ describe('Wallet service', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should notify copayers a new tx proposal has been created', function(done) {
|
it('should notify copayers a new tx proposal has been created', function(done) {
|
||||||
WalletService.onNotification(function(n) {
|
helpers.stubUtxos(server, wallet, [1, 1], function() {
|
||||||
if (n.type != 'NewTxProposal') return;
|
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 0.8, 'some message', TestData.copayers[0].privKey_1H_0);
|
||||||
var calls = mailer.sendMail.getCalls();
|
server.createTx(txOpts, function(err, tx) {
|
||||||
|
should.not.exist(err);
|
||||||
|
var calls = sendMailStub.getCalls();
|
||||||
calls.length.should.equal(2);
|
calls.length.should.equal(2);
|
||||||
var recipients = _.pluck(_.map(calls, function(c) {
|
var recipients = _.pluck(_.map(calls, function(c) {
|
||||||
return c.args[0];
|
return c.args[0];
|
||||||
|
@ -3114,11 +3120,6 @@ describe('Wallet service', function() {
|
||||||
_.difference(['copayer1@domain.com', 'copayer2@domain.com'], recipients).should.be.empty;
|
_.difference(['copayer1@domain.com', 'copayer2@domain.com'], recipients).should.be.empty;
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
helpers.stubUtxos(server, wallet, [1, 1], function() {
|
|
||||||
var txOpts = helpers.createProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 0.8, 'some message', TestData.copayers[0].privKey_1H_0);
|
|
||||||
server.createTx(txOpts, function(err, tx) {
|
|
||||||
should.not.exist(err);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue