forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadbutlerBidAdapter_spec.js
More file actions
329 lines (278 loc) · 9.46 KB
/
adbutlerBidAdapter_spec.js
File metadata and controls
329 lines (278 loc) · 9.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
import { expect } from 'chai';
import { spec } from 'modules/adbutlerBidAdapter.js';
describe('AdButler adapter', function () {
let validBidRequests;
beforeEach(function () {
validBidRequests = [
{
bidder: 'adbutler',
params: {
accountID: '181556',
zoneID: '705374',
keyword: 'red',
minCPM: '1.00',
maxCPM: '5.00',
},
placementCode: '/19968336/header-bid-tag-1',
mediaTypes: {
banner: {
sizes: [[300, 250], [300, 600]],
},
},
bidId: '23acc48ad47af5',
auctionId: '0fb4905b-9456-4152-86be-c6f6d259ba99',
bidderRequestId: '1c56ad30b9b8ca8',
transactionId: '92489f71-1bf2-49a0-adf9-000cea934729',
},
];
});
describe('for requests', function () {
describe('without account ID', function () {
it('rejects the bid', function () {
const invalidBid = {
bidder: 'adbutler',
params: {
zoneID: '210093',
},
};
const isValid = spec.isBidRequestValid(invalidBid);
expect(isValid).to.equal(false);
});
});
describe('without a zone ID', function () {
it('rejects the bid', function () {
const invalidBid = {
bidder: 'adbutler',
params: {
accountID: '167283',
},
};
const isValid = spec.isBidRequestValid(invalidBid);
expect(isValid).to.equal(false);
});
});
describe('with a valid bid', function () {
describe('with a custom domain', function () {
it('uses the custom domain', function () {
validBidRequests[0].params.domain = 'customadbutlerdomain.com';
const requests = spec.buildRequests(validBidRequests);
const requestURL = requests[0].url;
expect(requestURL).to.have.string('customadbutlerdomain.com');
});
});
it('accepts the bid', function () {
const validBid = {
bidder: 'adbutler',
params: {
accountID: '167283',
zoneID: '210093',
},
};
const isValid = spec.isBidRequestValid(validBid);
expect(isValid).to.equal(true);
});
it('sets default domain', function () {
const requests = spec.buildRequests(validBidRequests);
const request = requests[0];
const [domain] = request.url.split('/adserve/');
expect(domain).to.equal('https://servedbyadbutler.com');
});
it('sets the keyword parameter', function () {
const requests = spec.buildRequests(validBidRequests);
const requestURL = requests[0].url;
expect(requestURL).to.have.string(';kw=red;');
});
describe('with extra params', function () {
beforeEach(function() {
validBidRequests[0].params.extra = {
foo: 'bar',
};
});
it('sets the extra parameter', function () {
const requests = spec.buildRequests(validBidRequests);
const requestURL = requests[0].url;
expect(requestURL).to.have.string(';foo=bar;');
});
});
describe('with multiple bids to the same zone', function () {
it('increments the place count', function () {
const requests = spec.buildRequests([validBidRequests[0], validBidRequests[0]]);
const firstRequest = requests[0].url;
const secondRequest = requests[1].url;
expect(firstRequest).to.have.string(';place=0;');
expect(secondRequest).to.have.string(';place=1;');
});
});
});
});
describe('for server responses', function () {
let serverResponse;
describe('with no body', function () {
beforeEach(function() {
serverResponse = {
body: null,
};
});
it('does not return any bids', function () {
const bids = spec.interpretResponse(serverResponse, { bidRequest: validBidRequests[0] });
expect(bids).to.be.length(0);
});
});
describe('with an incorrect size', function () {
beforeEach(function() {
serverResponse = {
body: {
status: 'SUCCESS',
account_id: 167283,
zone_id: 210083,
cpm: 1.5,
width: 728,
height: 90,
place: 0,
},
};
});
it('does not return any bids', function () {
const bids = spec.interpretResponse(serverResponse, { bidRequest: validBidRequests[0] });
expect(bids).to.be.length(0);
});
});
describe('with a failed status', function () {
beforeEach(function() {
serverResponse = {
body: {
status: 'NO_ELIGIBLE_ADS',
zone_id: 210083,
width: 300,
height: 250,
place: 0,
},
};
});
it('does not return any bids', function () {
const bids = spec.interpretResponse(serverResponse, { bidRequest: validBidRequests[0] });
expect(bids).to.be.length(0);
});
});
describe('with low CPM', function () {
beforeEach(function() {
serverResponse = {
body: {
status: 'SUCCESS',
account_id: 167283,
zone_id: 210093,
cpm: 0.75,
width: 300,
height: 250,
place: 0,
ad_code: '<img src="http://image.source.com/img" alt="" title="" border="0" width="300" height="250">',
tracking_pixels: [],
},
}
});
describe('with a minimum CPM', function () {
it('does not return any bids', function () {
const bids = spec.interpretResponse(serverResponse, { bidRequest: validBidRequests[0] });
expect(bids).to.be.length(0);
});
});
describe('with no minimum CPM', function () {
beforeEach(function() {
delete validBidRequests[0].params.minCPM;
});
it('returns a bid', function() {
const bids = spec.interpretResponse(serverResponse, { bidRequest: validBidRequests[0] });
expect(bids).to.be.length(1);
});
});
});
describe('with high CPM', function () {
beforeEach(function() {
serverResponse = {
body: {
status: 'SUCCESS',
account_id: 167283,
zone_id: 210093,
cpm: 999,
width: 300,
height: 250,
place: 0,
ad_code: '<img src="http://image.source.com/img" alt="" title="" border="0" width="300" height="250">',
tracking_pixels: [],
},
}
});
describe('with a maximum CPM', function () {
it('does not return any bids', function () {
const bids = spec.interpretResponse(serverResponse, { bidRequest: validBidRequests[0] });
expect(bids).to.be.length(0);
});
});
describe('with no maximum CPM', function () {
beforeEach(function() {
delete validBidRequests[0].params.maxCPM;
});
it('returns a bid', function() {
const bids = spec.interpretResponse(serverResponse, { bidRequest: validBidRequests[0] });
expect(bids).to.be.length(1);
});
});
});
describe('with a valid ad', function () {
beforeEach(function() {
serverResponse = {
body: {
status: 'SUCCESS',
account_id: 167283,
zone_id: 210093,
cpm: 1.5,
width: 300,
height: 250,
place: 0,
ad_code: '<img src="http://image.source.com/img" alt="" title="" border="0" width="300" height="250">',
tracking_pixels: [
'http://tracking.pixel.com/params=info',
],
},
};
});
it('returns a complete bid', function () {
const bids = spec.interpretResponse(serverResponse, { bidRequest: validBidRequests[0] });
expect(bids).to.be.length(1);
expect(bids[0].cpm).to.equal(1.5);
expect(bids[0].width).to.equal(300);
expect(bids[0].height).to.equal(250);
expect(bids[0].currency).to.equal('USD');
expect(bids[0].netRevenue).to.equal(true);
expect(bids[0].ad).to.have.length.above(1);
expect(bids[0].ad).to.have.string('http://tracking.pixel.com/params=info');
});
describe('for a bid request without banner media type', function () {
beforeEach(function() {
delete validBidRequests[0].mediaTypes.banner;
});
it('does not return any bids', function () {
const bids = spec.interpretResponse(serverResponse, { bidRequest: validBidRequests[0] });
expect(bids).to.be.length(0);
});
});
describe('with advertiser meta', function () {
beforeEach(function() {
serverResponse.body.advertiser = {
id: 123,
name: 'Advertiser Name',
domain: 'advertiser.com',
};
});
it('returns a bid including advertiser meta', function () {
const bids = spec.interpretResponse(serverResponse, { bidRequest: validBidRequests[0] });
expect(bids).to.be.length(1);
expect(bids[0]).to.have.property('meta');
expect(bids[0].meta.advertiserId).to.equal(123);
expect(bids[0].meta.advertiserName).to.equal('Advertiser Name');
expect(bids[0].meta.advertiserDomains).to.contain('advertiser.com');
});
});
});
});
});