forked from bengourley/currency-symbol-map
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
44 lines (38 loc) · 1.89 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const test = require('tape')
const getSymbolFromCurrency = require('./')
const currencySymbolMap = require('./map')
test('getSymbolFromCurrency(): valid params', t => {
t.equal('$', getSymbolFromCurrency('USD'), 'should return $ when USD is provided')
t.equal('£', getSymbolFromCurrency('GBP'), 'should return £ when GBP is provided')
t.equal('€', getSymbolFromCurrency('EUR'), 'should return € when EUR is provided')
t.equal('€', getSymbolFromCurrency('eur'), 'should return € when eur is provided')
t.equal(undefined, getSymbolFromCurrency('NON-EXISTENT-CODE'), 'should return undefined when code is non-existent')
t.end()
})
test('getSymbolFromCurrency(): invalid params', t => {
t.equal(undefined, getSymbolFromCurrency(1), 'should return undefined when param is not a string')
t.equal(undefined, getSymbolFromCurrency(null), 'should return undefined when param is null')
t.equal(undefined, getSymbolFromCurrency(false), 'should return undefined when param is false')
t.equal(undefined, getSymbolFromCurrency(), 'should return undefined when param is undefined')
t.end()
})
test('currency-symbol-map: sanity check every value in map', t => {
const currencies = Object.keys(currencySymbolMap)
const obj = {}
currencies.forEach(code => { obj[code] = getSymbolFromCurrency(code) })
t.deepEqual(obj, currencySymbolMap)
t.end()
})
test('currency-symbol-map: no symbols should be missing', t => {
for (const code in currencySymbolMap) {
t.equal(typeof currencySymbolMap[code], 'string', `Symbol of ${code} should be a string`)
t.isNotEqual(currencySymbolMap[code], '', `Symbol of ${code} should not be empty`)
}
t.end()
})
test('currency-symbol-map: codes should be in alphabetical order', t => {
const currencies = Object.keys(currencySymbolMap)
const sorted = Object.keys(currencySymbolMap).sort((a, b) => a.localeCompare(b))
t.deepEqual(currencies, sorted)
t.end()
})