Fixes test on rateService: github issue #1457

This commit is contained in:
Esteban Ordano 2014-09-22 15:50:19 -03:00
commit 59c9553a4e
3 changed files with 19 additions and 13 deletions

View file

@ -101,5 +101,4 @@ Logger.prototype.setLevel = function(level) {
var logger = new Logger('copay'); var logger = new Logger('copay');
logger.setLevel(config.logLevel); logger.setLevel(config.logLevel);
logger.log('Log level:' + config.logLevel);
module.exports = logger; module.exports = logger;

View file

@ -4,6 +4,7 @@ var RateService = function(request) {
this.isAvailable = false; this.isAvailable = false;
this.UNAVAILABLE_ERROR = 'Service is not available - check for service.isAvailable or use service.whenAvailable'; this.UNAVAILABLE_ERROR = 'Service is not available - check for service.isAvailable or use service.whenAvailable';
this.SAT_TO_BTC = 1 / 1e8; this.SAT_TO_BTC = 1 / 1e8;
this.BTC_TO_SAT = 1e8;
var MINS_IN_HOUR = 60; var MINS_IN_HOUR = 60;
var MILLIS_IN_SECOND = 1000; var MILLIS_IN_SECOND = 1000;
var rateServiceConfig = config.rate; var rateServiceConfig = config.rate;
@ -62,7 +63,7 @@ RateService.prototype.fromFiat = function(amount, code) {
if (!this.isAvailable) { if (!this.isAvailable) {
throw new Error(this.UNAVAILABLE_ERROR); 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() { RateService.prototype.listAlternatives = function() {

View file

@ -124,17 +124,23 @@ describe('Unit: Rate Service', function() {
}); });
})); }));
it('should be possible to ask for conversion from fiat', it('should be possible to ask for conversion from fiat',
inject(function(rateService) { function(done) {
rateService.whenAvailable(function() { inject(function(rateService) {
(1).should.equal(rateService.fromFiat(2, 'LOL')); rateService.whenAvailable(function() {
}); (1e8).should.equal(rateService.fromFiat(2, 'LOL'));
}) done();
});
})
}
); );
it('should be possible to ask for conversion to fiat', it('should be possible to ask for conversion to fiat',
inject(function(rateService) { function(done) {
rateService.whenAvailable(function() { inject(function(rateService) {
(2).should.equal(rateService.toFiat(1e8, 'LOL')); rateService.whenAvailable(function() {
}); (2).should.equal(rateService.toFiat(1e8, 'LOL'));
}) done();
});
})
}
); );
}); });