forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaniviewBidAdapter_spec.js
More file actions
426 lines (344 loc) · 13.9 KB
/
aniviewBidAdapter_spec.js
File metadata and controls
426 lines (344 loc) · 13.9 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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
import { spec } from 'modules/aniviewBidAdapter.js';
import { newBidder } from 'src/adapters/bidderFactory.js';
const { expect } = require('chai');
const PUBLISHER_ID_1 = 'publisher_id_1';
const CHANNEL_ID_1 = 'channel_id_1';
const PUBLISHER_ID_2 = 'publisher_id_2';
const CHANNEL_ID_2 = 'channel_id_2';
const BID_ID_1 = 'bid_id_1';
const BID_ID_2 = 'bid_id_2';
const BIDDER_REQUEST_ID = 'bidder_request_id';
const CUSTOM_DOMAIN = 'example.com';
const BASE_URL = 'https://' + CUSTOM_DOMAIN + '/track' +
'?rtbbp=10' +
'&cpm=${AUCTION_PRICE}' +
'&aucid=${AUCTION_ID}' +
'&aucbid=${AUCTION_BID_ID}' +
'&limid=${AUCTION_IMP_ID}' +
'&aucseid=${AUCTION_SEAT_ID}' +
'&aucadid=${AUCTION_AD_ID}';
const LURL = `${BASE_URL}&e=AV_M40&rcd=\${AUCTION_LOSS}`;
const NURL = `${BASE_URL}&e=AV_M4`;
const VIDEO_VAST = `<VAST version="3.0"><Tracking><![CDATA[${NURL}]]></Tracking></VAST>`
const BANNER_VAST = VIDEO_VAST;
const BANNER_HTML = '<h1>HTML BANNER</h1>';
const CURRENCY = 'USD';
const PRICE = 10;
const FLOOR_PRICE = PRICE * 0.5;
const TTL = 600;
const VIDEO_SIZE = { width: 640, height: 360 };
const BANNER_SIZE = { width: 250, height: 250 };
const CUSTOM_RENDERER_URL = `https://${CUSTOM_DOMAIN}/script/6.1/prebidRenderer.js`;
const DEFAULT_RENDERER_URL = `https://player.aniview.com/script/6.1/prebidRenderer.js`;
const REPLACEMENT_1 = '12345';
const MOCK = {
bidRequest: () => ({
bidderCode: 'aniview',
auctionId: null,
bidderRequestId: BIDDER_REQUEST_ID,
bids: [
{
bidder: 'aniview',
params: {
AV_PUBLISHERID: PUBLISHER_ID_1,
AV_CHANNELID: CHANNEL_ID_1,
playerDomain: CUSTOM_DOMAIN,
},
mediaTypes: {
video: {
playerSize: [[VIDEO_SIZE.width, VIDEO_SIZE.height]],
context: 'outstream',
mimes: ['video/mpeg', 'video/mp4', 'application/javascript'],
}
},
bidId: BID_ID_1,
bidderRequestId: BIDDER_REQUEST_ID,
sizes: [[VIDEO_SIZE.width, VIDEO_SIZE.height]],
},
{
bidder: 'aniview',
params: {
AV_PUBLISHERID: PUBLISHER_ID_2,
AV_CHANNELID: CHANNEL_ID_2,
playerDomain: CUSTOM_DOMAIN,
replacements: {
AV_CDIM1: REPLACEMENT_1,
},
},
mediaTypes: {
video: {
playerSize: [[VIDEO_SIZE.width, VIDEO_SIZE.height]],
context: 'outstream',
mimes: ['video/mpeg', 'video/mp4', 'application/javascript'],
}
},
bidId: BID_ID_2,
bidderRequestId: BIDDER_REQUEST_ID,
sizes: [[VIDEO_SIZE.width, VIDEO_SIZE.height]],
floorData: {
currency: CURRENCY,
floor: FLOOR_PRICE,
},
getFloor: _ => ({
currency: CURRENCY,
floor: FLOOR_PRICE,
}),
},
],
auctionStart: 1722343584268,
timeout: 1_000,
start: 1722343584269,
ortb2: {
source: {},
site: {
page: 'http://localhost:8080/',
ref: 'http://localhost:8080/',
domain: 'http://localhost:8080',
publisher: {
domain: 'http://localhost:8080',
}
},
device: {
w: 1800,
h: 1169,
language: 'en',
},
},
}),
bidderResponse: () => ({
body: {
id: 'bidder_response_id',
bidid: 'bidder_response_bid_id',
cur: CURRENCY,
ext: {
aniview: {
sync: [
{ url: 'https://iframe-1.example.com/sync', e: 'sync', pr: '14', t: 3 },
{ url: 'https://iframe-2.example.com/sync', e: 'sync', pr: '28', t: 3 },
{ url: 'https://image.example.com/sync', e: 'sync', pr: 'abc12', t: 1 }
]
}
},
seatbid: [
{
seat: '',
bid: [
{
adm: VIDEO_VAST,
adomain: [''],
id: 'seatbid_bid_id_1',
impid: BID_ID_1,
lurl: LURL,
nurl: NURL,
price: PRICE,
}
]
}
]
},
})
}
describe('Aniview Bid Adapter', function () {
const adapter = newBidder(spec);
describe('Inherited function', function () {
it('exists and is a function', function () {
expect(adapter.callBids).to.exist.and.to.be.a('function');
});
});
describe('isBidRequestValid', function () {
let videoBidRequest;
beforeEach(() => {
videoBidRequest = MOCK.bidRequest();
});
it('should return `true` when required params found', function () {
expect(spec.isBidRequestValid(videoBidRequest.bids[0])).to.be.true;
});
it('should return `false` when required params are wrong', function () {
videoBidRequest.bids[0].params = { something: 'is wrong' };
expect(spec.isBidRequestValid(videoBidRequest.bids[0])).to.be.false;
});
});
describe('buildRequests', function () {
let videoBidRequest;
beforeEach(() => {
videoBidRequest = MOCK.bidRequest();
});
it('should return expected request object', function () {
const bidRequest = spec.buildRequests(videoBidRequest.bids, videoBidRequest);
expect(bidRequest).to.exist.and.to.be.a('array').and.to.have.lengthOf(2);
const { url, method, data } = bidRequest[0];
const { ext, imp } = data;
expect(url).equal('https://rtb.aniview.com/sspRTB2');
expect(method).equal('POST');
expect(imp[0].tagid).equal(CHANNEL_ID_1);
expect(imp[0].id).equal(videoBidRequest.bids[0].bidId);
expect(ext.aniview.pbjs).equal(1);
});
it('should have floor data inside imp', function () {
const bidRequest = spec.buildRequests(videoBidRequest.bids, videoBidRequest);
const imp = bidRequest[1].data.imp[0];
expect(imp.bidfloor).equal(FLOOR_PRICE);
expect(imp.bidfloorcur).equal(CURRENCY);
});
it('should have replacements in request', function () {
const bidRequest = spec.buildRequests(videoBidRequest.bids, videoBidRequest);
const { replacements } = bidRequest[1].data.ext.aniview;
expect(replacements.AV_CDIM1).equal(REPLACEMENT_1);
});
it('should not have floor data in imp if getFloor returns empty object', function () {
videoBidRequest.bids[1].getFloor = () => ({});
const bidRequest = spec.buildRequests(videoBidRequest.bids, videoBidRequest);
const imp = bidRequest[1].data.imp[0];
expect(imp.bidfloor).not.exist;
expect(imp.bidfloorcur).not.exist;
});
it('should have vastUrl if adm is not provided but nurl is', function () {
const bidRequests = spec.buildRequests(videoBidRequest.bids, videoBidRequest);
const bidderResponse = MOCK.bidderResponse();
delete bidderResponse.body.seatbid[0].bid[0].adm
const bids = spec.interpretResponse(bidderResponse, bidRequests[0]);
const bid = bids[0];
expect(bid.vastXml).to.not.exist;
expect(bid.vastUrl).to.exist.and.to.not.have.string('${AUCTION_PRICE}');
expect(bid.vastUrl).to.have.string('cpm=' + PRICE);
});
it('should use dev environment', function () {
const DEV_ENDPOINT = 'https://dev.aniview.com/sspRTB2';
videoBidRequest.bids[0].params.dev = { endpoint: DEV_ENDPOINT };
const bidRequest = spec.buildRequests(videoBidRequest.bids, videoBidRequest);
expect(bidRequest[0].url).to.equal(DEV_ENDPOINT);
});
});
describe('interpretResponse', function () {
describe('Video format', function () {
let bidRequests, bidderResponse;
beforeEach(function() {
const videoBidRequest = MOCK.bidRequest();
bidRequests = spec.buildRequests(videoBidRequest.bids, videoBidRequest);
bidderResponse = MOCK.bidderResponse();
});
it('should return empty bids array for empty response', function () {
const emptyResponse = bidderResponse.body = {};
const bids = spec.interpretResponse(emptyResponse, bidRequests[0]);
expect(bids).to.be.empty;
});
it('should return valid bids array', function () {
const bids = spec.interpretResponse(bidderResponse, bidRequests[0]);
const bid = bids[0];
expect(bids.length).to.greaterThan(0);
expect(bid.vastXml).to.exist.and.to.not.have.string('${AUCTION_PRICE}');
expect(bid.vastXml).to.have.string('cpm=' + PRICE);
expect(bid.vastUrl).to.not.exist;
expect(bid.requestId).to.equal(bidRequests[0].data.imp[0].id);
expect(bid.cpm).to.equal(PRICE);
expect(bid.ttl).to.equal(TTL);
expect(bid.currency).to.equal(CURRENCY);
expect(bid.netRevenue).to.equal(true);
expect(bid.mediaType).to.equal('video');
expect(bid.meta.advertiserDomains).to.be.an('array');
expect(bid.creativeId).to.exist;
expect(bid.width).to.exist;
expect(bid.height).to.exist;
});
it('should return bid without required properties if cpm less or equal 0', function () {
bidderResponse.body.seatbid[0].bid[0].price = 0;
const bids = spec.interpretResponse(bidderResponse, bidRequests[0]);
const bid = bids[0];
expect(bid.renderer).to.not.exist;
expect(bid.ad).to.not.exist;
});
it('should return empty bids array if no bids in response', function () {
bidderResponse.body.seatbid[0].bid = [];
const bids = spec.interpretResponse(bidderResponse, bidRequests[0]);
expect(bids).to.exist.and.to.be.a('array').and.to.have.lengthOf(0);
});
it('should add renderer if outstream context', function () {
const bid = spec.interpretResponse(bidderResponse, bidRequests[0])[0];
expect(bid.renderer.url).to.equal(CUSTOM_RENDERER_URL);
expect(bid.renderer.config.AV_PUBLISHERID).to.equal(PUBLISHER_ID_1);
expect(bid.renderer.config.AV_CHANNELID).to.equal(CHANNEL_ID_1);
expect(bid.renderer.loaded).to.equal(false);
expect(bid.width).to.equal(VIDEO_SIZE.width);
expect(bid.height).to.equal(VIDEO_SIZE.height);
});
it('should use default renderer domain', function () {
delete bidRequests[0].bids[0].params.playerDomain;
const bid = spec.interpretResponse(bidderResponse, bidRequests[0])[0];
expect(bid.renderer.url).to.equal(DEFAULT_RENDERER_URL);
});
it('should not add renderer if context is not outstream', function () {
bidRequests[0].bids[0].mediaTypes.video.context = 'instream';
const bid = spec.interpretResponse(bidderResponse, bidRequests[0])[0];
expect(bidRequests[0].bids[0].mediaTypes.video.context).to.be.not.equal('outstream');
expect(bid.renderer).to.not.exist;
});
});
describe('Banner format', function () {
let bidRequests, bidderResponse;
beforeEach(function() {
const bannerBidRequest = MOCK.bidRequest();
// Converting video bid request to banner bid request
delete bannerBidRequest.bids[0].mediaTypes.video;
bannerBidRequest.bids[0].sizes = [[BANNER_SIZE.width, BANNER_SIZE.height]];
bannerBidRequest.bids[0].mediaTypes.banner = {
sizes: [
[BANNER_SIZE.width, BANNER_SIZE.height],
[BANNER_SIZE.width * 2, BANNER_SIZE.height],
],
};
bidRequests = spec.buildRequests(bannerBidRequest.bids, bannerBidRequest);
bidderResponse = MOCK.bidderResponse();
});
it('should return valid banner bids (HTML)', function () {
bidderResponse.body.seatbid[0].bid[0].adm = BANNER_HTML;
const bid = spec.interpretResponse(bidderResponse, bidRequests[0])[0];
expect(bid.ad).to.exist;
expect(bid.cpm).to.equal(PRICE);
expect(bid.width).to.equal(BANNER_SIZE.width);
expect(bid.height).to.equal(BANNER_SIZE.height);
expect(bid.renderer).to.not.exist;
});
it('should return valid banner bids (VAST) with renderer', function () {
bidderResponse.body.seatbid[0].bid[0].adm = BANNER_VAST;
const bid = spec.interpretResponse(bidderResponse, bidRequests[0])[0];
expect(bid.ad).to.exist;
expect(bid.ad).to.not.have.string('${AUCTION_PRICE}');
expect(bid.ad).to.have.string('cpm=' + PRICE);
expect(bid.cpm).to.equal(PRICE);
expect(bid.width).to.equal(BANNER_SIZE.width);
expect(bid.height).to.equal(BANNER_SIZE.height);
expect(bid.renderer.url).to.equal(CUSTOM_RENDERER_URL);
expect(bid.renderer.config.AV_PUBLISHERID).to.equal(PUBLISHER_ID_1);
expect(bid.renderer.config.AV_CHANNELID).to.equal(CHANNEL_ID_1);
expect(bid.renderer.loaded).to.equal(false);
});
});
});
describe('getUserSyncs', function () {
let bidRequest, bidderResponse;
beforeEach(function() {
const videoBidRequest = MOCK.bidRequest();
bidRequest = spec.buildRequests(videoBidRequest.bids, videoBidRequest);
bidderResponse = MOCK.bidderResponse();
});
it('should get syncs from response', function () {
const syncs = spec.getUserSyncs({ iframeEnabled: true, pixelEnabled: true }, [bidderResponse]);
expect(syncs).to.be.a('array').and.to.have.lengthOf(3);
});
it('should get only pixel syncs from response', function () {
const syncs = spec.getUserSyncs({ iframeEnabled: false, pixelEnabled: true }, [bidderResponse]);
expect(syncs).to.be.a('array').and.to.have.lengthOf(1);
expect(syncs[0].type).to.equal('image');
});
it('should return empty array of syncs if no syncs in response', function () {
delete bidderResponse.body.ext.aniview.sync
const syncs = spec.getUserSyncs({ iframeEnabled: true, pixelEnabled: false }, [bidderResponse]);
expect(syncs).to.be.a('array').and.to.have.lengthOf(0);
});
it('should return empty array of syncs if no body in response', function () {
delete bidderResponse.body
const syncs = spec.getUserSyncs({ iframeEnabled: true, pixelEnabled: true }, [bidderResponse]);
expect(syncs).to.be.a('array').and.to.have.lengthOf(0);
});
});
});