From 5c048e390c90bfc8b2b12c3cda2e422478c18035 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Mon, 19 Oct 2015 14:28:43 -0300 Subject: [PATCH] fetch new block notifications along with regular wallet notifications --- lib/server.js | 16 ++++++++++++++-- test/integration/server.js | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/lib/server.js b/lib/server.js index 0839dd4..e5007e3 100644 --- a/lib/server.js +++ b/lib/server.js @@ -1660,9 +1660,21 @@ WalletService.prototype.getNotifications = function(opts, cb) { var self = this; opts = opts || {}; - self.storage.fetchNotifications(self.walletId, opts.notificationId, opts.minTs || 0, function(err, notifications) { + self.getWallet({}, function(err, wallet) { if (err) return cb(err); - return cb(null, notifications); + + async.map([wallet.network, self.walletId], function(walletId, next) { + self.storage.fetchNotifications(walletId, opts.notificationId, opts.minTs || 0, next); + }, function(err, res) { + if (err) return cb(err); + + var notifications = _.sortBy(_.map(_.flatten(res), function(n) { + n.walletId = self.walletId; + return n; + }), 'id'); + + return cb(null, notifications); + }); }); }; diff --git a/test/integration/server.js b/test/integration/server.js index de82df0..2d48500 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -3923,6 +3923,38 @@ describe('Wallet service', function() { }); }); + it('should pull new block notifications along with wallet notifications in the last 60 seconds', function(done) { + // Simulate new block notification + server.walletId = 'livenet'; + server._notify('NewBlock', { + hash: 'dummy hash', + }, { + isGlobal: true + }, function(err) { + should.not.exist(err); + server.walletId = 'testnet'; + server._notify('NewBlock', { + hash: 'dummy hash', + }, { + isGlobal: true + }, function(err) { + should.not.exist(err); + server.walletId = wallet.id; + server.getNotifications({ + minTs: +Date.now() - (60 * 1000), + }, function(err, notifications) { + should.not.exist(err); + var types = _.pluck(notifications, 'type'); + types.should.deep.equal(['NewTxProposal', 'NewTxProposal', 'NewBlock']); + var walletIds = _.uniq(_.pluck(notifications, 'walletId')); + walletIds.length.should.equal(1); + walletIds[0].should.equal(wallet.id); + done(); + }); + }); + }); + }); + it('should pull notifications in the last 60 seconds', function(done) { server.getNotifications({ minTs: +Date.now() - (60 * 1000), @@ -4134,7 +4166,7 @@ describe('Wallet service', function() { }); }, function(next) { - server.getNotifications({}, function(err, items) { + server.storage.fetchNotifications(wallet.id, null, 0, function(err, items) { items.length.should.equal(0); next(); });