1
1
import { expect } from 'chai' ;
2
2
import { spec } from 'modules/cointrafficBidAdapter.js' ;
3
+ import { config } from 'src/config.js'
4
+ import * as utils from 'src/utils.js'
3
5
4
6
const ENDPOINT_URL = 'https://appspb.cointraffic.io/pb/tmp' ;
5
7
@@ -37,7 +39,7 @@ describe('cointrafficBidAdapter', function () {
37
39
] ,
38
40
bidId : 'bidId12345' ,
39
41
bidderRequestId : 'bidderRequestId12345' ,
40
- auctionId : 'auctionId12345' ,
42
+ auctionId : 'auctionId12345'
41
43
} ,
42
44
{
43
45
bidder : 'cointraffic' ,
@@ -50,7 +52,7 @@ describe('cointrafficBidAdapter', function () {
50
52
] ,
51
53
bidId : 'bidId67890"' ,
52
54
bidderRequestId : 'bidderRequestId67890' ,
53
- auctionId : 'auctionId12345' ,
55
+ auctionId : 'auctionId12345'
54
56
}
55
57
] ;
56
58
@@ -65,34 +67,71 @@ describe('cointrafficBidAdapter', function () {
65
67
}
66
68
} ;
67
69
68
- const request = spec . buildRequests ( bidRequests , bidderRequests ) ;
70
+ it ( 'replaces currency with EUR if there is no currency provided' , function ( ) {
71
+ const request = spec . buildRequests ( bidRequests , bidderRequests ) ;
72
+
73
+ expect ( request [ 0 ] . data . currency ) . to . equal ( 'EUR' ) ;
74
+ expect ( request [ 1 ] . data . currency ) . to . equal ( 'EUR' ) ;
75
+ } ) ;
76
+
77
+ it ( 'replaces currency with EUR if there is no currency provided' , function ( ) {
78
+ const getConfigStub = sinon . stub ( config , 'getConfig' ) . callsFake (
79
+ arg => arg === 'currency.bidderCurrencyDefault.cointraffic' ? 'USD' : 'EUR'
80
+ ) ;
81
+
82
+ const request = spec . buildRequests ( bidRequests , bidderRequests ) ;
83
+
84
+ expect ( request [ 0 ] . data . currency ) . to . equal ( 'USD' ) ;
85
+ expect ( request [ 1 ] . data . currency ) . to . equal ( 'USD' ) ;
86
+
87
+ getConfigStub . restore ( ) ;
88
+ } ) ;
89
+
90
+ it ( 'throws an error if currency provided in params is not allowed' , function ( ) {
91
+ const utilsMock = sinon . mock ( utils ) . expects ( 'logError' ) . twice ( )
92
+ const getConfigStub = sinon . stub ( config , 'getConfig' ) . callsFake (
93
+ arg => arg === 'currency.bidderCurrencyDefault.cointraffic' ? 'BTC' : 'EUR'
94
+ ) ;
95
+
96
+ const request = spec . buildRequests ( bidRequests , bidderRequests ) ;
97
+
98
+ expect ( request [ 0 ] ) . to . undefined ;
99
+ expect ( request [ 1 ] ) . to . undefined ;
100
+
101
+ utilsMock . restore ( )
102
+ getConfigStub . restore ( ) ;
103
+ } ) ;
69
104
70
105
it ( 'sends bid request to our endpoint via POST' , function ( ) {
106
+ const request = spec . buildRequests ( bidRequests , bidderRequests ) ;
107
+
71
108
expect ( request [ 0 ] . method ) . to . equal ( 'POST' ) ;
72
109
expect ( request [ 1 ] . method ) . to . equal ( 'POST' ) ;
73
110
} ) ;
111
+
74
112
it ( 'attaches source and version to endpoint URL as query params' , function ( ) {
113
+ const request = spec . buildRequests ( bidRequests , bidderRequests ) ;
114
+
75
115
expect ( request [ 0 ] . url ) . to . equal ( ENDPOINT_URL ) ;
76
116
expect ( request [ 1 ] . url ) . to . equal ( ENDPOINT_URL ) ;
77
117
} ) ;
78
118
} ) ;
79
119
80
120
describe ( 'interpretResponse' , function ( ) {
81
- let bidRequest = [
82
- {
121
+ it ( 'should get the correct bid response' , function ( ) {
122
+ let bidRequest = [ {
83
123
method : 'POST' ,
84
124
url : ENDPOINT_URL ,
85
125
data : {
86
126
placementId : 'testPlacementId' ,
87
127
device : 'desktop' ,
128
+ currency : 'EUR' ,
88
129
sizes : [ '300x250' ] ,
89
130
bidId : 'bidId12345' ,
90
131
referer : 'www.example.com'
91
132
}
92
- }
93
- ] ;
133
+ } ] ;
94
134
95
- it ( 'should get the correct bid response' , function ( ) {
96
135
let serverResponse = {
97
136
body : {
98
137
requestId : 'bidId12345' ,
@@ -103,7 +142,7 @@ describe('cointrafficBidAdapter', function () {
103
142
height : 250 ,
104
143
creativeId : 'creativeId12345' ,
105
144
ttl : 90 ,
106
- ad : '<html><h3>I am an ad</h3></html> ' ,
145
+ ad : '<html><h3>I am an ad</h3></html> '
107
146
}
108
147
} ;
109
148
@@ -118,22 +157,99 @@ describe('cointrafficBidAdapter', function () {
118
157
ttl : 90 ,
119
158
ad : '<html><h3>I am an ad</h3></html>'
120
159
} ] ;
160
+
121
161
let result = spec . interpretResponse ( serverResponse , bidRequest [ 0 ] ) ;
122
162
expect ( Object . keys ( result ) ) . to . deep . equal ( Object . keys ( expectedResponse ) ) ;
123
163
} ) ;
124
164
125
- it ( 'should get empty bid response if server response body is empty' , function ( ) {
165
+ it ( 'should get the correct bid response with different currency' , function ( ) {
166
+ let bidRequest = [ {
167
+ method : 'POST' ,
168
+ url : ENDPOINT_URL ,
169
+ data : {
170
+ placementId : 'testPlacementId' ,
171
+ device : 'desktop' ,
172
+ currency : 'USD' ,
173
+ sizes : [ '300x250' ] ,
174
+ bidId : 'bidId12345' ,
175
+ referer : 'www.example.com'
176
+ }
177
+ } ] ;
178
+
126
179
let serverResponse = {
127
- body : { }
180
+ body : {
181
+ requestId : 'bidId12345' ,
182
+ cpm : 3.9 ,
183
+ currency : 'USD' ,
184
+ netRevenue : true ,
185
+ width : 300 ,
186
+ height : 250 ,
187
+ creativeId : 'creativeId12345' ,
188
+ ttl : 90 ,
189
+ ad : '<html><h3>I am an ad</h3></html> '
190
+ }
128
191
} ;
129
192
193
+ let expectedResponse = [ {
194
+ requestId : 'bidId12345' ,
195
+ cpm : 3.9 ,
196
+ currency : 'USD' ,
197
+ netRevenue : true ,
198
+ width : 300 ,
199
+ height : 250 ,
200
+ creativeId : 'creativeId12345' ,
201
+ ttl : 90 ,
202
+ ad : '<html><h3>I am an ad</h3></html>'
203
+ } ] ;
204
+
205
+ const getConfigStub = sinon . stub ( config , 'getConfig' ) . returns ( 'USD' ) ;
206
+
207
+ let result = spec . interpretResponse ( serverResponse , bidRequest [ 0 ] ) ;
208
+ expect ( Object . keys ( result ) ) . to . deep . equal ( Object . keys ( expectedResponse ) ) ;
209
+
210
+ getConfigStub . restore ( ) ;
211
+ } ) ;
212
+
213
+ it ( 'should get empty bid response requested currency is not available' , function ( ) {
214
+ let bidRequest = [ {
215
+ method : 'POST' ,
216
+ url : ENDPOINT_URL ,
217
+ data : {
218
+ placementId : 'testPlacementId' ,
219
+ device : 'desktop' ,
220
+ currency : 'BTC' ,
221
+ sizes : [ '300x250' ] ,
222
+ bidId : 'bidId12345' ,
223
+ referer : 'www.example.com'
224
+ }
225
+ } ] ;
226
+
227
+ let serverResponse = { } ;
228
+
130
229
let expectedResponse = [ ] ;
131
230
231
+ const getConfigStub = sinon . stub ( config , 'getConfig' ) . returns ( 'BTC' ) ;
232
+
132
233
let result = spec . interpretResponse ( serverResponse , bidRequest [ 0 ] ) ;
133
234
expect ( Object . keys ( result ) ) . to . deep . equal ( Object . keys ( expectedResponse ) ) ;
235
+
236
+ getConfigStub . restore ( ) ;
134
237
} ) ;
135
238
136
239
it ( 'should get empty bid response if no server response' , function ( ) {
240
+ let bidRequest = [ {
241
+ method : 'POST' ,
242
+ url : ENDPOINT_URL ,
243
+ data : {
244
+ placementId : 'testPlacementId' ,
245
+ device : 'desktop' ,
246
+ currency : 'EUR' ,
247
+ sizes : [ '300x250' ] ,
248
+ bidId : 'bidId12345' ,
249
+ referer : 'www.example.com'
250
+ }
251
+ } ] ;
252
+
137
253
let serverResponse = { } ;
138
254
139
255
let expectedResponse = [ ] ;
0 commit comments