Add test for PrivateKey and RateService
This commit is contained in:
parent
bf82fa0760
commit
b741effd18
2 changed files with 90 additions and 0 deletions
|
|
@ -23,6 +23,28 @@ describe('PrivateKey model', function() {
|
||||||
should.exist(w.bip.derive);
|
should.exist(w.bip.derive);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should return the extended public key', function() {
|
||||||
|
var w = new PrivateKey(pkConfig);
|
||||||
|
var pubk1 = w.getExtendedPublicKeyString();
|
||||||
|
should.exist(pubk1);
|
||||||
|
console.log(pubk1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return the private key', function() {
|
||||||
|
var w = new PrivateKey(pkConfig);
|
||||||
|
var pk1 = w.getIdKey();
|
||||||
|
should.exist(pk1);
|
||||||
|
var pk2 = w.getIdKey();
|
||||||
|
should.exist(pk2);
|
||||||
|
pk1.should.be.equal(pk2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return the Hierarchical key', function() {
|
||||||
|
var w = new PrivateKey(pkConfig);
|
||||||
|
var hk = w._getHK();
|
||||||
|
should.exist(hk);
|
||||||
|
});
|
||||||
|
|
||||||
it('should derive priv keys', function() {
|
it('should derive priv keys', function() {
|
||||||
var pk = new PrivateKey(pkConfig);
|
var pk = new PrivateKey(pkConfig);
|
||||||
for (var j = false; !j; j = true) {
|
for (var j = false; !j; j = true) {
|
||||||
|
|
|
||||||
|
|
@ -173,6 +173,29 @@ describe('RateService model', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should return an error', function() {
|
||||||
|
var rs = new RateService();
|
||||||
|
rs.isAvailable = sinon.stub().returns(true);
|
||||||
|
var today = Date.now();
|
||||||
|
var yesterday = today - 24 * 3600;
|
||||||
|
var getHistoricalRateStub = sinon.stub(rs, 'getHistoricRate');
|
||||||
|
getHistoricalRateStub.withArgs('XXX', today).yields('Not found', null);
|
||||||
|
|
||||||
|
|
||||||
|
var params = [{
|
||||||
|
satoshis: 0,
|
||||||
|
code: 'XXX',
|
||||||
|
date: today,
|
||||||
|
expected: '0.00'
|
||||||
|
}];
|
||||||
|
_.each(params, function(p) {
|
||||||
|
rs.toFiatHistoric(p.satoshis, p.code, p.date, function(err, rate) {
|
||||||
|
err.should.equal('Not found');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#getHistoricRate', function() {
|
describe('#getHistoricRate', function() {
|
||||||
|
|
@ -203,6 +226,7 @@ describe('RateService model', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return error', function() {
|
it('should return error', function() {
|
||||||
var yesterday = moment().subtract(1, 'day');
|
var yesterday = moment().subtract(1, 'day');
|
||||||
var reqStub = sinon.stub();
|
var reqStub = sinon.stub();
|
||||||
|
|
@ -265,6 +289,30 @@ describe('RateService model', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should return a value', function() {
|
||||||
|
var yesterday = moment().subtract(1, 'day');
|
||||||
|
var reqStub = sinon.stub();
|
||||||
|
|
||||||
|
var statusIn = {
|
||||||
|
statusCode: 200
|
||||||
|
};
|
||||||
|
|
||||||
|
var rateIn = {
|
||||||
|
rate: 50
|
||||||
|
};
|
||||||
|
reqStub.get = sinon.stub().yields(null, statusIn, rateIn);
|
||||||
|
|
||||||
|
var rs = new RateService({
|
||||||
|
request: reqStub
|
||||||
|
});
|
||||||
|
rs.isAvailable = sinon.stub().returns(true);
|
||||||
|
|
||||||
|
var dates = [yesterday, yesterday];
|
||||||
|
rs.getHistoricRates('USD', dates, function(err, status, rate) {
|
||||||
|
status[0].rate.should.equal(50);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should return error', function() {
|
it('should return error', function() {
|
||||||
var yesterday = moment().subtract(1, 'day');
|
var yesterday = moment().subtract(1, 'day');
|
||||||
var reqStub = sinon.stub();
|
var reqStub = sinon.stub();
|
||||||
|
|
@ -356,6 +404,26 @@ describe('RateService model', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#whenAvailable is available', function() {
|
||||||
|
it('should return callback ', function() {
|
||||||
|
var rs = new RateService();
|
||||||
|
rs.isAvailable = sinon.stub().returns(true);
|
||||||
|
rs.whenAvailable(function() {});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#whenAvailable is not available', function() {
|
||||||
|
it('should queue the callback ', function() {
|
||||||
|
|
||||||
|
var rs = new RateService();
|
||||||
|
var count = rs._queued.length;
|
||||||
|
rs.isAvailable = sinon.stub().returns(false);
|
||||||
|
rs.whenAvailable(function() {});
|
||||||
|
rs._queued.length.should.be.equal(count + 1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('#singleton', function() {
|
describe('#singleton', function() {
|
||||||
it('should create only one instance', function() {
|
it('should create only one instance', function() {
|
||||||
var rs = RateService.singleton();
|
var rs = RateService.singleton();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue