BlueWallet/tests/integration/Currency.test.js

51 lines
1.9 KiB
JavaScript
Raw Normal View History

import assert from 'assert';
2020-12-16 04:15:57 +01:00
import AsyncStorage from '@react-native-async-storage/async-storage';
import { FiatUnit } from '../../models/fiatUnit';
jest.setTimeout(90 * 1000);
describe('currency', () => {
it('fetches exchange rate and saves to AsyncStorage', async () => {
2020-06-09 16:08:18 +02:00
const currency = require('../../blue_modules/currency');
2021-09-09 21:36:35 +02:00
await currency.init();
2021-05-18 22:38:18 +02:00
let cur = await AsyncStorage.getItem(currency.EXCHANGE_RATES);
cur = JSON.parse(cur);
2021-09-09 21:36:35 +02:00
assert.ok(Number.isInteger(cur[currency.LAST_UPDATED]));
assert.ok(cur[currency.LAST_UPDATED] > 0);
assert.ok(cur.BTC_USD > 0);
// now, setting other currency as default
2021-05-18 22:38:18 +02:00
await AsyncStorage.setItem(currency.PREFERRED_CURRENCY, JSON.stringify(FiatUnit.JPY));
2021-09-09 21:36:35 +02:00
await currency.init(true);
2021-05-18 22:38:18 +02:00
cur = JSON.parse(await AsyncStorage.getItem(currency.EXCHANGE_RATES));
assert.ok(cur.BTC_JPY > 0);
// now setting with a proper setter
await currency.setPrefferedCurrency(FiatUnit.EUR);
2021-09-09 21:36:35 +02:00
await currency.init(true);
const preferred = await currency.getPreferredCurrency();
assert.strictEqual(preferred.endPointKey, 'EUR');
2021-05-18 22:38:18 +02:00
cur = JSON.parse(await AsyncStorage.getItem(currency.EXCHANGE_RATES));
assert.ok(cur.BTC_EUR > 0);
// test Yadio rate source
await currency.setPrefferedCurrency(FiatUnit.ARS);
2021-09-09 21:36:35 +02:00
await currency.init(true);
2021-05-18 22:38:18 +02:00
cur = JSON.parse(await AsyncStorage.getItem(currency.EXCHANGE_RATES));
assert.ok(cur.BTC_ARS > 0);
2022-09-24 22:36:06 +02:00
// test YadioConvert rate source
await currency.setPrefferedCurrency(FiatUnit.LBP);
await currency.init(true);
cur = JSON.parse(await AsyncStorage.getItem(currency.EXCHANGE_RATES));
assert.ok(cur.BTC_LBP > 0);
2021-07-06 15:07:47 +02:00
// test Exir rate source
2021-09-21 15:48:46 +02:00
await currency.setPrefferedCurrency(FiatUnit.IRT);
2021-09-09 21:36:35 +02:00
await currency.init(true);
2021-07-06 15:07:47 +02:00
cur = JSON.parse(await AsyncStorage.getItem(currency.EXCHANGE_RATES));
2021-09-21 15:48:46 +02:00
assert.ok(cur.BTC_IRT > 0);
});
});