From e62e5b032d100c1078e88022b872759e63f13465 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Mon, 11 Jan 2016 15:25:13 -0300 Subject: [PATCH] add fetchedOn to returned rates --- lib/fiatrateservice.js | 1 + test/integration/fiatrateservice.js | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/fiatrateservice.js b/lib/fiatrateservice.js index a653fbf..0b6849d 100644 --- a/lib/fiatrateservice.js +++ b/lib/fiatrateservice.js @@ -119,6 +119,7 @@ FiatRateService.prototype.getRate = function(code, opts, cb) { return cb(null, { ts: +ts, rate: rate ? rate.value : undefined, + fetchedOn: rate ? rate.ts : undefined, }); }); }, function(err, res) { diff --git a/test/integration/fiatrateservice.js b/test/integration/fiatrateservice.js index 0228f40..304dd48 100644 --- a/test/integration/fiatrateservice.js +++ b/test/integration/fiatrateservice.js @@ -48,7 +48,7 @@ describe.only('Fiat rate service', function() { }); }); }); - it('should get current for different currency', function(done) { + it('should get current rate for different currency', function(done) { service.storage.storeFiatRate('BitPay', [{ code: 'USD', value: 123.45, @@ -69,6 +69,7 @@ describe.only('Fiat rate service', function() { }); it('should get rate for specific ts', function(done) { var clock = sinon.useFakeTimers(0, 'Date'); + clock.tick(20); service.storage.storeFiatRate('BitPay', [{ code: 'USD', value: 123.45, @@ -84,7 +85,9 @@ describe.only('Fiat rate service', function() { ts: 50, }, function(err, res) { should.not.exist(err); + res.ts.should.equal(50); res.rate.should.equal(123.45); + res.fetchedOn.should.equal(20); clock.restore(); done(); }); @@ -106,17 +109,27 @@ describe.only('Fiat rate service', function() { }, function(err) { should.not.exist(err); service.getRate('USD', { - ts: [50, 100, 500], + ts: [50, 100, 199, 500], }, function(err, res) { should.not.exist(err); - res.length.should.equal(3); + res.length.should.equal(4); res[0].ts.should.equal(50); should.not.exist(res[0].rate); + should.not.exist(res[0].fetchedOn); + res[1].ts.should.equal(100); res[1].rate.should.equal(1.00); - res[2].ts.should.equal(500); - res[2].rate.should.equal(4.00); + res[1].fetchedOn.should.equal(100); + + res[2].ts.should.equal(199); + res[2].rate.should.equal(1.00); + res[2].fetchedOn.should.equal(100); + + res[3].ts.should.equal(500); + res[3].rate.should.equal(4.00); + res[3].fetchedOn.should.equal(400); + clock.restore(); done(); });