-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuildFirstLayerUrl.test.ts
More file actions
131 lines (100 loc) · 3.81 KB
/
buildFirstLayerUrl.test.ts
File metadata and controls
131 lines (100 loc) · 3.81 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
import packageJson from '../../package.json';
import buildFirstLayerUrl from './buildFirstLayerUrl';
describe('buildFirstLayerUrl', () => {
const defaultParams = {
baseUrl: 'https://example.com',
propertyId: 'prop-123',
planId: 'plan-456',
purposesList: ['analytics', 'marketing'],
vendorCount: 5,
};
it('should build a URL with the correct base path', () => {
const url = buildFirstLayerUrl(defaultParams);
expect(url).toContain('https://example.com/first-layer/');
});
it('should include the start parameter without =true', () => {
const url = buildFirstLayerUrl(defaultParams);
expect(url).toContain('?start&');
expect(url).not.toContain('start=true');
});
it('should include the theme parameter', () => {
const url = buildFirstLayerUrl(defaultParams);
const parsed = new URL(url);
expect(parsed.searchParams.get('theme')).toBe('classic-app');
});
it('should include the SDK version parameter', () => {
const url = buildFirstLayerUrl(defaultParams);
const parsed = new URL(url);
expect(parsed.searchParams.get('v')).toBeTruthy();
expect(parsed.searchParams.get('v')).toBe(
`react-native-contentpass-ui@${packageJson.version}`
);
});
it('should omit the locale parameter when no locale is provided', () => {
const url = buildFirstLayerUrl(defaultParams);
const parsed = new URL(url);
expect(parsed.searchParams.has('locale')).toBe(false);
});
it('should include the locale parameter when provided', () => {
const url = buildFirstLayerUrl({ ...defaultParams, locale: 'es' });
const parsed = new URL(url);
expect(parsed.searchParams.get('locale')).toBe('es');
});
it('should omit the locale parameter when an empty string is provided', () => {
const url = buildFirstLayerUrl({ ...defaultParams, locale: '' });
const parsed = new URL(url);
expect(parsed.searchParams.has('locale')).toBe(false);
});
it('should include the planId parameter', () => {
const url = buildFirstLayerUrl(defaultParams);
const parsed = new URL(url);
expect(parsed.searchParams.get('planId')).toBe('plan-456');
});
it('should include the propertyId parameter', () => {
const url = buildFirstLayerUrl(defaultParams);
const parsed = new URL(url);
expect(parsed.searchParams.get('propertyId')).toBe('prop-123');
});
it('should include the vendorCount as a string', () => {
const url = buildFirstLayerUrl(defaultParams);
const parsed = new URL(url);
expect(parsed.searchParams.get('vendorCount')).toBe('5');
});
it('should encode and join purposesList with commas', () => {
const url = buildFirstLayerUrl(defaultParams);
const parsed = new URL(url);
const purposesList = parsed.searchParams.get('purposesList');
expect(purposesList).toBe('analytics,marketing');
});
it('should handle a single purpose in the list', () => {
const url = buildFirstLayerUrl({
...defaultParams,
purposesList: ['analytics'],
});
const parsed = new URL(url);
expect(parsed.searchParams.get('purposesList')).toBe('analytics');
});
it('should handle an empty purposes list', () => {
const url = buildFirstLayerUrl({
...defaultParams,
purposesList: [],
});
const parsed = new URL(url);
expect(parsed.searchParams.get('purposesList')).toBe('');
});
it('should handle vendorCount of 0', () => {
const url = buildFirstLayerUrl({
...defaultParams,
vendorCount: 0,
});
const parsed = new URL(url);
expect(parsed.searchParams.get('vendorCount')).toBe('0');
});
it('should handle a baseUrl with a trailing path', () => {
const url = buildFirstLayerUrl({
...defaultParams,
baseUrl: 'https://cdn.example.com/consent',
});
expect(url).toContain('https://cdn.example.com/consent/first-layer/');
});
});