-
Notifications
You must be signed in to change notification settings - Fork 252
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
672 additions
and
576 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,4 @@ | ||
import { | ||
AccountFormT, | ||
AccountStateT, | ||
AccountStorageT, | ||
AccountGroupT, | ||
defaultGroup, | ||
groupOptions, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,57 @@ | ||
import Currency from './Currency' | ||
import Currency from './Currency'; | ||
|
||
it('has default base currency', () => { | ||
expect(Currency.defaultBase).toEqual('USD') | ||
}) | ||
expect(Currency.defaultBase).toEqual('USD'); | ||
}); | ||
|
||
it('returns list of options', () => { | ||
const options = Currency.options() | ||
const options = Currency.options(); | ||
|
||
expect(Array.isArray(options)).toBeTruthy() | ||
expect(options.length).toBeGreaterThanOrEqual(1) | ||
expect(options[0]).toHaveProperty('key') | ||
expect(options[0]).toHaveProperty('value') | ||
expect(options[0]).toHaveProperty('flag') | ||
expect(options[0]).toHaveProperty('text') | ||
expect(Array.isArray(options)).toBeTruthy(); | ||
expect(options.length).toBeGreaterThanOrEqual(1); | ||
expect(options[0]).toHaveProperty('key'); | ||
expect(options[0]).toHaveProperty('value'); | ||
expect(options[0]).toHaveProperty('flag'); | ||
expect(options[0]).toHaveProperty('text'); | ||
|
||
const usdOption = options.find(option => option.key === 'USD') | ||
expect(usdOption).toBeTruthy() | ||
const usdOption = options.find(option => option.key === 'USD'); | ||
expect(usdOption).toBeTruthy(); | ||
if (usdOption) { | ||
expect(usdOption.text).toEqual('USD, US Dollar') | ||
expect(usdOption.flag).toEqual('us') | ||
expect(usdOption.text).toEqual('USD, US Dollar'); | ||
expect(usdOption.flag).toEqual('us'); | ||
} | ||
}) | ||
}); | ||
|
||
it('returns currency name', () => { | ||
expect(Currency.name('USD')).toEqual('US Dollar') | ||
}) | ||
expect(Currency.name('USD')).toEqual('US Dollar'); | ||
}); | ||
|
||
it('returns currency minimal amount', () => { | ||
expect(Currency.minAmount('USD')).toEqual(0.01) | ||
expect(Currency.minAmount('JPY')).toEqual(1) | ||
expect(Currency.minAmount('KWD')).toEqual(0.001) | ||
}) | ||
expect(Currency.minAmount('USD')).toEqual(0.01); | ||
expect(Currency.minAmount('JPY')).toEqual(1); | ||
expect(Currency.minAmount('KWD')).toEqual(0.001); | ||
}); | ||
|
||
it('converts to currency subunit (cents)', () => { | ||
expect(Currency.toInt(10.99, 'USD')).toEqual(1099) // $10.99 => 1099 cents | ||
expect(Currency.toInt(9.5, 'USD')).toEqual(950) // $9.50 => 950 cents | ||
expect(Currency.toInt(199, 'JPY')).toEqual(199) // 199 yen has no subunit, 1 yen is the minimum unit | ||
expect(Currency.toInt(1.5, 'KWD')).toEqual(1500) // 1.5 Kuwaiti dinar => 1500 fils | ||
}) | ||
expect(Currency.toCents(10.99, 'USD')).toEqual(1099); // $10.99 => 1099 cents | ||
expect(Currency.toCents(9.5, 'USD')).toEqual(950); // $9.50 => 950 cents | ||
expect(Currency.toCents(199, 'JPY')).toEqual(199); // 199 yen has no subunit, 1 yen is the minimum unit | ||
expect(Currency.toCents(1.5, 'KWD')).toEqual(1500); // 1.5 Kuwaiti dinar => 1500 fils | ||
}); | ||
|
||
it('converts from currency subunit (cents) back to float', () => { | ||
expect(Currency.toFloat(1099, 'USD')).toEqual('10.99') | ||
expect(Currency.toFloat(950, 'USD')).toEqual('9.50') | ||
expect(Currency.toFloat(100099, 'USD')).toEqual('1,000.99') | ||
expect(Currency.toFloat(199, 'JPY')).toEqual('199') | ||
expect(Currency.toFloat(1550, 'KWD')).toEqual('1.550') | ||
}) | ||
expect(Currency.centsToNumber(1099, 'USD')).toEqual(10.99); | ||
expect(Currency.centsToNumber(950, 'USD')).toEqual(9.5); | ||
expect(Currency.centsToNumber(100099, 'USD')).toEqual(1000.99); | ||
expect(Currency.centsToNumber(199, 'JPY')).toEqual(199); | ||
expect(Currency.centsToNumber(1550, 'KWD')).toEqual(1.55); | ||
}); | ||
|
||
it('converts from currency subunit (cents) to human readable string', () => { | ||
expect(Currency.centsToString(1099, 'USD')).toEqual('10.99'); | ||
expect(Currency.centsToString(950, 'USD')).toEqual('9.50'); | ||
expect(Currency.centsToString(100099, 'USD')).toEqual('1,000.99'); | ||
expect(Currency.centsToString(100099, 'USD', false)).toEqual('1000.99'); | ||
expect(Currency.centsToString(199, 'JPY')).toEqual('199'); | ||
expect(Currency.centsToString(1550, 'KWD')).toEqual('1.550'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.