fix returning old rates

This commit is contained in:
Ivan Socolsky 2016-02-10 18:21:48 -03:00
parent 9404dee2d8
commit 3f5f219450
2 changed files with 4 additions and 4 deletions

View File

@ -119,7 +119,7 @@ FiatRateService.prototype.getRate = function(opts, cb) {
async.map([].concat(ts), function(ts, cb) {
self.storage.fetchFiatRate(provider, opts.code, ts, function(err, rate) {
if (err) return cb(err);
if (rate && (now - rate.ts) > Defaults.FIAT_RATE_MAX_LOOK_BACK_TIME * 60 * 1000) rate = null;
if (rate && (ts - rate.ts) > Defaults.FIAT_RATE_MAX_LOOK_BACK_TIME * 60 * 1000) rate = null;
return cb(null, {
ts: +ts,

View File

@ -182,16 +182,16 @@ describe('Fiat rate service', function() {
value: 123.45,
}], function(err) {
should.not.exist(err);
clock.tick((120 * 60 - 1) * 1000); // Almost 2 hours
clock.tick(24 * 3600 * 1000); // Some time in the future
service.getRate({
ts: 2 * 3600 * 1000 - 1, // almost 2 hours
code: 'USD',
}, function(err, res) {
should.not.exist(err);
res.rate.should.equal(123.45);
res.fetchedOn.should.equal(0);
clock.restore();
clock.tick(2 * 1000); // 2 seconds later...
service.getRate({
ts: 2 * 3600 * 1000 + 1, // just past 2 hours
code: 'USD',
}, function(err, res) {
should.not.exist(err);