mirror of https://github.com/BTCPrivate/copay.git
Merge pull request #1464 from eordano/fix/1457
Fix test: rateService issue #1457
This commit is contained in:
commit
133b01cbb2
|
@ -101,5 +101,4 @@ Logger.prototype.setLevel = function(level) {
|
|||
|
||||
var logger = new Logger('copay');
|
||||
logger.setLevel(config.logLevel);
|
||||
logger.log('Log level:' + config.logLevel);
|
||||
module.exports = logger;
|
||||
|
|
|
@ -4,6 +4,7 @@ var RateService = function(request) {
|
|||
this.isAvailable = false;
|
||||
this.UNAVAILABLE_ERROR = 'Service is not available - check for service.isAvailable or use service.whenAvailable';
|
||||
this.SAT_TO_BTC = 1 / 1e8;
|
||||
this.BTC_TO_SAT = 1e8;
|
||||
var MINS_IN_HOUR = 60;
|
||||
var MILLIS_IN_SECOND = 1000;
|
||||
var rateServiceConfig = config.rate;
|
||||
|
@ -62,7 +63,7 @@ RateService.prototype.fromFiat = function(amount, code) {
|
|||
if (!this.isAvailable) {
|
||||
throw new Error(this.UNAVAILABLE_ERROR);
|
||||
}
|
||||
return amount / this.rates[code] / this.SAT_TO_BTC;
|
||||
return amount / this.rates[code] * this.BTC_TO_SAT;
|
||||
};
|
||||
|
||||
RateService.prototype.listAlternatives = function() {
|
||||
|
|
|
@ -124,17 +124,23 @@ describe('Unit: Rate Service', function() {
|
|||
});
|
||||
}));
|
||||
it('should be possible to ask for conversion from fiat',
|
||||
function(done) {
|
||||
inject(function(rateService) {
|
||||
rateService.whenAvailable(function() {
|
||||
(1).should.equal(rateService.fromFiat(2, 'LOL'));
|
||||
(1e8).should.equal(rateService.fromFiat(2, 'LOL'));
|
||||
done();
|
||||
});
|
||||
})
|
||||
}
|
||||
);
|
||||
it('should be possible to ask for conversion to fiat',
|
||||
function(done) {
|
||||
inject(function(rateService) {
|
||||
rateService.whenAvailable(function() {
|
||||
(2).should.equal(rateService.toFiat(1e8, 'LOL'));
|
||||
done();
|
||||
});
|
||||
})
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue