-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathutils.test.ts
73 lines (65 loc) · 1.9 KB
/
utils.test.ts
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import {
groupArrayByKey,
splitArrayIntoChunks,
getCanonicalAdapterName,
canonicalizeAdapterNameKeys,
} from '../src/util'
import test from 'ava'
test('Test splitArrayIntoChunks function', async (t) => {
const array = [1, 2, 3, 4, 5]
let chunks = splitArrayIntoChunks(array, 2)
t.deepEqual(chunks, [[1, 2], [3, 4], [5]])
// Size greater than array length returns whole array
chunks = splitArrayIntoChunks(array, 10)
t.deepEqual(chunks, [[1, 2, 3, 4, 5]])
chunks = splitArrayIntoChunks([], 10)
t.deepEqual(chunks, [[]])
})
test('Test groupArrayByKey function', async (t) => {
const array = [
{ base: 'BTC', quote: 'ETH' },
{ base: 'BTC', quote: 'USD' },
{ base: 'LTC', quote: 'DASH' },
]
let grouped = groupArrayByKey(array, 'base')
t.deepEqual(grouped, {
BTC: [
{ base: 'BTC', quote: 'ETH' },
{ base: 'BTC', quote: 'USD' },
],
LTC: [{ base: 'LTC', quote: 'DASH' }],
})
grouped = groupArrayByKey(array, 'quote')
t.deepEqual(grouped, {
ETH: [{ base: 'BTC', quote: 'ETH' }],
USD: [{ base: 'BTC', quote: 'USD' }],
DASH: [{ base: 'LTC', quote: 'DASH' }],
})
})
test('Test getCanonicalAdapterName', async (t) => {
t.is(getCanonicalAdapterName(undefined), undefined)
t.is(getCanonicalAdapterName('test'), 'test')
t.is(getCanonicalAdapterName('TEST'), 'test')
t.is(getCanonicalAdapterName('TEST-adapter'), 'test_adapter')
t.is(getCanonicalAdapterName('TEST_ADAPTER'), 'test_adapter')
t.is(getCanonicalAdapterName('A-B-C-D-e-f'), 'a_b_c_d_e_f')
})
test('Test canonicalizeAdapterNameKeys', async (t) => {
t.deepEqual(canonicalizeAdapterNameKeys(undefined), undefined)
t.deepEqual(
canonicalizeAdapterNameKeys({
test: 1,
TEST2: 2,
'TEST-adapter': 3,
TEST_ADAPTER2: 4,
'A-B-C-D-e-f': 5,
}),
{
test: 1,
test2: 2,
test_adapter: 3,
test_adapter2: 4,
a_b_c_d_e_f: 5,
},
)
})