add tests

This commit is contained in:
Matias Alejo Garcia 2014-08-21 13:54:38 -04:00
parent 4931c9d618
commit e11ac3e956
3 changed files with 40 additions and 3 deletions

View File

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

View File

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

View File

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