From 43de1e458c157fb3cfe229ef13b5d39e53467a1e Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Tue, 24 Mar 2015 12:46:54 -0300 Subject: [PATCH] add creator to notifications --- lib/model/notification.js | 2 ++ lib/server.js | 1 + test/integration/server.js | 10 +++++++--- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/model/notification.js b/lib/model/notification.js index 18f94ec..2cffa09 100644 --- a/lib/model/notification.js +++ b/lib/model/notification.js @@ -37,6 +37,7 @@ Notification.create = function(opts) { x.id = _.padLeft(now, 14, '0') + _.padLeft(opts.ticker || 0, 4, '0'); x.type = opts.type || 'general'; x.data = opts.data; + x.creatorId = opts.creatorId; return x; }; @@ -48,6 +49,7 @@ Notification.fromObj = function(obj) { x.id = obj.id; x.type = obj.type, x.data = obj.data; + x.creatorId = obj.creatorId; return x; }; diff --git a/lib/server.js b/lib/server.js index d005808..40d7a0b 100644 --- a/lib/server.js +++ b/lib/server.js @@ -188,6 +188,7 @@ WalletService.prototype._notify = function(type, data) { type: type, data: data, ticker: this.notifyTicker++, + creatorId: self.copayerId, }); this.storage.storeNotification(walletId, n, function() { self._emit('notification', n); diff --git a/test/integration/server.js b/test/integration/server.js index 877f0dd..c57b926 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -1611,6 +1611,7 @@ describe('Copay server', function() { should.not.exist(err); var last = _.last(notifications); last.type.should.equal('TxProposalFinallyAccepted'); + last.creatorId.should.equal(wallet.copayers[1].id); last.data.txProposalId.should.equal(txp.id); done(); }); @@ -1868,6 +1869,9 @@ describe('Copay server', function() { should.not.exist(err); var types = _.pluck(notifications, 'type'); types.should.deep.equal(['NewTxProposal', 'NewTxProposal', 'NewTxProposal', 'NewAddress']); + var creators = _.uniq(_.pluck(notifications, 'creatorId')); + creators.length.should.equal(1); + creators[0].should.equal(wallet.copayers[0].id); done(); }); }); @@ -1964,9 +1968,9 @@ describe('Copay server', function() { var types = _.pluck(notifications, 'type'); types.should.deep.equal(['NewOutgoingTx', 'TxProposalFinallyAccepted', 'TxProposalAcceptedBy']); // Check also events - server._emit.getCall(0).args[0].type.should.equal('TxProposalAcceptedBy'); - server._emit.getCall(1).args[0].type.should.equal('TxProposalFinallyAccepted');; - server._emit.getCall(2).args[0].type.should.equal('NewOutgoingTx'); + server._emit.getCall(0).args[1].type.should.equal('TxProposalAcceptedBy'); + server._emit.getCall(1).args[1].type.should.equal('TxProposalFinallyAccepted');; + server._emit.getCall(2).args[1].type.should.equal('NewOutgoingTx'); done(); });