-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
83 lines (78 loc) · 2.08 KB
/
index.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
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
74
75
76
77
78
79
80
81
82
83
const R = require('ramda')
const { snakeToCamel, camelToSnake } = require('./index');
it.concurrent('Convert string from snake to camel case', async () => {
expect(snakeToCamel('snake_case')).toBe('snakeCase');
expect(camelToSnake('camelCase')).toBe('camel_case');
});
it.concurrent('Convert array from snake to camel case', async () => {
const a = R.times((n) => `snake_case_${n}`, 5)
const b = R.times((n) => `snakeCase${n}`, 5)
expect(snakeToCamel(a)).toStrictEqual(b);
const c = { array: ['shouldBeSameCaseAsBefore'] }
expect(snakeToCamel(c)).toStrictEqual(c)
});
it.concurrent('Convert object from snake to camel case', async () => {
const a = {'user_id': 1, 'user_name': 'Oga'}
const b = {'userId': 1, 'userName': 'Oga'}
expect(snakeToCamel(a)).toStrictEqual(b);
});
it.concurrent('Convert object recursively from snake to camel case', async () => {
const a = {
'user_id': 1,
'user_name': 'Oga',
'user_links': {
'profile_url': 'http://url.io',
'resume_url': 'http://url.io',
}
}
const b = {
'userId': 1,
'userName': 'Oga',
'userLinks': {
'profileUrl': 'http://url.io',
'resumeUrl': 'http://url.io',
}
}
expect(snakeToCamel(a)).toStrictEqual(b);
});
it.concurrent('Convert object recursively from snake to camel case with different types', async () => {
const a = {
'user_id': 1,
'user_name': 'Oga',
'user_links': {
'profile_url': 'http://url.io',
'resume_url': 'http://url.io',
},
'user_positions': [11, 21, 43, 54],
'user_friends': [
{
'user_id': 2,
'user_name': 'Red Hot'
},
{
'user_id': 5,
'user_name': 'Tommy'
},
],
}
const b = {
'userId': 1,
'userName': 'Oga',
'userLinks': {
'profileUrl': 'http://url.io',
'resumeUrl': 'http://url.io',
},
'userPositions': [11, 21, 43, 54],
'userFriends': [
{
'userId': 2,
'userName': 'Red Hot'
},
{
'userId': 5,
'userName': 'Tommy'
},
],
}
expect(snakeToCamel(a)).toStrictEqual(b);
});