@@ -10,7 +10,13 @@ describe('Bing Ads', function() {
1010  var  analytics ; 
1111  var  bing ; 
1212  var  options  =  { 
13-     tagId : '4002754' 
13+     tagId : '4002754' , 
14+     enableConsent : true , 
15+     adStoragePropertyMapping : '' , 
16+     adStorage : 'denied' , 
17+     consentSettings : { 
18+       categories : [ ] 
19+     } 
1420  } ; 
1521
1622  beforeEach ( function ( )  { 
@@ -44,6 +50,58 @@ describe('Bing Ads', function() {
4450    } ) ; 
4551  } ) ; 
4652
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+ 
47105  describe ( 'after loading' ,  function ( )  { 
48106    beforeEach ( function ( done )  { 
49107      analytics . once ( 'ready' ,  done ) ; 
@@ -75,6 +133,51 @@ describe('Bing Ads', function() {
75133          gv : 90 
76134        } ) ; 
77135      } ) ; 
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+       } ) ; 
78181    } ) ; 
79182  } ) ; 
80183} ) ; 
0 commit comments