diff --git a/currency.js b/currency.js index 8a4abc515..377a34a2e 100644 --- a/currency.js +++ b/currency.js @@ -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 diff --git a/tests/integration/Currency.test.js b/tests/integration/Currency.test.js index 5f42ba9d4..861af96c0 100644 --- a/tests/integration/Currency.test.js +++ b/tests/integration/Currency.test.js @@ -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'); - }); }); diff --git a/tests/unit/Currency.test.js b/tests/unit/Currency.test.js new file mode 100644 index 000000000..983f39603 --- /dev/null +++ b/tests/unit/Currency.test.js @@ -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'); + }); +});