@@ -15,15 +15,24 @@ describe('the rubicon adapter', () => {
15
15
let sandbox ,
16
16
bidderRequest ;
17
17
18
- function addConsentManagement ( ) {
19
- bidderRequest . gdprConsent = {
20
- 'consentString' : 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==' ,
21
- 'gdprApplies' : true
18
+ /**
19
+ * @param {boolean } [gdprApplies]
20
+ */
21
+ function createGdprBidderRequest ( gdprApplies ) {
22
+ if ( typeof gdprApplies === 'boolean' ) {
23
+ bidderRequest . gdprConsent = {
24
+ 'consentString' : 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==' ,
25
+ 'gdprApplies' : gdprApplies
26
+ } ;
27
+ } else {
28
+ bidderRequest . gdprConsent = {
29
+ 'consentString' : 'BOJ/P2HOJ/P2HABABMAAAAAZ+A=='
30
+ } ;
22
31
}
23
32
}
24
33
25
34
function createVideoBidderRequest ( ) {
26
- addConsentManagement ( ) ;
35
+ createGdprBidderRequest ( true ) ;
27
36
28
37
let bid = bidderRequest . bids [ 0 ] ;
29
38
bid . mediaTypes = {
@@ -46,7 +55,7 @@ describe('the rubicon adapter', () => {
46
55
}
47
56
48
57
function createLegacyVideoBidderRequest ( ) {
49
- addConsentManagement ( ) ;
58
+ createGdprBidderRequest ( true ) ;
50
59
51
60
let bid = bidderRequest . bids [ 0 ] ;
52
61
// Legacy property (Prebid <1.0)
@@ -535,77 +544,43 @@ describe('the rubicon adapter', () => {
535
544
} ) ;
536
545
} ) ;
537
546
538
- it ( 'should send GDPR params when enabled' , ( ) => {
539
- addConsentManagement ( ) ;
547
+ describe ( 'GDPR consent config' , ( ) => {
548
+ it ( 'should send "gdpr" and "gdpr_consent", when gdprConsent defines consentString and gdprApplies' , ( ) => {
549
+ createGdprBidderRequest ( true ) ;
550
+ let [ request ] = spec . buildRequests ( bidderRequest . bids , bidderRequest ) ;
551
+ let data = parseQuery ( request . data ) ;
540
552
541
- sandbox . stub ( config , 'getConfig' ) . callsFake ( ( key ) => {
542
- var config = {
543
- consentManagement : {
544
- cmp : 'iab' ,
545
- waitForConsentTimeout : 4000 ,
546
- lookUpFailureResolution : 'cancel'
547
- }
548
- } ;
549
- return config [ key ] ;
553
+ expect ( data [ 'gdpr' ] ) . to . equal ( '1' ) ;
554
+ expect ( data [ 'gdpr_consent' ] ) . to . equal ( 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==' ) ;
550
555
} ) ;
551
556
552
- let [ request ] = spec . buildRequests ( bidderRequest . bids , bidderRequest ) ;
553
- let data = parseQuery ( request . data ) ;
554
- let expectedQuery = {
555
- 'gdpr' : '1' ,
556
- 'gdpr_consent' : 'BOJ/P2HOJ/P2HABABMAAAAAZ+A=='
557
- } ;
558
-
559
- // test that all values above are both present and correct
560
- Object . keys ( expectedQuery ) . forEach ( key => {
561
- let value = expectedQuery [ key ] ;
562
- expect ( data [ key ] ) . to . equal ( value ) ;
563
- } ) ;
564
- } ) ;
557
+ it ( 'should send only "gdpr_consent", when gdprConsent defines only consentString' , ( ) => {
558
+ createGdprBidderRequest ( ) ;
559
+ let [ request ] = spec . buildRequests ( bidderRequest . bids , bidderRequest ) ;
560
+ let data = parseQuery ( request . data ) ;
565
561
566
- it ( 'should not send GDPR params if not enabled' , ( ) => {
567
- sandbox . stub ( config , 'getConfig' ) . callsFake ( ( key ) => {
568
- var config = { } ;
569
- return config [ key ] ;
562
+ expect ( data [ 'gdpr_consent' ] ) . to . equal ( 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==' ) ;
563
+ expect ( data [ 'gdpr' ] ) . to . equal ( undefined ) ;
570
564
} ) ;
571
565
572
- let [ request ] = spec . buildRequests ( bidderRequest . bids , bidderRequest ) ;
573
- let data = parseQuery ( request . data ) ;
574
- let expectedQuery = {
575
- 'gdpr' : undefined ,
576
- 'gdpr_consent' : undefined
577
- } ;
578
-
579
- // test that all values above are both present and correct
580
- Object . keys ( expectedQuery ) . forEach ( key => {
581
- let value = expectedQuery [ key ] ;
582
- expect ( data [ key ] ) . to . equal ( value ) ;
583
- } ) ;
584
- } ) ;
566
+ it ( 'should not send GDPR params if gdprConsent is not defined' , ( ) => {
567
+ let [ request ] = spec . buildRequests ( bidderRequest . bids , bidderRequest ) ;
568
+ let data = parseQuery ( request . data ) ;
585
569
586
- it ( 'should not send GDPR params if gdprConsent is not set in config' , ( ) => {
587
- sandbox . stub ( config , 'getConfig' ) . callsFake ( ( key ) => {
588
- var config = {
589
- consentManagement : {
590
- cmp : 'iab' ,
591
- waitForConsentTimeout : 4000 ,
592
- lookUpFailureResolution : 'cancel'
593
- }
594
- } ;
595
- return config [ key ] ;
570
+ expect ( data [ 'gdpr' ] ) . to . equal ( undefined ) ;
571
+ expect ( data [ 'gdpr_consent' ] ) . to . equal ( undefined ) ;
596
572
} ) ;
597
573
598
- let [ request ] = spec . buildRequests ( bidderRequest . bids , bidderRequest ) ;
599
- let data = parseQuery ( request . data ) ;
600
- let expectedQuery = {
601
- 'gdpr' : undefined ,
602
- 'gdpr_consent' : undefined
603
- } ;
574
+ it ( 'should set "gdpr" value as 1 or 0, using "gdprApplies" value of either true/false' , ( ) => {
575
+ createGdprBidderRequest ( true ) ;
576
+ let [ request ] = spec . buildRequests ( bidderRequest . bids , bidderRequest ) ;
577
+ let data = parseQuery ( request . data ) ;
578
+ expect ( data [ 'gdpr' ] ) . to . equal ( '1' ) ;
604
579
605
- // test that all values above are both present and correct
606
- Object . keys ( expectedQuery ) . forEach ( key => {
607
- let value = expectedQuery [ key ] ;
608
- expect ( data [ key ] ) . to . equal ( value ) ;
580
+ createGdprBidderRequest ( false ) ;
581
+ [ request ] = spec . buildRequests ( bidderRequest . bids , bidderRequest ) ;
582
+ data = parseQuery ( request . data ) ;
583
+ expect ( data [ 'gdpr' ] ) . to . equal ( '0' ) ;
609
584
} ) ;
610
585
} ) ;
611
586
} ) ;
0 commit comments