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