@@ -4,17 +4,22 @@ import {newBidder} from 'src/adapters/bidderFactory';
4
4
5
5
describe ( 'orbidderBidAdapter' , ( ) => {
6
6
const adapter = newBidder ( spec ) ;
7
- const bidRequest = {
7
+ const defaultBidRequest = {
8
8
bidId : 'd66fa86787e0b0ca900a96eacfd5f0bb' ,
9
9
auctionId : 'ccc4c7cdfe11cfbd74065e6dd28413d8' ,
10
10
transactionId : 'd58851660c0c4461e4aa06344fc9c0c6' ,
11
11
adUnitCode : 'adunit-code' ,
12
12
sizes : [ [ 300 , 250 ] , [ 300 , 600 ] ] ,
13
13
params : {
14
- 'foo' : 'bar'
14
+ 'accountId' : 'string1' ,
15
+ 'placementId' : 'string2'
15
16
}
16
17
} ;
17
18
19
+ const deepClone = function ( val ) {
20
+ return JSON . parse ( JSON . stringify ( val ) ) ;
21
+ } ;
22
+
18
23
const buildRequest = function ( buildRequest ) {
19
24
return spec . buildRequests (
20
25
[ buildRequest ] ,
@@ -23,7 +28,7 @@ describe('orbidderBidAdapter', () => {
23
28
referer : 'http://localhost:9876/'
24
29
}
25
30
} ) [ 0 ] ;
26
- }
31
+ } ;
27
32
28
33
describe ( 'inherited functions' , ( ) => {
29
34
it ( 'exists and is a function' , ( ) => {
@@ -33,18 +38,36 @@ describe('orbidderBidAdapter', () => {
33
38
34
39
describe ( 'isBidRequestValid' , ( ) => {
35
40
it ( 'should return true when required params found' , ( ) => {
41
+ expect ( spec . isBidRequestValid ( defaultBidRequest ) ) . to . equal ( true ) ;
42
+ } ) ;
43
+
44
+ it ( 'accepts optional keyValues object' , ( ) => {
45
+ const bidRequest = deepClone ( defaultBidRequest ) ;
46
+ bidRequest . params . keyValues = { 'key' : 'value' } ;
36
47
expect ( spec . isBidRequestValid ( bidRequest ) ) . to . equal ( true ) ;
37
48
} ) ;
38
49
50
+ it ( 'performs type checking' , ( ) => {
51
+ const bidRequest = deepClone ( defaultBidRequest ) ;
52
+ bidRequest . params . accountId = 1 ; // supposed to be a string
53
+ expect ( spec . isBidRequestValid ( bidRequest ) ) . to . equal ( false ) ;
54
+ } ) ;
55
+
56
+ it ( 'doesn\'t accept malformed keyValues' , ( ) => {
57
+ const bidRequest = deepClone ( defaultBidRequest ) ;
58
+ bidRequest . params . keyValues = 'another not usable string' ;
59
+ expect ( spec . isBidRequestValid ( bidRequest ) ) . to . equal ( false ) ;
60
+ } ) ;
61
+
39
62
it ( 'should return false when required params are not passed' , ( ) => {
40
- let bidRequest = Object . assign ( { } , bidRequest ) ;
63
+ const bidRequest = deepClone ( defaultBidRequest ) ;
41
64
delete bidRequest . params ;
42
65
expect ( spec . isBidRequestValid ( bidRequest ) ) . to . equal ( false ) ;
43
66
} ) ;
44
67
} ) ;
45
68
46
69
describe ( 'buildRequests' , ( ) => {
47
- const request = buildRequest ( bidRequest ) ;
70
+ const request = buildRequest ( defaultBidRequest ) ;
48
71
49
72
it ( 'sends bid request to endpoint via https using post' , ( ) => {
50
73
expect ( request . method ) . to . equal ( 'POST' ) ;
@@ -54,24 +77,24 @@ describe('orbidderBidAdapter', () => {
54
77
55
78
it ( 'sends correct bid parameters' , ( ) => {
56
79
// we add one, because we add referer information from bidderRequest object
57
- expect ( Object . keys ( request . data ) . length ) . to . equal ( Object . keys ( bidRequest ) . length + 1 ) ;
80
+ expect ( Object . keys ( request . data ) . length ) . to . equal ( Object . keys ( defaultBidRequest ) . length + 1 ) ;
58
81
expect ( request . data . pageUrl ) . to . equal ( 'http://localhost:9876/' ) ;
59
82
// expect(request.data.referrer).to.equal('');
60
- Object . keys ( bidRequest ) . forEach ( ( key ) => {
61
- expect ( bidRequest [ key ] ) . to . equal ( request . data [ key ] ) ;
83
+ Object . keys ( defaultBidRequest ) . forEach ( ( key ) => {
84
+ expect ( defaultBidRequest [ key ] ) . to . equal ( request . data [ key ] ) ;
62
85
} ) ;
63
86
} ) ;
64
87
65
88
it ( 'handles empty gdpr object' , ( ) => {
66
- let bidRequest = Object . assign ( { } , bidRequest ) ;
89
+ const bidRequest = deepClone ( defaultBidRequest ) ;
67
90
bidRequest . gdprConsent = { } ;
68
91
69
92
const request = buildRequest ( bidRequest ) ;
70
93
expect ( request . data . gdprConsent . consentRequired ) . to . be . equal ( true ) ;
71
94
} ) ;
72
95
73
96
it ( 'handles non-existent gdpr object' , ( ) => {
74
- let bidRequest = Object . assign ( { } , bidRequest ) ;
97
+ const bidRequest = deepClone ( defaultBidRequest ) ;
75
98
bidRequest . gdprConsent = null ;
76
99
77
100
const request = buildRequest ( bidRequest ) ;
@@ -80,7 +103,7 @@ describe('orbidderBidAdapter', () => {
80
103
81
104
it ( 'handles properly filled gdpr object where gdpr applies' , ( ) => {
82
105
const consentString = 'someWeirdString' ;
83
- const bidRequest = Object . assign ( { } , bidRequest ) ;
106
+ const bidRequest = deepClone ( defaultBidRequest ) ;
84
107
bidRequest . gdprConsent = {
85
108
gdprApplies : true ,
86
109
consentString : 'someWeirdString'
@@ -94,7 +117,7 @@ describe('orbidderBidAdapter', () => {
94
117
95
118
it ( 'handles properly filled gdpr object where gdpr does not apply' , ( ) => {
96
119
const consentString = 'someWeirdString' ;
97
- const bidRequest = Object . assign ( { } , bidRequest ) ;
120
+ const bidRequest = deepClone ( defaultBidRequest ) ;
98
121
bidRequest . gdprConsent = {
99
122
gdprApplies : false ,
100
123
consentString : 'someWeirdString'
@@ -110,6 +133,7 @@ describe('orbidderBidAdapter', () => {
110
133
describe ( 'onBidWon' , ( ) => {
111
134
let ajaxStub ;
112
135
const winObj = {
136
+ adId : 'testId' ,
113
137
test : 1 ,
114
138
pageUrl : 'www.someurl.de' ,
115
139
referrer : 'www.somereferrer.de'
0 commit comments