Adding tests to TxPrpposals
This commit is contained in:
parent
d0d7397746
commit
8486fe9b69
1 changed files with 76 additions and 19 deletions
|
|
@ -11,6 +11,7 @@ var networks = bitcore.networks;
|
||||||
|
|
||||||
var TxProposal = copay.TxProposal;
|
var TxProposal = copay.TxProposal;
|
||||||
var TxProposals = copay.TxProposals;
|
var TxProposals = copay.TxProposals;
|
||||||
|
var moment = moment || require('moment');
|
||||||
|
|
||||||
var dummyProposal = new TxProposal({
|
var dummyProposal = new TxProposal({
|
||||||
creator: 1,
|
creator: 1,
|
||||||
|
|
@ -45,29 +46,86 @@ describe('TxProposals', function() {
|
||||||
var txps = TxProposals.fromObj({
|
var txps = TxProposals.fromObj({
|
||||||
networkName: 'livenet',
|
networkName: 'livenet',
|
||||||
walletId: '123a12',
|
walletId: '123a12',
|
||||||
txps: [ { a: 1 }],
|
txps: [{
|
||||||
|
a: 1
|
||||||
|
}],
|
||||||
});
|
});
|
||||||
should.exist(txps);
|
should.exist(txps);
|
||||||
Object.keys(txps.txps).length.should.equal(0);
|
Object.keys(txps.txps).length.should.equal(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe('#length', function() {
|
||||||
|
it('should return length', function() {
|
||||||
|
var txps = new TxProposals();
|
||||||
|
txps.txps = {
|
||||||
|
a: 1,
|
||||||
|
b: 2
|
||||||
|
};
|
||||||
|
txps.length().should.equal(2);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('#getNtxidsSince', function() {
|
||||||
|
it('should throw illegal argument', function() {
|
||||||
|
var txps = new TxProposals();
|
||||||
|
txps.txps = {
|
||||||
|
a: 1,
|
||||||
|
b: 2
|
||||||
|
};
|
||||||
|
(function() {
|
||||||
|
txps.getNtxidsSince()
|
||||||
|
}).should.throw('Illegal Argument');
|
||||||
|
});
|
||||||
|
it('should return keys since a date', function() {
|
||||||
|
var today = moment().toDate();
|
||||||
|
var today_plus_1 = moment().add(1, 'day').toDate();
|
||||||
|
var today_plus_2 = moment().add(2, 'day').toDate();
|
||||||
|
var today_plus_3 = moment().add(3, 'day').toDate();
|
||||||
|
|
||||||
|
var txps = new TxProposals();
|
||||||
|
txps.txps = [{
|
||||||
|
id: 1,
|
||||||
|
createdTs: today
|
||||||
|
}, {
|
||||||
|
id: 2,
|
||||||
|
createdTs: today_plus_1
|
||||||
|
}, {
|
||||||
|
id: 3,
|
||||||
|
createdTs: today_plus_2
|
||||||
|
}];
|
||||||
|
|
||||||
|
txps.getNtxidsSince(today).length.should.be.equal(3);
|
||||||
|
txps.getNtxidsSince(today_plus_1).length.should.be.equal(2);
|
||||||
|
txps.getNtxidsSince(today_plus_2).length.should.be.equal(1);
|
||||||
|
txps.getNtxidsSince(today_plus_3).length.should.be.equal(0);
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
describe('#getNtxids', function() {
|
describe('#getNtxids', function() {
|
||||||
it('should return keys', function() {
|
it('should return keys', function() {
|
||||||
var txps = new TxProposals();
|
var txps = new TxProposals();
|
||||||
txps.txps = {a:1, b:2};
|
txps.txps = {
|
||||||
|
a: 1,
|
||||||
|
b: 2
|
||||||
|
};
|
||||||
txps.getNtxids().should.deep.equal(['a', 'b']);
|
txps.getNtxids().should.deep.equal(['a', 'b']);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('#deleteOne', function() {
|
describe('#deleteOne', function() {
|
||||||
it('should delete specified ntxid', function() {
|
it('should delete specified ntxid', function() {
|
||||||
var txps = new TxProposals();
|
var txps = new TxProposals();
|
||||||
txps.txps = {a:1, b:2};
|
txps.txps = {
|
||||||
|
a: 1,
|
||||||
|
b: 2
|
||||||
|
};
|
||||||
txps.deleteOne('a');
|
txps.deleteOne('a');
|
||||||
txps.getNtxids().should.deep.equal(['b']);
|
txps.getNtxids().should.deep.equal(['b']);
|
||||||
});
|
});
|
||||||
it('should fail on non-existent ntxid', function() {
|
it('should fail on non-existent ntxid', function() {
|
||||||
var txps = new TxProposals();
|
var txps = new TxProposals();
|
||||||
txps.txps = {a:1, b:2};
|
txps.txps = {
|
||||||
|
a: 1,
|
||||||
|
b: 2
|
||||||
|
};
|
||||||
(function() {
|
(function() {
|
||||||
txps.deleteOne('c');
|
txps.deleteOne('c');
|
||||||
}).should.throw('Unknown TXP: c');
|
}).should.throw('Unknown TXP: c');
|
||||||
|
|
@ -121,4 +179,3 @@ describe('TxProposals', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue