forked from obytes/react-native-template-obytes
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathutils.test.tsx
More file actions
134 lines (123 loc) · 3.4 KB
/
utils.test.tsx
File metadata and controls
134 lines (123 loc) · 3.4 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import { getUrlParameters, toCamelCase, toSnakeCase } from '../../../src/api/common/utils';
describe('utils', () => {
describe('toCamelCase', () => {
it('should convert snake_case to camelCase', () => {
const obj = {
foo_bar: 'foo',
bar_baz: 'bar',
};
const expected = {
fooBar: 'foo',
barBaz: 'bar',
};
expect(toCamelCase(obj)).toEqual(expected);
});
it('should convert to camelCase only snake_case keys', () => {
const obj = {
foo_bar: 'foo',
bar_baz: 'bar',
fooBar: 'foo',
barBaz: 'bar',
};
const expected = {
fooBar: 'foo',
barBaz: 'bar',
};
expect(toCamelCase(obj)).toEqual(expected);
});
});
describe('toSnakeCase', () => {
it('should convert camelCase to snake_case', () => {
const obj = {
fooBar: 'foo',
barBaz: 'bar',
};
const expected = {
foo_bar: 'foo',
bar_baz: 'bar',
};
expect(toSnakeCase(obj)).toEqual(expected);
});
it('should convert to snake_case only camelCase keys', () => {
const obj = {
fooBar: 'foo',
barBaz: 'bar',
foo_bar: 'foo',
bar_baz: 'bar',
};
const expected = {
foo_bar: 'foo',
bar_baz: 'bar',
};
expect(toSnakeCase(obj)).toEqual(expected);
});
});
});
describe('toCamelCase with nested objects', () => {
it('should convert to camelCase only snake_case keys', () => {
const obj = {
user: {
foo_bar: 'foo',
bar_baz: 'bar',
nested_object: {
another_key: 'value',
yet_another_key: 'another value',
},
},
};
const expected = {
user: {
fooBar: 'foo',
barBaz: 'bar',
nestedObject: {
anotherKey: 'value',
yetAnotherKey: 'another value',
},
},
};
expect(toCamelCase(obj)).toEqual(expected);
});
});
describe('toSnakeCase with nested objects', () => {
it('should convert to snake_case only camelCase keys', () => {
const obj = {
user: {
fooBar: 'foo',
barBaz: 'bar',
foo_bar: 'foo',
bar_baz: 'bar',
},
};
const expected = {
user: {
foo_bar: 'foo',
bar_baz: 'bar',
},
};
expect(toSnakeCase(obj)).toEqual(expected);
});
});
describe('getUrlParameters', () => {
it('should return null for a null URL', () => {
const result = getUrlParameters(null);
expect(result).toBeNull();
});
it('should return an empty object for a URL with no parameters', () => {
const result = getUrlParameters('https://example.com');
expect(result).toEqual({});
});
it('should return an object with a single key-value pair for a URL with one parameter', () => {
const result = getUrlParameters('https://example.com?name=John');
expect(result).toEqual({ name: 'John' });
});
it('should return an object with multiple key-value pairs for a URL with multiple parameters', () => {
const result = getUrlParameters('https://example.com?name=John&age=30');
expect(result).toEqual({ name: 'John', age: '30' });
});
it('should handle special characters in the URL parameters', () => {
const result = getUrlParameters(
'https://example.com?name=John%20Doe&city=New%20York',
);
expect(result).toEqual({ name: 'John Doe', city: 'New York' });
});
});