@@ -10,7 +10,13 @@ describe('Bing Ads', function() {
10
10
var analytics ;
11
11
var bing ;
12
12
var options = {
13
- tagId : '4002754'
13
+ tagId : '4002754' ,
14
+ enableConsent : true ,
15
+ adStoragePropertyMapping : '' ,
16
+ adStorage : 'denied' ,
17
+ consentSettings : {
18
+ categories : [ ]
19
+ }
14
20
} ;
15
21
16
22
beforeEach ( function ( ) {
@@ -44,6 +50,58 @@ describe('Bing Ads', function() {
44
50
} ) ;
45
51
} ) ;
46
52
53
+ describe ( '#initialize' , function ( ) {
54
+ beforeEach ( function ( ) {
55
+ window . uetq = [ ] ;
56
+ window . UET = function ( setup ) {
57
+ this . ti = setup . ti ;
58
+ this . q = setup . q ;
59
+ } ;
60
+ analytics . stub ( bing , 'load' , function ( callback ) {
61
+ callback ( ) ;
62
+ } ) ;
63
+ analytics . spy ( window . uetq , 'push' ) ;
64
+ } ) ;
65
+
66
+ afterEach ( function ( ) {
67
+ // Clean up after each test
68
+ delete window . uetq ;
69
+ } ) ;
70
+
71
+ it ( 'should initialize uetq as an empty array if not already defined' , function ( ) {
72
+ delete window . uetq ;
73
+ bing . options . enableConsent = false ;
74
+
75
+ bing . initialize ( ) ;
76
+
77
+ analytics . assert ( Array . isArray ( window . uetq . q ) ) ;
78
+ analytics . assert . deepEqual ( window . uetq . q , [ ] ) ;
79
+ } ) ;
80
+
81
+ it ( 'should push default consent if enableConsent is true' , function ( ) {
82
+ bing . options . enableConsent = true ;
83
+ bing . initialize ( ) ;
84
+ analytics . spy ( window . uetq , 'push' ) ;
85
+ analytics . called ( window . uetq . q . push , 'consent' , 'default' , {
86
+ ad_storage : 'denied'
87
+ } ) ;
88
+ } ) ;
89
+
90
+ it ( 'should not push default consent if enableConsent is false' , function ( ) {
91
+ bing . options . enableConsent = false ;
92
+ bing . initialize ( ) ;
93
+ analytics . spy ( window . uetq , 'push' ) ;
94
+ analytics . didNotCall ( window . uetq . push , 'consent' , 'default' ) ;
95
+ } ) ;
96
+
97
+ it ( 'should call load and set up UET after loading' , function ( ) {
98
+ bing . initialize ( ) ;
99
+ analytics . called ( bing . load ) ;
100
+ analytics . assert ( window . uetq instanceof window . UET ) ;
101
+ analytics . assert . equal ( window . uetq . ti , bing . options . tagId ) ;
102
+ } ) ;
103
+ } ) ;
104
+
47
105
describe ( 'after loading' , function ( ) {
48
106
beforeEach ( function ( done ) {
49
107
analytics . once ( 'ready' , done ) ;
@@ -75,6 +133,51 @@ describe('Bing Ads', function() {
75
133
gv : 90
76
134
} ) ;
77
135
} ) ;
136
+
137
+ it ( 'should not call updateConsent when enable_consent is false' , function ( ) {
138
+ bing . options . enableConsent = false ;
139
+ analytics . spy ( bing , 'updateConsent' ) ;
140
+ analytics . track ( 'play' , { category : 'fun' , revenue : 90 } ) ;
141
+ analytics . didNotCall ( bing . updateConsent ) ;
142
+ } ) ;
143
+
144
+ it ( 'should not update consent if ad_storagePropertyMapping is missing' , function ( ) {
145
+ bing . options . enableConsent = true ;
146
+ bing . options . adStoragePropertyMapping = '' ;
147
+ analytics . stub ( window . uetq , 'push' ) ;
148
+ analytics . track ( 'purchase' , { properties : { ad_storage : 'granted' } } ) ;
149
+ analytics . didNotCall ( window . uetq . push , 'consent' , 'update' ) ;
150
+ } ) ;
151
+
152
+ it ( 'should update consent if adStoragePropertyMapping has value' , function ( ) {
153
+ bing . options . enableConsent = true ;
154
+ bing . options . adStoragePropertyMapping = 'ad_storage' ;
155
+ analytics . stub ( window . uetq , 'push' ) ;
156
+ analytics . track ( 'purchase' , { ad_storage : 'granted' } ) ;
157
+ analytics . called ( window . uetq . push , 'consent' , 'update' , {
158
+ ad_storage : 'granted'
159
+ } ) ;
160
+ } ) ;
161
+
162
+ it ( 'should update consent based on consentSettings categories' , function ( ) {
163
+ bing . options . enable_consent = true ;
164
+ bing . options . consentSettings . categories = [ 'analytics' , 'ads' ] ;
165
+ bing . options . adStorageConsentCategory = 'ads' ;
166
+ analytics . stub ( window . uetq , 'push' ) ;
167
+ analytics . track ( 'purchase' ) ;
168
+ analytics . called ( window . uetq . push , 'consent' , 'update' , {
169
+ ad_storage : 'granted'
170
+ } ) ;
171
+ } ) ;
172
+
173
+ it ( 'should not update consent if consentSettings categories do not match' , function ( ) {
174
+ bing . options . enable_consent = true ;
175
+ bing . options . consentSettings . categories = [ 'analytics' ] ;
176
+ bing . options . adStorageConsentCategory = 'ads' ;
177
+ analytics . stub ( window . uetq , 'push' ) ;
178
+ analytics . track ( 'purchase' ) ;
179
+ analytics . didNotCall ( window . uetq . push , 'consent' , 'update' ) ;
180
+ } ) ;
78
181
} ) ;
79
182
} ) ;
80
183
} ) ;
0 commit comments