1
- import { getConsent } from "./consent" ;
1
+ import { getConsent , applicableReg } from "./consent" ;
2
2
import * as gpp from "./gpp" ;
3
3
4
4
const allowAll = {
@@ -15,6 +15,75 @@ const denyAll = {
15
15
measureAdvertisingPerformance : false ,
16
16
} ;
17
17
18
+ describe ( "applicableReg" , ( ) => {
19
+ it ( "returns gdpr when cmp indicates gdpr applies" , ( ) => {
20
+ expect ( applicableReg ( "can" , { gdprApplies : true } ) ) . toBe ( "gdpr" ) ;
21
+ expect ( applicableReg ( "us" , { gdprApplies : true } ) ) . toBe ( "gdpr" ) ;
22
+ expect ( applicableReg ( null , { gdprApplies : true } ) ) . toBe ( "gdpr" ) ;
23
+
24
+ expect ( applicableReg ( "can" , { gppSectionIDs : [ 2 ] } ) ) . toBe ( "gdpr" ) ;
25
+ expect ( applicableReg ( "us" , { gppSectionIDs : [ 2 ] } ) ) . toBe ( "gdpr" ) ;
26
+ expect ( applicableReg ( null , { gppSectionIDs : [ 2 ] } ) ) . toBe ( "gdpr" ) ;
27
+ } ) ;
28
+
29
+ it ( "returns can when cmp indicates can applies" , ( ) => {
30
+ expect ( applicableReg ( "gdpr" , { gppSectionIDs : [ 5 ] } ) ) . toBe ( "can" ) ;
31
+ expect ( applicableReg ( "us" , { gppSectionIDs : [ 5 ] } ) ) . toBe ( "can" ) ;
32
+ expect ( applicableReg ( null , { gppSectionIDs : [ 5 ] } ) ) . toBe ( "can" ) ;
33
+ } ) ;
34
+
35
+ it ( "returns us when cmp indicates us applies" , ( ) => {
36
+ expect ( applicableReg ( "gdpr" , { gppSectionIDs : [ 7 ] } ) ) . toBe ( "us" ) ;
37
+ expect ( applicableReg ( "can" , { gppSectionIDs : [ 7 ] } ) ) . toBe ( "us" ) ;
38
+ expect ( applicableReg ( null , { gppSectionIDs : [ 7 ] } ) ) . toBe ( "us" ) ;
39
+ } ) ;
40
+
41
+ it ( "returns unknown when cmp indicates detected regulation does not apply" , ( ) => {
42
+ expect ( applicableReg ( "gdpr" , { gdprApplies : false } ) ) . toBe ( null ) ;
43
+ expect ( applicableReg ( "gdpr" , { gppSectionIDs : [ 999 ] } ) ) . toBe ( null ) ;
44
+ expect ( applicableReg ( "gdpr" , { gppSectionIDs : [ - 1 ] } ) ) . toBe ( null ) ;
45
+
46
+ expect ( applicableReg ( "can" , { gppSectionIDs : [ 999 ] } ) ) . toBe ( null ) ;
47
+ expect ( applicableReg ( "can" , { gppSectionIDs : [ - 1 ] } ) ) . toBe ( null ) ;
48
+
49
+ expect ( applicableReg ( "us" , { gppSectionIDs : [ 999 ] } ) ) . toBe ( null ) ;
50
+ expect ( applicableReg ( "us" , { gppSectionIDs : [ - 1 ] } ) ) . toBe ( null ) ;
51
+ } ) ;
52
+
53
+ it ( "prefers tcf signaling over gpp" , ( ) => {
54
+ expect ( applicableReg ( "gdpr" , { gdprApplies : true , gppSectionIDs : [ 8 ] } ) ) . toBe ( "gdpr" ) ;
55
+ expect ( applicableReg ( "can" , { gdprApplies : true , gppSectionIDs : [ 5 ] } ) ) . toBe ( "gdpr" ) ;
56
+ expect ( applicableReg ( "us" , { gdprApplies : true , gppSectionIDs : [ - 1 ] } ) ) . toBe ( "gdpr" ) ;
57
+ expect ( applicableReg ( "gdpr" , { gdprApplies : false , gppSectionIDs : [ 8 ] } ) ) . toBe ( null ) ;
58
+ expect ( applicableReg ( "can" , { gdprApplies : false , gppSectionIDs : [ 5 ] } ) ) . toBe ( "can" ) ;
59
+ expect ( applicableReg ( "us" , { gdprApplies : false , gppSectionIDs : [ - 1 ] } ) ) . toBe ( "us" ) ;
60
+
61
+ // presence of gdprData may resolve to gdpr only if it was detected as well
62
+ expect ( applicableReg ( "gdpr" , { gdprData : { } } ) ) . toBe ( "gdpr" ) ;
63
+ expect ( applicableReg ( null , { gdprData : { } } ) ) . toBe ( null ) ;
64
+ expect ( applicableReg ( "can" , { gdprData : { } } ) ) . toBe ( "can" ) ;
65
+ } ) ;
66
+
67
+ it ( "infers gdpr>can>us when using gpp" , ( ) => {
68
+ expect ( applicableReg ( null , { gppSectionIDs : [ 2 , 5 , 7 , 8 ] } ) ) . toBe ( "gdpr" ) ;
69
+ expect ( applicableReg ( null , { gppSectionIDs : [ 5 , 7 , 8 ] } ) ) . toBe ( "can" ) ;
70
+ expect ( applicableReg ( null , { gppSectionIDs : [ 7 , 8 ] } ) ) . toBe ( "us" ) ;
71
+ expect ( applicableReg ( null , { gppSectionIDs : [ 8 ] } ) ) . toBe ( "us" ) ;
72
+ expect ( applicableReg ( null , { gppSectionIDs : [ ] } ) ) . toBe ( null ) ;
73
+ } ) ;
74
+
75
+ it ( "returns reg until cmp knows" , ( ) => {
76
+ expect ( applicableReg ( "gdpr" , { } ) ) . toBe ( "gdpr" ) ;
77
+ expect ( applicableReg ( "gdpr" , { gppSectionIDs : [ 0 ] } ) ) . toBe ( "gdpr" ) ;
78
+
79
+ expect ( applicableReg ( "can" , { } ) ) . toBe ( "can" ) ;
80
+ expect ( applicableReg ( "can" , { gppSectionIDs : [ 0 ] } ) ) . toBe ( "can" ) ;
81
+
82
+ expect ( applicableReg ( "us" , { } ) ) . toBe ( "us" ) ;
83
+ expect ( applicableReg ( "us" , { gppSectionIDs : [ 0 ] } ) ) . toBe ( "us" ) ;
84
+ } ) ;
85
+ } ) ;
86
+
18
87
describe ( "getConsent" , ( ) => {
19
88
afterEach ( ( ) => {
20
89
Object . defineProperties ( window , {
@@ -64,7 +133,7 @@ describe("getConsent", () => {
64
133
// Simulate event indicating that gdpr doesn't apply
65
134
signal ( tcfData ( { gdprApplies : false , tcString : "doesntapply" } ) ) ;
66
135
expect ( consent . deviceAccess ) . toBe ( true ) ;
67
- expect ( consent . tcf ) . toBeUndefined ( ) ;
136
+ expect ( consent . gdpr ) . toBe ( "doesntapply" ) ;
68
137
69
138
// Simulate event where no consent is granted
70
139
signal (
@@ -74,7 +143,7 @@ describe("getConsent", () => {
74
143
} )
75
144
) ;
76
145
expect ( consent . deviceAccess ) . toBe ( false ) ;
77
- expect ( consent . tcf ) . toBe ( "noconsent" ) ;
146
+ expect ( consent . gdpr ) . toBe ( "noconsent" ) ;
78
147
79
148
// Simulate event where purpose 1 consent is granted to the publisher
80
149
signal (
@@ -84,7 +153,7 @@ describe("getConsent", () => {
84
153
} )
85
154
) ;
86
155
expect ( consent . deviceAccess ) . toBe ( true ) ;
87
- expect ( consent . tcf ) . toBe ( "purpose1" ) ;
156
+ expect ( consent . gdpr ) . toBe ( "purpose1" ) ;
88
157
89
158
// Simulate removing consent
90
159
signal (
@@ -94,7 +163,7 @@ describe("getConsent", () => {
94
163
} )
95
164
) ;
96
165
expect ( consent . deviceAccess ) . toBe ( false ) ;
97
- expect ( consent . tcf ) . toBe ( "revoked" ) ;
166
+ expect ( consent . gdpr ) . toBe ( "revoked" ) ;
98
167
} ) ;
99
168
100
169
it ( "updates consent based on gpp signals for gdpr" , ( ) => {
@@ -105,11 +174,11 @@ describe("getConsent", () => {
105
174
expect ( consent . deviceAccess ) . toBe ( false ) ;
106
175
expect ( consent . reg ) . toBe ( "gdpr" ) ;
107
176
108
- // Simulate gpp ready event indicating no applicable sections
109
- signal ( { applicableSections : [ - 1 ] , gppString : "ignored" } ) ;
110
- expect ( consent . deviceAccess ) . toBe ( true ) ;
177
+ // Simulate gpp ready event indicating applicable sections unknown
178
+ signal ( { applicableSections : [ 0 ] , gppString : "ignored" } ) ;
179
+ expect ( consent . deviceAccess ) . toBe ( false ) ;
111
180
expect ( consent . gpp ) . toBe ( "ignored" ) ;
112
- expect ( consent . gppSectionIDs ) . toEqual ( [ - 1 ] ) ;
181
+ expect ( consent . gppSectionIDs ) . toEqual ( [ 0 ] ) ;
113
182
114
183
// Section tcfeuv2 applies but nothing in parsed sections
115
184
signal ( { parsedSections : { } , applicableSections : [ gpp . tcfeuv2 . SectionID ] , gppString : "noparsedsections" } ) ;
@@ -247,7 +316,7 @@ describe("getConsent", () => {
247
316
) ;
248
317
249
318
expect ( consent . deviceAccess ) . toBe ( true ) ;
250
- expect ( consent . tcf ) . toBe ( "granted" ) ;
319
+ expect ( consent . gdpr ) . toBe ( "granted" ) ;
251
320
expect ( consent . gpp ) . toBe ( "revoked" ) ;
252
321
} ) ;
253
322
0 commit comments