FIX: move currency format tests to unit

This commit is contained in:
Ivan Vershigora 2020-06-03 18:24:59 +03:00 committed by Overtorment
parent 6e54572402
commit 68e7788d24
3 changed files with 33 additions and 28 deletions

View file

@ -138,3 +138,4 @@ module.exports.BTCToLocalCurrency = BTCToLocalCurrency;
module.exports.setPrefferedCurrency = setPrefferedCurrency;
module.exports.getPreferredCurrency = getPreferredCurrency;
module.exports.exchangeRates = exchangeRates; // export it to mock data in tests
module.exports.preferredFiatCurrency = preferredFiatCurrency; // export it to mock data in tests

View file

@ -30,32 +30,4 @@ describe('currency', () => {
cur = JSON.parse(await AsyncStorage.getItem(AppStorage.EXCHANGE_RATES));
assert.ok(cur.BTC_EUR > 0);
});
it('formats everything correctly', async () => {
const currency = require('../../currency');
await currency.setPrefferedCurrency(FiatUnit.USD);
await currency.startUpdater();
currency.exchangeRates.BTC_USD = 10000;
assert.strictEqual(currency.satoshiToLocalCurrency(1), '$0.0001');
assert.strictEqual(currency.satoshiToLocalCurrency(-1), '-$0.0001');
assert.strictEqual(currency.satoshiToLocalCurrency(123), '$0.012');
assert.strictEqual(currency.satoshiToLocalCurrency(146), '$0.015');
assert.strictEqual(currency.satoshiToLocalCurrency(123456789), '$12,345.68');
assert.strictEqual(currency.BTCToLocalCurrency(1), '$10,000.00');
assert.strictEqual(currency.BTCToLocalCurrency(-1), '-$10,000.00');
assert.strictEqual(currency.BTCToLocalCurrency(1.00000001), '$10,000.00');
assert.strictEqual(currency.BTCToLocalCurrency(1.0000123), '$10,000.12');
assert.strictEqual(currency.BTCToLocalCurrency(1.0000146), '$10,000.15');
assert.strictEqual(currency.satoshiToBTC(1), '0.00000001');
assert.strictEqual(currency.satoshiToBTC(-1), '-0.00000001');
assert.strictEqual(currency.satoshiToBTC(100000000), '1');
assert.strictEqual(currency.satoshiToBTC(123456789123456789), '1234567891.2345678');
await currency.setPrefferedCurrency(FiatUnit.JPY);
await currency.startUpdater();
currency.exchangeRates.BTC_JPY = 1043740.8614;
assert.strictEqual(currency.satoshiToLocalCurrency(1), '¥0.01');
});
});

View file

@ -0,0 +1,32 @@
/* global describe, it */
import { FiatUnit } from '../../models/fiatUnit';
let assert = require('assert');
describe('currency', () => {
it('formats everything correctly', async () => {
const currency = require('../../currency');
currency.exchangeRates.BTC_USD = 10000;
assert.strictEqual(currency.satoshiToLocalCurrency(1), '$0.0001');
assert.strictEqual(currency.satoshiToLocalCurrency(-1), '-$0.0001');
assert.strictEqual(currency.satoshiToLocalCurrency(123), '$0.012');
assert.strictEqual(currency.satoshiToLocalCurrency(146), '$0.015');
assert.strictEqual(currency.satoshiToLocalCurrency(123456789), '$12,345.68');
assert.strictEqual(currency.BTCToLocalCurrency(1), '$10,000.00');
assert.strictEqual(currency.BTCToLocalCurrency(-1), '-$10,000.00');
assert.strictEqual(currency.BTCToLocalCurrency(1.00000001), '$10,000.00');
assert.strictEqual(currency.BTCToLocalCurrency(1.0000123), '$10,000.12');
assert.strictEqual(currency.BTCToLocalCurrency(1.0000146), '$10,000.15');
assert.strictEqual(currency.satoshiToBTC(1), '0.00000001');
assert.strictEqual(currency.satoshiToBTC(-1), '-0.00000001');
assert.strictEqual(currency.satoshiToBTC(100000000), '1');
assert.strictEqual(currency.satoshiToBTC(123456789123456789), '1234567891.2345678');
currency.preferredFiatCurrency.endPointKey = FiatUnit.JPY.endPointKey;
currency.preferredFiatCurrency.symbol = FiatUnit.JPY.symbol;
currency.preferredFiatCurrency.locale = FiatUnit.JPY.locale;
currency.exchangeRates.BTC_JPY = 1043740.8614;
assert.strictEqual(currency.satoshiToLocalCurrency(1), '¥0.01');
});
});