Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

Commit 7297222

Browse files
committed
Add jsdoc and add unit test for USD fallback
1 parent 104b9c2 commit 7297222

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/action/setting.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ class SettingAction {
4242
this._db.save();
4343
}
4444

45+
/**
46+
* Detect the user's local fiat currency based on their OS locale.
47+
* If the currency is not supported use the default currency `usd`.
48+
* @return {Promise<undefined>}
49+
*/
4550
async detectLocalCurrency() {
4651
try {
4752
let locale = await this._ipc.send('locale-get', 'locale');

test/unit/action/setting.spec.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,26 @@ describe('Action Setting Unit Test', () => {
6161
});
6262

6363
describe('detectLocalCurrency()', () => {
64-
it('should set a valid fiat currency and save settings', async () => {
64+
it('should detect Euro for Germany and save settings', async () => {
6565
ipc.send.resolves('de');
6666
await setting.detectLocalCurrency();
6767
expect(store.settings.fiat, 'to equal', 'eur');
6868
expect(wallet.getExchangeRate, 'was called once');
6969
expect(db.save, 'was called once');
7070
});
7171

72-
it('should throw error on invalid fiat type', async () => {
72+
it('should log error', async () => {
7373
ipc.send.rejects(new Error('Boom!'));
7474
await setting.detectLocalCurrency();
75-
expect(logger.error, 'was called with', /Detecting/);
75+
expect(logger.error, 'was called with', /Detecting/, /Boom/);
76+
});
77+
78+
it('should fall back to USD for unsupported fiat', async () => {
79+
ipc.send.resolves('jp');
80+
await setting.detectLocalCurrency();
81+
expect(store.settings.fiat, 'to equal', 'usd');
82+
expect(logger.error, 'was called with', /Detecting/, /Invalid fiat/);
83+
expect(db.save, 'was not called');
7684
});
7785
});
7886
});

0 commit comments

Comments
 (0)