From b741effd18d18b104abf2e5096ad75957181bd47 Mon Sep 17 00:00:00 2001 From: Matias Pando Date: Thu, 22 Jan 2015 15:51:18 -0300 Subject: [PATCH] Add test for PrivateKey and RateService --- test/PrivateKey.js | 22 +++++++++++++++ test/RateService.js | 68 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) diff --git a/test/PrivateKey.js b/test/PrivateKey.js index d8b32a77b..7e8b660c1 100644 --- a/test/PrivateKey.js +++ b/test/PrivateKey.js @@ -23,6 +23,28 @@ describe('PrivateKey model', function() { 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() { var pk = new PrivateKey(pkConfig); for (var j = false; !j; j = true) { diff --git a/test/RateService.js b/test/RateService.js index fa68e2961..4838f00cd 100644 --- a/test/RateService.js +++ b/test/RateService.js @@ -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() { @@ -203,6 +226,7 @@ describe('RateService model', function() { }); }); }); + it('should return error', function() { var yesterday = moment().subtract(1, 'day'); 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() { var yesterday = moment().subtract(1, 'day'); 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() { it('should create only one instance', function() { var rs = RateService.singleton();