@ht-sdks/consent-manager 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +45 -0
- package/README.md +851 -0
- package/commonjs/__tests__/consent-manager-builder/analytics.test.js +250 -0
- package/commonjs/__tests__/consent-manager-builder/fetch-destinations.test.js +155 -0
- package/commonjs/__tests__/consent-manager-builder/index.todo.js +327 -0
- package/commonjs/__tests__/consent-manager-builder/preferences.test.js +129 -0
- package/commonjs/__tests__/index.test.js +57 -0
- package/commonjs/consent-manager/banner.js +89 -0
- package/commonjs/consent-manager/buttons.js +18 -0
- package/commonjs/consent-manager/cancel-dialog.js +76 -0
- package/commonjs/consent-manager/categories.js +29 -0
- package/commonjs/consent-manager/container.js +169 -0
- package/commonjs/consent-manager/dialog.js +129 -0
- package/commonjs/consent-manager/font-styles.js +10 -0
- package/commonjs/consent-manager/index.js +244 -0
- package/commonjs/consent-manager/preference-dialog.js +178 -0
- package/commonjs/consent-manager-builder/analytics.js +76 -0
- package/commonjs/consent-manager-builder/fetch-destinations.js +104 -0
- package/commonjs/consent-manager-builder/index.js +330 -0
- package/commonjs/consent-manager-builder/preferences.js +82 -0
- package/commonjs/index.js +39 -0
- package/commonjs/standalone.js +86 -0
- package/commonjs/types.js +3 -0
- package/esm/__tests__/consent-manager-builder/analytics.test.js +245 -0
- package/esm/__tests__/consent-manager-builder/fetch-destinations.test.js +150 -0
- package/esm/__tests__/consent-manager-builder/index.todo.js +322 -0
- package/esm/__tests__/consent-manager-builder/preferences.test.js +124 -0
- package/esm/__tests__/index.test.js +55 -0
- package/esm/consent-manager/banner.js +65 -0
- package/esm/consent-manager/buttons.js +12 -0
- package/esm/consent-manager/cancel-dialog.js +52 -0
- package/esm/consent-manager/categories.js +26 -0
- package/esm/consent-manager/container.js +162 -0
- package/esm/consent-manager/dialog.js +105 -0
- package/esm/consent-manager/font-styles.js +8 -0
- package/esm/consent-manager/index.js +220 -0
- package/esm/consent-manager/preference-dialog.js +154 -0
- package/esm/consent-manager-builder/analytics.js +73 -0
- package/esm/consent-manager-builder/fetch-destinations.js +98 -0
- package/esm/consent-manager-builder/index.js +325 -0
- package/esm/consent-manager-builder/preferences.js +73 -0
- package/esm/index.js +28 -0
- package/esm/standalone.js +58 -0
- package/esm/types.js +1 -0
- package/package.json +168 -0
- package/src/__tests__/consent-manager-builder/analytics.test.ts +279 -0
- package/src/__tests__/consent-manager-builder/fetch-destinations.test.ts +89 -0
- package/src/__tests__/consent-manager-builder/index.todo.js +386 -0
- package/src/__tests__/consent-manager-builder/preferences.test.ts +156 -0
- package/src/__tests__/index.test.ts +68 -0
- package/src/consent-manager/banner.tsx +227 -0
- package/src/consent-manager/buttons.tsx +78 -0
- package/src/consent-manager/cancel-dialog.tsx +68 -0
- package/src/consent-manager/categories.ts +27 -0
- package/src/consent-manager/container.tsx +282 -0
- package/src/consent-manager/dialog.tsx +236 -0
- package/src/consent-manager/font-styles.tsx +14 -0
- package/src/consent-manager/index.tsx +327 -0
- package/src/consent-manager/preference-dialog.tsx +371 -0
- package/src/consent-manager-builder/analytics.ts +104 -0
- package/src/consent-manager-builder/fetch-destinations.ts +50 -0
- package/src/consent-manager-builder/index.tsx +426 -0
- package/src/consent-manager-builder/preferences.ts +100 -0
- package/src/index.ts +42 -0
- package/src/standalone.tsx +57 -0
- package/src/styled.d.ts +7 -0
- package/src/types.ts +151 -0
- package/standalone/consent-manager.js +23 -0
- package/standalone/consent-manager.js.map +1 -0
- package/types/__tests__/consent-manager-builder/analytics.test.d.ts +1 -0
- package/types/__tests__/consent-manager-builder/fetch-destinations.test.d.ts +1 -0
- package/types/__tests__/consent-manager-builder/index.todo.d.ts +1 -0
- package/types/__tests__/consent-manager-builder/preferences.test.d.ts +1 -0
- package/types/__tests__/index.test.d.ts +1 -0
- package/types/consent-manager/banner.d.ts +21 -0
- package/types/consent-manager/buttons.d.ts +13 -0
- package/types/consent-manager/cancel-dialog.d.ts +19 -0
- package/types/consent-manager/categories.d.ts +3 -0
- package/types/consent-manager/container.d.ts +35 -0
- package/types/consent-manager/dialog.d.ts +29 -0
- package/types/consent-manager/font-styles.d.ts +2 -0
- package/types/consent-manager/index.d.ts +35 -0
- package/types/consent-manager/preference-dialog.d.ts +32 -0
- package/types/consent-manager-builder/analytics.d.ts +14 -0
- package/types/consent-manager-builder/fetch-destinations.d.ts +2 -0
- package/types/consent-manager-builder/index.d.ts +126 -0
- package/types/consent-manager-builder/preferences.d.ts +26 -0
- package/types/index.d.ts +7 -0
- package/types/src/__tests__/consent-manager-builder/analytics.test.d.ts +1 -0
- package/types/src/__tests__/consent-manager-builder/fetch-destinations.test.d.ts +1 -0
- package/types/src/__tests__/consent-manager-builder/preferences.test.d.ts +1 -0
- package/types/src/__tests__/index.test.d.ts +1 -0
- package/types/src/consent-manager/banner.d.ts +21 -0
- package/types/src/consent-manager/buttons.d.ts +13 -0
- package/types/src/consent-manager/cancel-dialog.d.ts +19 -0
- package/types/src/consent-manager/categories.d.ts +3 -0
- package/types/src/consent-manager/container.d.ts +35 -0
- package/types/src/consent-manager/dialog.d.ts +29 -0
- package/types/src/consent-manager/font-styles.d.ts +2 -0
- package/types/src/consent-manager/index.d.ts +35 -0
- package/types/src/consent-manager/preference-dialog.d.ts +32 -0
- package/types/src/consent-manager-builder/analytics.d.ts +14 -0
- package/types/src/consent-manager-builder/fetch-destinations.d.ts +2 -0
- package/types/src/consent-manager-builder/index.d.ts +126 -0
- package/types/src/consent-manager-builder/preferences.d.ts +26 -0
- package/types/src/index.d.ts +7 -0
- package/types/src/standalone.d.ts +5 -0
- package/types/src/types.d.ts +131 -0
- package/types/standalone.d.ts +5 -0
- package/types/types.d.ts +131 -0
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { shallow } from 'enzyme'
|
|
3
|
+
import nock from 'nock'
|
|
4
|
+
import sinon from 'sinon'
|
|
5
|
+
import ConsentManagerBuilder from '../../consent-manager-builder'
|
|
6
|
+
import { ADVERTISING_CATEGORIES, FUNCTIONAL_CATEGORIES } from '../../consent-manager/categories'
|
|
7
|
+
|
|
8
|
+
describe('ConsentManagerBuilder', () => {
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
document = {}
|
|
11
|
+
window = {}
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
test.todo('doesn՚t load events.js when consent is required')
|
|
15
|
+
|
|
16
|
+
test.skip('provides a list of enabled destinations', done => {
|
|
17
|
+
nock('https://cdn.hightouch-events.com')
|
|
18
|
+
.get('/v1/projects/123/integrations')
|
|
19
|
+
.reply(200, [
|
|
20
|
+
{
|
|
21
|
+
name: 'Google Analytics',
|
|
22
|
+
creationName: 'Google Analytics'
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: 'Amplitude',
|
|
26
|
+
creationName: 'Amplitude'
|
|
27
|
+
}
|
|
28
|
+
])
|
|
29
|
+
.get('/v1/projects/abc/integrations')
|
|
30
|
+
.reply(200, [
|
|
31
|
+
{
|
|
32
|
+
name: 'FullStory',
|
|
33
|
+
creationName: 'FullStory'
|
|
34
|
+
}
|
|
35
|
+
])
|
|
36
|
+
|
|
37
|
+
shallow(
|
|
38
|
+
<ConsentManagerBuilder writeKey="123">
|
|
39
|
+
{({ destinations }) => {
|
|
40
|
+
expect(destinations).toMatchObject([
|
|
41
|
+
{
|
|
42
|
+
id: 'Amplitude',
|
|
43
|
+
name: 'Amplitude'
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
id: 'FullStory',
|
|
47
|
+
name: 'FullStory'
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
id: 'Google Analytics',
|
|
51
|
+
name: 'Google Analytics'
|
|
52
|
+
}
|
|
53
|
+
])
|
|
54
|
+
done()
|
|
55
|
+
}}
|
|
56
|
+
</ConsentManagerBuilder>
|
|
57
|
+
)
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
test.skip('provides a list of newly added destinations', done => {
|
|
61
|
+
document.cookie =
|
|
62
|
+
'ht-cm-preferences={%22version%22:1%2C%22destinations%22:{%22Amplitude%22:true}}'
|
|
63
|
+
window.htevents = { load() {}, track() {}, addSourceMiddleware() {} }
|
|
64
|
+
|
|
65
|
+
nock('https://cdn.hightouch-events.com')
|
|
66
|
+
.get('/v1/projects/123/integrations')
|
|
67
|
+
.reply(200, [
|
|
68
|
+
{
|
|
69
|
+
name: 'Google Analytics',
|
|
70
|
+
creationName: 'Google Analytics'
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: 'Amplitude',
|
|
74
|
+
creationName: 'Amplitude'
|
|
75
|
+
}
|
|
76
|
+
])
|
|
77
|
+
|
|
78
|
+
shallow(
|
|
79
|
+
<ConsentManagerBuilder writeKey="123">
|
|
80
|
+
{({ newDestinations }) => {
|
|
81
|
+
expect(newDestinations).toMatchObject([
|
|
82
|
+
{
|
|
83
|
+
name: 'Google Analytics',
|
|
84
|
+
id: 'Google Analytics'
|
|
85
|
+
}
|
|
86
|
+
])
|
|
87
|
+
done()
|
|
88
|
+
}}
|
|
89
|
+
</ConsentManagerBuilder>
|
|
90
|
+
)
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
test.skip('loads events.js with the user՚s preferences', done => {
|
|
94
|
+
const hteventsLoad = sinon.spy()
|
|
95
|
+
document.cookie =
|
|
96
|
+
'ht-cm-preferences={%22version%22:1%2C%22destinations%22:{%22Amplitude%22:true}}'
|
|
97
|
+
window.htevents = { load: hteventsLoad, track() {}, addSourceMiddleware() {} }
|
|
98
|
+
const writeKey = '123'
|
|
99
|
+
|
|
100
|
+
nock('https://cdn.hightouch-events.com')
|
|
101
|
+
.get('/v1/projects/123/integrations')
|
|
102
|
+
.reply(200, [
|
|
103
|
+
{
|
|
104
|
+
name: 'Amplitude',
|
|
105
|
+
creationName: 'Amplitude'
|
|
106
|
+
}
|
|
107
|
+
])
|
|
108
|
+
|
|
109
|
+
shallow(
|
|
110
|
+
<ConsentManagerBuilder writeKey={writeKey}>
|
|
111
|
+
{() => {
|
|
112
|
+
expect(hteventsLoad.calledOnce).toBe(true)
|
|
113
|
+
expect(hteventsLoad.args[0][0]).toBe(writeKey)
|
|
114
|
+
expect(hteventsLoad.args[0][1]).toMatchObject({
|
|
115
|
+
integrations: {
|
|
116
|
+
All: false,
|
|
117
|
+
Amplitude: true
|
|
118
|
+
}
|
|
119
|
+
})
|
|
120
|
+
done()
|
|
121
|
+
}}
|
|
122
|
+
</ConsentManagerBuilder>
|
|
123
|
+
)
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
test.skip('provides an object containing the WIP preferences', done => {
|
|
127
|
+
document.cookie =
|
|
128
|
+
'ht-cm-preferences={%22version%22:1%2C%22destinations%22:{%22Amplitude%22:true}}'
|
|
129
|
+
window.htevents = { load() {}, track() {}, addSourceMiddleware() {} }
|
|
130
|
+
|
|
131
|
+
nock('https://cdn.hightouch-events.com')
|
|
132
|
+
.get('/v1/projects/123/integrations')
|
|
133
|
+
.reply(200, [
|
|
134
|
+
{
|
|
135
|
+
name: 'Amplitude',
|
|
136
|
+
creationName: 'Amplitude'
|
|
137
|
+
}
|
|
138
|
+
])
|
|
139
|
+
|
|
140
|
+
shallow(
|
|
141
|
+
<ConsentManagerBuilder writeKey="123">
|
|
142
|
+
{({ preferences }) => {
|
|
143
|
+
expect(preferences).toMatchObject({
|
|
144
|
+
Amplitude: true
|
|
145
|
+
})
|
|
146
|
+
done()
|
|
147
|
+
}}
|
|
148
|
+
</ConsentManagerBuilder>
|
|
149
|
+
)
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
test.skip('does not imply consent on interacation', done => {
|
|
153
|
+
nock('https://cdn.hightouch-events.com')
|
|
154
|
+
.get('/v1/projects/123/integrations')
|
|
155
|
+
.reply(200, [
|
|
156
|
+
{
|
|
157
|
+
name: 'Amplitude',
|
|
158
|
+
creationName: 'Amplitude'
|
|
159
|
+
}
|
|
160
|
+
])
|
|
161
|
+
|
|
162
|
+
shallow(
|
|
163
|
+
<ConsentManagerBuilder writeKey="123">
|
|
164
|
+
{({ preferences }) => {
|
|
165
|
+
expect(preferences).toMatchObject({})
|
|
166
|
+
done()
|
|
167
|
+
}}
|
|
168
|
+
</ConsentManagerBuilder>
|
|
169
|
+
)
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
test.skip('if defaultDestinationBehavior is set to imply and category is set to true, loads new destination', done => {
|
|
173
|
+
document.cookie =
|
|
174
|
+
'ht-cm-preferences={%22version%22:1%2C%22destinations%22:{%22Amplitude%22:true}%2C%22custom%22:{%22advertising%22:false%2C%22marketingAndAnalytics%22:true%2C%22functional%22:true}}'
|
|
175
|
+
window.htevents = { load() {}, identify() {}, track() {}, addSourceMiddleware() {} }
|
|
176
|
+
|
|
177
|
+
nock('https://cdn.hightouch-events.com')
|
|
178
|
+
.get('/v1/projects/123/integrations')
|
|
179
|
+
.reply(200, [
|
|
180
|
+
{
|
|
181
|
+
name: 'Google Analytics',
|
|
182
|
+
creationName: 'Google Analytics'
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
name: 'Amplitude',
|
|
186
|
+
creationName: 'Amplitude'
|
|
187
|
+
}
|
|
188
|
+
])
|
|
189
|
+
|
|
190
|
+
shallow(
|
|
191
|
+
<ConsentManagerBuilder
|
|
192
|
+
defaultDestinationBehavior="imply"
|
|
193
|
+
writeKey="123"
|
|
194
|
+
mapCustomPreferences={(destinations, preferences) => {
|
|
195
|
+
const destinationPreferences = {}
|
|
196
|
+
const customPreferences = {}
|
|
197
|
+
// Default unset preferences to true (for implicit consent)
|
|
198
|
+
for (const preferenceName of Object.keys(preferences)) {
|
|
199
|
+
const value = preferences[preferenceName]
|
|
200
|
+
if (typeof value === 'boolean') {
|
|
201
|
+
customPreferences[preferenceName] = value
|
|
202
|
+
} else {
|
|
203
|
+
customPreferences[preferenceName] = true
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const customPrefs = customPreferences
|
|
208
|
+
|
|
209
|
+
for (const destination of destinations) {
|
|
210
|
+
// Mark advertising destinations
|
|
211
|
+
if (
|
|
212
|
+
ADVERTISING_CATEGORIES.find(c => c === destination.category) &&
|
|
213
|
+
destinationPreferences[destination.id] !== false
|
|
214
|
+
) {
|
|
215
|
+
destinationPreferences[destination.id] = customPrefs.advertising
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Mark function destinations
|
|
219
|
+
if (
|
|
220
|
+
FUNCTIONAL_CATEGORIES.find(c => c === destination.category) &&
|
|
221
|
+
destinationPreferences[destination.id] !== false
|
|
222
|
+
) {
|
|
223
|
+
destinationPreferences[destination.id] = customPrefs.functional
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// Fallback to marketing
|
|
227
|
+
if (!(destination.id in destinationPreferences)) {
|
|
228
|
+
destinationPreferences[destination.id] = customPrefs.marketingAndAnalytics
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return { destinationPreferences, customPreferences }
|
|
233
|
+
}}
|
|
234
|
+
>
|
|
235
|
+
{({ destinationPreferences }) => {
|
|
236
|
+
expect(destinationPreferences).toMatchObject({
|
|
237
|
+
Amplitude: true,
|
|
238
|
+
'Google Analytics': true
|
|
239
|
+
})
|
|
240
|
+
done()
|
|
241
|
+
}}
|
|
242
|
+
</ConsentManagerBuilder>
|
|
243
|
+
)
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
test.skip('if defaultDestinationBehavior is set to imply and category is set to false, does not load new destination', done => {
|
|
247
|
+
document.cookie =
|
|
248
|
+
'ht-cm-preferences={%22version%22:1%2C%22destinations%22:{%22Amplitude%22:true}%2C%22custom%22:{%22advertising%22:false%2C%22marketingAndAnalytics%22:false%2C%22functional%22:true}}'
|
|
249
|
+
window.htevents = {
|
|
250
|
+
load() {},
|
|
251
|
+
identify() {},
|
|
252
|
+
track() {},
|
|
253
|
+
addSourceMiddleware() {}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
nock('https://cdn.hightouch-events.com')
|
|
257
|
+
.get('/v1/projects/123/integrations')
|
|
258
|
+
.reply(200, [
|
|
259
|
+
{
|
|
260
|
+
name: 'Google Analytics',
|
|
261
|
+
creationName: 'Google Analytics'
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
name: 'Amplitude',
|
|
265
|
+
creationName: 'Amplitude'
|
|
266
|
+
}
|
|
267
|
+
])
|
|
268
|
+
|
|
269
|
+
shallow(
|
|
270
|
+
<ConsentManagerBuilder
|
|
271
|
+
defaultDestinationBehavior="imply"
|
|
272
|
+
writeKey="123"
|
|
273
|
+
mapCustomPreferences={(destinations, preferences) => {
|
|
274
|
+
const destinationPreferences = {}
|
|
275
|
+
const customPreferences = {}
|
|
276
|
+
|
|
277
|
+
// Default unset preferences to true (for implicit consent)
|
|
278
|
+
for (const preferenceName of Object.keys(preferences)) {
|
|
279
|
+
const value = preferences[preferenceName]
|
|
280
|
+
if (typeof value === 'boolean') {
|
|
281
|
+
customPreferences[preferenceName] = value
|
|
282
|
+
} else {
|
|
283
|
+
customPreferences[preferenceName] = true
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const customPrefs = customPreferences
|
|
288
|
+
|
|
289
|
+
for (const destination of destinations) {
|
|
290
|
+
// Mark advertising destinations
|
|
291
|
+
if (
|
|
292
|
+
ADVERTISING_CATEGORIES.find(c => c === destination.category) &&
|
|
293
|
+
destinationPreferences[destination.id] !== false
|
|
294
|
+
) {
|
|
295
|
+
destinationPreferences[destination.id] = customPrefs.advertising
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// Mark function destinations
|
|
299
|
+
if (
|
|
300
|
+
FUNCTIONAL_CATEGORIES.find(c => c === destination.category) &&
|
|
301
|
+
destinationPreferences[destination.id] !== false
|
|
302
|
+
) {
|
|
303
|
+
destinationPreferences[destination.id] = customPrefs.functional
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// Fallback to marketing
|
|
307
|
+
if (!(destination.id in destinationPreferences)) {
|
|
308
|
+
destinationPreferences[destination.id] = customPrefs.marketingAndAnalytics
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
return { destinationPreferences, customPreferences }
|
|
313
|
+
}}
|
|
314
|
+
>
|
|
315
|
+
{({ destinationPreferences }) => {
|
|
316
|
+
expect(destinationPreferences).toMatchObject({
|
|
317
|
+
Amplitude: false,
|
|
318
|
+
'Google Analytics': false
|
|
319
|
+
})
|
|
320
|
+
done()
|
|
321
|
+
}}
|
|
322
|
+
</ConsentManagerBuilder>
|
|
323
|
+
)
|
|
324
|
+
})
|
|
325
|
+
|
|
326
|
+
test.skip('a different cdn is used when cdnHost is set', done => {
|
|
327
|
+
nock('https://foo.bar.com')
|
|
328
|
+
.get('/v1/projects/123/integrations')
|
|
329
|
+
.reply(200, [
|
|
330
|
+
{
|
|
331
|
+
name: 'Google Analytics',
|
|
332
|
+
creationName: 'Google Analytics'
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
name: 'Amplitude',
|
|
336
|
+
creationName: 'Amplitude'
|
|
337
|
+
}
|
|
338
|
+
])
|
|
339
|
+
.get('/v1/projects/abc/integrations')
|
|
340
|
+
.reply(200, [
|
|
341
|
+
{
|
|
342
|
+
name: 'FullStory',
|
|
343
|
+
creationName: 'FullStory'
|
|
344
|
+
}
|
|
345
|
+
])
|
|
346
|
+
|
|
347
|
+
shallow(
|
|
348
|
+
<ConsentManagerBuilder writeKey="123" cdnHost="foo.bar.com">
|
|
349
|
+
{({ destinations }) => {
|
|
350
|
+
expect(destinations).toMatchObject([
|
|
351
|
+
{
|
|
352
|
+
id: 'Amplitude',
|
|
353
|
+
name: 'Amplitude'
|
|
354
|
+
},
|
|
355
|
+
{
|
|
356
|
+
id: 'FullStory',
|
|
357
|
+
name: 'FullStory'
|
|
358
|
+
},
|
|
359
|
+
{
|
|
360
|
+
id: 'Google Analytics',
|
|
361
|
+
name: 'Google Analytics'
|
|
362
|
+
}
|
|
363
|
+
])
|
|
364
|
+
done()
|
|
365
|
+
}}
|
|
366
|
+
</ConsentManagerBuilder>
|
|
367
|
+
)
|
|
368
|
+
})
|
|
369
|
+
test.todo('loads events.js normally when consent isn՚t required')
|
|
370
|
+
test.todo('still applies preferences when consent isn՚t required')
|
|
371
|
+
test.todo('provides a setPreferences() function for setting the preferences')
|
|
372
|
+
test.todo('setPreferences() function can be passed a boolean to set all preferences')
|
|
373
|
+
test.todo('provides a resetPreferences() function for resetting the preferences')
|
|
374
|
+
test.todo(
|
|
375
|
+
'provides a saveConsent() function for persisting the preferences and loading events.js'
|
|
376
|
+
)
|
|
377
|
+
test.todo('saveConsent() can be passed additional preferences to persist')
|
|
378
|
+
test.todo('saveConsent() can be passed a boolean to set all preferences')
|
|
379
|
+
test.todo('saveConsent() fills in missing preferences')
|
|
380
|
+
test.todo('initialPreferences sets the initial preferences')
|
|
381
|
+
test.todo('loads custom preferences')
|
|
382
|
+
test.todo('saveConsent() maps custom preferences to destination preferences')
|
|
383
|
+
test.todo('mapCustomPreferences allows customPreferences to be updated')
|
|
384
|
+
test.todo('saveConsent() saves custom preferences')
|
|
385
|
+
test.todo('cookieDomain sets the cookie domain')
|
|
386
|
+
})
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { URL } from 'url'
|
|
2
|
+
import sinon from 'sinon'
|
|
3
|
+
import {
|
|
4
|
+
loadPreferences,
|
|
5
|
+
savePreferences,
|
|
6
|
+
DEFAULT_COOKIE_NAME
|
|
7
|
+
} from '../../consent-manager-builder/preferences'
|
|
8
|
+
|
|
9
|
+
describe('preferences', () => {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
window = {
|
|
12
|
+
location: {
|
|
13
|
+
href: 'http://localhost/'
|
|
14
|
+
}
|
|
15
|
+
} as Window & typeof globalThis
|
|
16
|
+
|
|
17
|
+
document = {
|
|
18
|
+
createElement(type: string) {
|
|
19
|
+
if (type === 'a') {
|
|
20
|
+
return new URL('http://localhost/')
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return
|
|
24
|
+
}
|
|
25
|
+
} as Document
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
test('loadPreferences() returns preferences when cookie exists', () => {
|
|
29
|
+
document.cookie = `${DEFAULT_COOKIE_NAME}={%22version%22:1%2C%22destination%22:{%22Amplitude%22:true}%2C%22custom%22:{%22functional%22:true}}`
|
|
30
|
+
|
|
31
|
+
expect(loadPreferences()).toMatchObject({
|
|
32
|
+
destinationPreferences: {
|
|
33
|
+
Amplitude: true
|
|
34
|
+
},
|
|
35
|
+
customPreferences: {
|
|
36
|
+
functional: true
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
test('loadPreferences(cookieName) returns preferences when cookie exists', () => {
|
|
42
|
+
document.cookie =
|
|
43
|
+
'custom-tracking-preferences={%22version%22:1%2C%22destination%22:{%22Amplitude%22:true}%2C%22custom%22:{%22functional%22:true}}'
|
|
44
|
+
|
|
45
|
+
expect(loadPreferences('custom-tracking-preferences')).toMatchObject({
|
|
46
|
+
destinationPreferences: {
|
|
47
|
+
Amplitude: true
|
|
48
|
+
},
|
|
49
|
+
customPreferences: {
|
|
50
|
+
functional: true
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
test('savePreferences() saves the preferences', () => {
|
|
56
|
+
const htevents = { identify: sinon.spy(), track: sinon.spy() }
|
|
57
|
+
;(window as any).htevents = htevents
|
|
58
|
+
document.cookie = ''
|
|
59
|
+
|
|
60
|
+
const destinationPreferences = {
|
|
61
|
+
Amplitude: true
|
|
62
|
+
}
|
|
63
|
+
const customPreferences = {
|
|
64
|
+
functional: true
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
savePreferences({
|
|
68
|
+
destinationPreferences,
|
|
69
|
+
customPreferences,
|
|
70
|
+
cookieDomain: undefined
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
expect(htevents.identify.calledOnce).toBe(true)
|
|
74
|
+
expect(htevents.identify.args[0][0]).toMatchObject({
|
|
75
|
+
destinationTrackingPreferences: destinationPreferences,
|
|
76
|
+
categoryTrackingPreferences: customPreferences
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
expect(htevents.track.calledOnce).toBe(true)
|
|
80
|
+
expect(htevents.track.args[0][0]).toBe('Consent Updated')
|
|
81
|
+
expect(htevents.track.args[0][1]).toMatchObject({
|
|
82
|
+
destinationTrackingPreferences: destinationPreferences,
|
|
83
|
+
categoryTrackingPreferences: customPreferences
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
expect(
|
|
87
|
+
document.cookie.includes(
|
|
88
|
+
`${DEFAULT_COOKIE_NAME}={%22version%22:1%2C%22destination%22:{%22Amplitude%22:true}%2C%22custom%22:{%22functional%22:true}}`
|
|
89
|
+
)
|
|
90
|
+
).toBe(true)
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
test('savePreferences() sets the cookie domain', () => {
|
|
94
|
+
const htevents = { identify: sinon.spy(), track: sinon.spy() }
|
|
95
|
+
;(window as any).htevents = htevents
|
|
96
|
+
document.cookie = ''
|
|
97
|
+
|
|
98
|
+
const destinationPreferences = {
|
|
99
|
+
Amplitude: true
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
savePreferences({
|
|
103
|
+
destinationPreferences,
|
|
104
|
+
customPreferences: undefined,
|
|
105
|
+
cookieDomain: 'example.com'
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
expect(htevents.identify.calledOnce).toBe(true)
|
|
109
|
+
expect(htevents.identify.args[0][0]).toMatchObject({
|
|
110
|
+
destinationTrackingPreferences: destinationPreferences,
|
|
111
|
+
categoryTrackingPreferences: undefined
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
expect(htevents.track.calledOnce).toBe(true)
|
|
115
|
+
expect(htevents.track.args[0][0]).toBe('Consent Updated')
|
|
116
|
+
expect(htevents.track.args[0][1]).toMatchObject({
|
|
117
|
+
destinationTrackingPreferences: destinationPreferences,
|
|
118
|
+
categoryTrackingPreferences: undefined
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
// TODO: actually check domain
|
|
122
|
+
// expect(document.cookie.includes('domain=example.com')).toBe(true)
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
test('savePreferences() sets the cookie with custom key', () => {
|
|
126
|
+
const htevents = { identify: sinon.spy(), track: sinon.spy() }
|
|
127
|
+
;(window as any).htevents = htevents
|
|
128
|
+
document.cookie = ''
|
|
129
|
+
|
|
130
|
+
const destinationPreferences = {
|
|
131
|
+
Amplitude: true
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
savePreferences({
|
|
135
|
+
destinationPreferences,
|
|
136
|
+
customPreferences: undefined,
|
|
137
|
+
cookieDomain: undefined,
|
|
138
|
+
cookieName: 'custom-tracking-preferences'
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
expect(htevents.identify.calledOnce).toBe(true)
|
|
142
|
+
expect(htevents.identify.args[0][0]).toMatchObject({
|
|
143
|
+
destinationTrackingPreferences: destinationPreferences,
|
|
144
|
+
categoryTrackingPreferences: undefined
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
expect(htevents.track.calledOnce).toBe(true)
|
|
148
|
+
expect(htevents.track.args[0][0]).toBe('Consent Updated')
|
|
149
|
+
expect(htevents.track.args[0][1]).toMatchObject({
|
|
150
|
+
destinationTrackingPreferences: destinationPreferences,
|
|
151
|
+
categoryTrackingPreferences: undefined
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
expect(document.cookie.includes('custom-tracking-preferences')).toBe(true)
|
|
155
|
+
})
|
|
156
|
+
})
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { doNotTrack } from '../'
|
|
2
|
+
|
|
3
|
+
describe('doNotTrack', () => {
|
|
4
|
+
beforeEach(() => {
|
|
5
|
+
navigator = {} as Navigator
|
|
6
|
+
window = {} as Window & typeof globalThis
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
test('doNotTrack() supports standard API', () => {
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
navigator.doNotTrack = '1'
|
|
12
|
+
expect(doNotTrack()).toBe(true)
|
|
13
|
+
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
navigator.doNotTrack = '0'
|
|
16
|
+
expect(doNotTrack()).toBe(false)
|
|
17
|
+
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
navigator.doNotTrack = 'unspecified'
|
|
20
|
+
expect(doNotTrack()).toBe(null)
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
test('doNotTrack() supports window', () => {
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
navigator.doNotTrack = undefined
|
|
26
|
+
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
window.doNotTrack = '1'
|
|
29
|
+
expect(doNotTrack()).toBe(true)
|
|
30
|
+
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
window.doNotTrack = '0'
|
|
33
|
+
expect(doNotTrack()).toBe(false)
|
|
34
|
+
|
|
35
|
+
// @ts-ignore
|
|
36
|
+
window.doNotTrack = 'unspecified'
|
|
37
|
+
expect(doNotTrack()).toBeNull()
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
test('doNotTrack() support yes/no', () => {
|
|
41
|
+
// @ts-ignore
|
|
42
|
+
navigator.doNotTrack = 'yes'
|
|
43
|
+
expect(doNotTrack()).toBe(true)
|
|
44
|
+
|
|
45
|
+
// @ts-ignore
|
|
46
|
+
navigator.doNotTrack = 'no'
|
|
47
|
+
expect(doNotTrack()).toBe(false)
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
test('doNotTrack() supports ms prefix', () => {
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
navigator.doNotTrack = undefined
|
|
53
|
+
// @ts-ignore
|
|
54
|
+
window.doNotTrack = undefined
|
|
55
|
+
|
|
56
|
+
// @ts-ignore
|
|
57
|
+
navigator.msDoNotTrack = '1'
|
|
58
|
+
expect(doNotTrack()).toBe(true)
|
|
59
|
+
|
|
60
|
+
// @ts-ignore
|
|
61
|
+
navigator.msDoNotTrack = '0'
|
|
62
|
+
expect(doNotTrack()).toBe(false)
|
|
63
|
+
|
|
64
|
+
// @ts-ignore
|
|
65
|
+
navigator.msDoNotTrack = 'unspecified'
|
|
66
|
+
expect(doNotTrack()).toBeNull()
|
|
67
|
+
})
|
|
68
|
+
})
|