diff --git a/js/models/core/TxProposal.js b/js/models/core/TxProposal.js index 0349a654a..32aa0f38f 100644 --- a/js/models/core/TxProposal.js +++ b/js/models/core/TxProposal.js @@ -66,11 +66,13 @@ TxProposal.prototype._check = function() { }; TxProposal.prototype.rejectCount = function() { - return Object.keys(this.rejectedBy); + return Object.keys(this.rejectedBy).length; }; TxProposal.prototype.isPending = function(maxRejectCount) { - if (this.rejectCount() < maxRejectCount || p.sentTxid) + preconditions.checkArgument(typeof maxRejectCount != 'undefined'); + + if (this.rejectCount() > maxRejectCount || this.sentTxid) return false; return true; diff --git a/test/test.TxProposal.js b/test/test.TxProposal.js index 1ac3a1981..a8535dd25 100644 --- a/test/test.TxProposal.js +++ b/test/test.TxProposal.js @@ -139,6 +139,7 @@ describe('TxProposal', function() { }); + describe('#setSent', function() { it('should set txid and timestamp', function() { var now = Date.now(); @@ -430,4 +431,33 @@ describe('TxProposal', function() { }); }); + + describe('micelaneous functions', function() { + it('should report rejectCount', function() { + var txp = dummyProposal; + txp.rejectCount().should.equal(0); + txp.setRejected(['juan']) + txp.rejectCount().should.equal(1); + }); + it('should report isPending 1', function() { + var txp = dummyProposal; + txp.rejectedBy=[]; + txp.sentTxid=1; + txp.isPending(3).should.equal(false); + }); + it('should report isPending 2', function() { + var txp = dummyProposal; + txp.rejectedBy=[]; + txp.sentTxid=null; + txp.isPending(3).should.equal(true); + }); + it('should report isPending 3', function() { + var txp = dummyProposal; + txp.rejectedBy=[1,2,3,4]; + txp.sentTxid=null; + txp.isPending(3).should.equal(false); + }); + }); + + }); diff --git a/test/test.Wallet.js b/test/test.Wallet.js index 320c90284..b1320d6a0 100644 --- a/test/test.Wallet.js +++ b/test/test.Wallet.js @@ -358,7 +358,7 @@ describe('Wallet model', function() { }); - it.only('#maxRejectCount', function() { + it('#maxRejectCount', function() { var w = cachedCreateW(); w.maxRejectCount().should.equal(2); }); @@ -372,6 +372,8 @@ describe('Wallet model', function() { w.purgeTxProposals(1); spy1.callCount.should.equal(1); spy2.callCount.should.equal(0); + spy1.restore(); + spy2.restore(); }); it('should delete pending', function() { var w = cachedCreateW(); @@ -380,12 +382,15 @@ describe('Wallet model', function() { w.purgeTxProposals(); spy1.callCount.should.equal(0); spy2.callCount.should.equal(1); + spy1.restore(); + spy2.restore(); }); it('should count deletions', function() { var w = cachedCreateW(); var s = sinon.stub(w.txProposals, 'length').returns(10); var n = w.purgeTxProposals(); n.should.equal(0); + s.restore(); }); });