1
1
import { criteoIdSubmodule , storage } from 'modules/criteoIdSystem.js' ;
2
2
import * as utils from 'src/utils.js' ;
3
+ import { gdprDataHandler , uspDataHandler , gppDataHandler } from '../../../src/adapterManager.js' ;
3
4
import { server } from '../../mocks/xhr' ;
4
5
5
6
const pastDateString = new Date ( 0 ) . toString ( )
@@ -17,6 +18,9 @@ describe('CriteoId module', function () {
17
18
let timeStampStub ;
18
19
let parseUrlStub ;
19
20
let triggerPixelStub ;
21
+ let gdprConsentDataStub ;
22
+ let uspConsentDataStub ;
23
+ let gppConsentDataStub ;
20
24
21
25
beforeEach ( function ( done ) {
22
26
getCookieStub = sinon . stub ( storage , 'getCookie' ) ;
@@ -27,6 +31,9 @@ describe('CriteoId module', function () {
27
31
timeStampStub = sinon . stub ( utils , 'timestamp' ) . returns ( nowTimestamp ) ;
28
32
parseUrlStub = sinon . stub ( utils , 'parseUrl' ) . returns ( { protocol : 'https' , hostname : 'testdev.com' } )
29
33
triggerPixelStub = sinon . stub ( utils , 'triggerPixel' ) ;
34
+ gdprConsentDataStub = sinon . stub ( gdprDataHandler , 'getConsentData' ) ;
35
+ uspConsentDataStub = sinon . stub ( uspDataHandler , 'getConsentData' ) ;
36
+ gppConsentDataStub = sinon . stub ( gppDataHandler , 'getConsentData' ) ;
30
37
done ( ) ;
31
38
} ) ;
32
39
@@ -39,6 +46,9 @@ describe('CriteoId module', function () {
39
46
timeStampStub . restore ( ) ;
40
47
triggerPixelStub . restore ( ) ;
41
48
parseUrlStub . restore ( ) ;
49
+ gdprConsentDataStub . restore ( ) ;
50
+ uspConsentDataStub . restore ( ) ;
51
+ gppConsentDataStub . restore ( ) ;
42
52
} ) ;
43
53
44
54
const storageTestCases = [
@@ -136,11 +146,11 @@ describe('CriteoId module', function () {
136
146
} ) ) ;
137
147
138
148
const gdprConsentTestCases = [
139
- { consentData : { gdprApplies : true , consentString : 'expectedConsentString' } , expected : 'expectedConsentString' } ,
140
- { consentData : { gdprApplies : false , consentString : 'expectedConsentString' } , expected : undefined } ,
141
- { consentData : { gdprApplies : true , consentString : undefined } , expected : undefined } ,
142
- { consentData : { gdprApplies : 'oui' , consentString : 'expectedConsentString' } , expected : undefined } ,
143
- { consentData : undefined , expected : undefined }
149
+ { consentData : { gdprApplies : true , consentString : 'expectedConsentString' } , expectedGdprConsent : 'expectedConsentString' , expectedGdpr : '1 ' } ,
150
+ { consentData : { gdprApplies : false , consentString : 'expectedConsentString' } , expectedGdprConsent : 'expectedConsentString' , expectedGdpr : '0' } ,
151
+ { consentData : { gdprApplies : true , consentString : undefined } , expectedGdprConsent : undefined , expectedGdpr : '1' } ,
152
+ { consentData : { gdprApplies : 'oui' , consentString : 'expectedConsentString' } , expectedGdprConsent : 'expectedConsentString' , expectedGdpr : '0' } ,
153
+ { consentData : undefined , expectedGdprConsent : undefined , expectedGdpr : undefined }
144
154
] ;
145
155
146
156
it ( 'should call sync pixels if request by backend' , function ( ) {
@@ -225,14 +235,94 @@ describe('CriteoId module', function () {
225
235
226
236
gdprConsentTestCases . forEach ( testCase => it ( 'should call user sync url with the gdprConsent' , function ( ) {
227
237
let callBackSpy = sinon . spy ( ) ;
228
- let result = criteoIdSubmodule . getId ( undefined , testCase . consentData ) ;
238
+
239
+ gdprConsentDataStub . returns ( testCase . consentData ) ;
240
+
241
+ let result = criteoIdSubmodule . getId ( undefined ) ;
242
+ result . callback ( callBackSpy ) ;
243
+
244
+ let request = server . requests [ 0 ] ;
245
+
246
+ if ( testCase . expectedGdprConsent ) {
247
+ expect ( request . url ) . to . have . string ( `gdprString=${ testCase . expectedGdprConsent } ` ) ;
248
+ } else {
249
+ expect ( request . url ) . to . not . have . string ( 'gdprString=' ) ;
250
+ }
251
+
252
+ if ( testCase . expectedGdpr ) {
253
+ expect ( request . url ) . to . have . string ( `gdpr=${ testCase . expectedGdpr } ` ) ;
254
+ } else {
255
+ expect ( request . url ) . to . not . have . string ( 'gdpr=' ) ;
256
+ }
257
+
258
+ request . respond (
259
+ 200 ,
260
+ { 'Content-Type' : 'application/json' } ,
261
+ JSON . stringify ( { } )
262
+ ) ;
263
+
264
+ expect ( callBackSpy . calledOnce ) . to . be . true ;
265
+ } ) ) ;
266
+
267
+ [ undefined , 'abc' ] . forEach ( usPrivacy => it ( 'should call user sync url with the us privacy string' , function ( ) {
268
+ let callBackSpy = sinon . spy ( ) ;
269
+
270
+ uspConsentDataStub . returns ( usPrivacy ) ;
271
+
272
+ let result = criteoIdSubmodule . getId ( undefined ) ;
229
273
result . callback ( callBackSpy ) ;
230
274
231
275
let request = server . requests [ 0 ] ;
232
- if ( testCase . expected ) {
233
- expect ( request . url ) . to . have . string ( `gdprString=${ testCase . expected } ` ) ;
276
+
277
+ if ( usPrivacy ) {
278
+ expect ( request . url ) . to . have . string ( `us_privacy=${ usPrivacy } ` ) ;
279
+ } else {
280
+ expect ( request . url ) . to . not . have . string ( 'us_privacy=' ) ;
281
+ }
282
+
283
+ request . respond (
284
+ 200 ,
285
+ { 'Content-Type' : 'application/json' } ,
286
+ JSON . stringify ( { } )
287
+ ) ;
288
+
289
+ expect ( callBackSpy . calledOnce ) . to . be . true ;
290
+ } ) ) ;
291
+
292
+ [
293
+ {
294
+ consentData : {
295
+ gppString : 'abc' ,
296
+ applicableSections : [ 1 ]
297
+ } ,
298
+ expectedGpp : 'abc' ,
299
+ expectedGppSid : '1'
300
+ } ,
301
+ {
302
+ consentData : undefined ,
303
+ expectedGpp : undefined ,
304
+ expectedGppSid : undefined
305
+ }
306
+ ] . forEach ( testCase => it ( 'should call user sync url with the gpp string' , function ( ) {
307
+ let callBackSpy = sinon . spy ( ) ;
308
+
309
+ gppConsentDataStub . returns ( testCase . consentData ) ;
310
+
311
+ let result = criteoIdSubmodule . getId ( undefined ) ;
312
+ result . callback ( callBackSpy ) ;
313
+
314
+ let request = server . requests [ 0 ] ;
315
+
316
+ if ( testCase . expectedGpp ) {
317
+ expect ( request . url ) . to . have . string ( `gpp=${ testCase . expectedGpp } ` ) ;
318
+ } else {
319
+ expect ( request . url ) . to . not . have . string ( 'gpp=' ) ;
320
+ }
321
+
322
+ if ( testCase . expectedGppSid ) {
323
+ expect ( request . url ) . to . have . string ( `gpp_sid=${ testCase . expectedGppSid } ` ) ;
234
324
} else {
235
- expect ( request . url ) . to . not . have . string ( 'gdprString ' ) ;
325
+ expect ( request . url ) . to . not . have . string ( 'gpp_sid= ' ) ;
236
326
}
237
327
238
328
request . respond (
0 commit comments