forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathampliffyBidAdapter_spec.js
More file actions
453 lines (439 loc) · 15.9 KB
/
ampliffyBidAdapter_spec.js
File metadata and controls
453 lines (439 loc) · 15.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
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
import {
parseXML,
isAllowedToBidUp,
spec,
getDefaultParams,
mergeParams,
paramsToQueryString, setCurrentURL
} from 'modules/ampliffyBidAdapter.js';
import { expect } from 'chai';
import { BANNER, VIDEO } from 'src/mediaTypes';
import { newBidder } from 'src/adapters/bidderFactory';
describe('Ampliffy bid adapter Test', function () {
const adapter = newBidder(spec);
describe('inherited functions', function () {
it('exists and is a function', function () {
expect(adapter.callBids).to.exist.and.to.be.a('function');
});
});
// Global definitions for all tests
const xmlStr = `<?xml version="1.0" encoding="UTF-8"?>
<Ads type="video">
<Companion id="138316138683">
<HTMLResource><![CDATA[
<ad cpmMap=\'{"ES":".23","MX":".13"}\'
cpmCurrency=\'USD\'
creativeMap=\'{"https://bidder.ampliffy.com/gampad/ads?adName=6463aa7b7f147.xml":["ES","MX"]}\'
domainMap=\'["testSports.com","sports.com"]\'
excludedURLs=\'["www.no-allowed.com/busqueda/sexo/sexo"]\' />
]]>
</HTMLResource>
</Companion>
<VASTAdTagURI><![CDATA[http://localhost:8080?adurl=https://es.ampliffy.com/%3FgeoData%26ct%3DES%26st%3D%26city%3D0%26dma%3D0%26zp%3D08192%26bw%3D4]]></VASTAdTagURI>
<Extensions><Extension type="geo"><Country>ES</Country></Extension></Extensions>
</Ads>`;
const xml = new window.DOMParser().parseFromString(xmlStr, 'text/xml');
const companion = xml.getElementsByTagName('Companion')[0];
const htmlResource = companion.getElementsByTagName('HTMLResource')[0];
const htmlContent = document.createElement('html');
htmlContent.innerHTML = htmlResource.textContent;
describe('Is allowed to bid up', function () {
it('Should return true using a URL that is in domainMap', () => {
const allowedToBidUp = isAllowedToBidUp(htmlContent, 'https://testSports.com?id=131313&text=aaaaa&foo=foo');
expect(allowedToBidUp).to.be.true;
})
it('Should return false using an url that is not in domainMap', () => {
const allowedToBidUp = isAllowedToBidUp(htmlContent, 'https://test.com');
expect(allowedToBidUp).to.be.false;
})
it('Should return false using an url that is excluded.', () => {
const allowedToBidUp = isAllowedToBidUp(htmlContent, 'https://www.no-allowed.com/busqueda/sexo/sexo?test=1#item1');
expect(allowedToBidUp).to.be.false;
})
})
describe('Helper functions', function () {
it('Should default params not to be null', () => {
const defaultParams = getDefaultParams();
expect(defaultParams).not.to.be.null;
})
it('Should the merge two object params into a new object', () => {
const params1 = {
'hello': 'world',
'ampTest': 'this will be replaced'
}
const params2 = {
'test': 1,
'ampTest': 'This will be replace the param with the same name in other array'
}
const allParams = mergeParams(params1, params2);
const paramsComplete =
{
'hello': 'world',
'ampTest': 'This will be replace the param with the same name in other array',
'test': 1,
}
expect(allParams).not.to.be.null;
expect(JSON.stringify(allParams)).to.equal(JSON.stringify(paramsComplete));
})
it('Params to QueryString', () => {
const params = {
'test': 1,
'ampTest': 'ret',
'empty': null,
'quoteMark': '?',
'test1': undefined
}
const queryString = paramsToQueryString(params);
expect(queryString).not.to.be.null;
expect(queryString).to.equal('test=1&Test=ret&empty"eMark=%3F');
})
})
describe('isBidRequestValid', function () {
it('Should return true when required params found', function () {
const bidRequest = {
bidder: 'ampliffy',
params: {
server: 'bidder.ampliffy.com',
placementId: 1235465798,
format: 'all'
},
mediaTypes: {
banner: {
sizes: [1, 1]
}
},
}
expect(spec.isBidRequestValid(bidRequest)).to.be.true;
})
it('Should return false when param format is display but mediaTypes are for video', function () {
const bidRequest = {
bidder: 'ampliffy',
params: {
server: 'bidder.ampliffy.com',
placementId: 1235465798,
format: 'display'
},
mediaTypes: {
video: {
sizes: [1, 1]
}
},
}
expect(spec.isBidRequestValid(bidRequest)).to.be.false;
})
it('Should return false when param format is video but mediaTypes are for banner', function () {
const bidRequest = {
bidder: 'ampliffy',
params: {
server: 'bidder.ampliffy.com',
placementId: 1235465798,
format: 'video'
},
mediaTypes: {
banner: {
sizes: [1, 1]
}
},
}
expect(spec.isBidRequestValid(bidRequest)).to.be.false;
})
it('Should return true when param format is video and mediaTypes are for video', function () {
const bidRequest = {
bidder: 'ampliffy',
params: {
server: 'bidder.ampliffy.com',
placementId: 1235465798,
format: 'video'
},
mediaTypes: {
video: {
sizes: [1, 1]
}
},
}
expect(spec.isBidRequestValid(bidRequest)).to.be.true;
})
it('Should return true when param format is display and mediaTypes are for banner', function () {
const bidRequest = {
bidder: 'ampliffy',
params: {
server: 'bidder.ampliffy.com',
placementId: 1235465798,
format: 'display'
},
mediaTypes: {
banner: {
sizes: [1, 1]
}
},
}
expect(spec.isBidRequestValid(bidRequest)).to.be.true;
})
it('Should return true when param format is all and mediaTypes are for banner', function () {
const bidRequest = {
bidder: 'ampliffy',
params: {
server: 'bidder.ampliffy.com',
placementId: 1235465798,
format: 'all'
},
mediaTypes: {
banner: {
sizes: [1, 1]
}
},
}
expect(spec.isBidRequestValid(bidRequest)).to.be.true;
})
it('Should return true when param format is all and mediaTypes are for video', function () {
const bidRequest = {
bidder: 'ampliffy',
params: {
server: 'bidder.ampliffy.com',
placementId: 1235465798,
format: 'all'
},
mediaTypes: {
video: {
sizes: [1, 1]
}
},
}
expect(spec.isBidRequestValid(bidRequest)).to.be.true;
})
it('Should return false without placementId param', function () {
const bidRequest = {
bidder: 'ampliffy',
params: {}
}
expect(spec.isBidRequestValid(bidRequest)).to.be.false;
})
it('Should return false without param object', function () {
const bidRequest = {
bidder: 'ampliffy',
}
expect(spec.isBidRequestValid(bidRequest)).to.be.false;
})
});
describe('Build request function', function () {
const bidderRequest = {
'bidderCode': 'ampliffy',
'auctionId': 'c4a771bf-1791-4513-82b3-96c48d19ddff',
'bidderRequestId': '1134bdcbe47f25',
'bids': [{
'bidder': 'ampliffy',
'params': {
'placementId': 1235465798,
'type': 'bidder.',
'region': 'alan-development.k8s.',
'adnetwork': 'ampliffy.com',
'SERVER': 'bidder.ampliffy.com'
},
'crumbs': { 'pubcid': '29844d69-c4e5-4b00-8602-6dd09815363a' },
'ortb2Imp': { 'ext': { 'data': { 'pbadslot': 'video1' } } },
'mediaTypes': {
'video': {
'context': 'instream',
'playerSize': [[640, 480]],
'mimes': ['video/mp4'],
'protocols': [1, 2, 3, 4, 5, 6, 7, 8],
'playbackmethod': [2],
'skip': 1
}
},
'adUnitCode': 'video1',
'transactionId': 'f85c1b10-bad3-4c3f-a2bb-2c484c405bc9',
'sizes': [[640, 480]],
'bidId': '2bc71d9c058842',
'bidderRequestId': '1134bdcbe47f25',
'auctionId': 'c4a771bf-1791-4513-82b3-96c48d19ddff',
'src': 'client',
'bidRequestsCount': 1,
'bidderRequestsCount': 1,
'bidderWinsCount': 0
}],
'auctionStart': 1644029483655,
'timeout': 3000,
'refererInfo': {
'referer': 'http://localhost:9999/integrationExamples/gpt/hello_world_video.html?pbjs_debug=true',
'reachedTop': true,
'isAmp': false,
'numIframes': 0,
'stack': ['http://localhost:9999/integrationExamples/gpt/hello_world_video.html?pbjs_debug=true'],
'canonicalUrl': null
},
'start': 1644029483708
}
const validBidRequests = [
{
'bidder': 'ampliffy',
'params': {
'placementId': 1235465798,
'type': 'bidder.',
'region': 'alan-development.k8s.',
'adnetwork': 'ampliffy.com',
'SERVER': 'bidder.ampliffy.com'
},
'crumbs': { 'pubcid': '29844d69-c4e5-4b00-8602-6dd09815363a' },
'ortb2Imp': { 'ext': { 'data': { 'pbadslot': 'video1' } } },
'mediaTypes': {
'video': {
'context': 'instream',
'playerSize': [[640, 480]],
'mimes': ['video/mp4'],
'protocols': [1, 2, 3, 4, 5, 6, 7, 8],
'playbackmethod': [2],
'skip': 1
}
},
'adUnitCode': 'video1',
'transactionId': 'f85c1b10-bad3-4c3f-a2bb-2c484c405bc9',
'sizes': [[640, 480]],
'bidId': '2bc71d9c058842',
'bidderRequestId': '1134bdcbe47f25',
'auctionId': 'c4a771bf-1791-4513-82b3-96c48d19ddff',
'src': 'client',
'bidRequestsCount': 1,
'bidderRequestsCount': 1,
'bidderWinsCount': 0
}
];
it('Should return one or more bid requests', function () {
expect(spec.buildRequests(validBidRequests, bidderRequest).length).to.be.greaterThan(0);
});
})
describe('Interpret response', function () {
const bidRequest = {
bidRequest: {
adUnitCode: 'div-gpt-ad-1460505748561-0',
auctionId: '469bb2e2-351f-4d01-b782-cdbca5e3e0ed',
bidId: '2d40b8dcd02ade',
bidRequestsCount: 1,
bidder: 'ampliffy',
bidderRequestId: '128c07edc4680f',
bidderRequestsCount: 1,
bidderWinsCount: 0,
crumbs: {
pubcid: '29844d69-c4e5-4b00-8602-6dd09815363a'
},
mediaTypes: {
banner: {
sizes: [
[300, 250],
[300, 600]
]
}
},
ortb2Imp: { ext: {} },
params: { placementId: 13144370 },
sizes: [
[300, 250],
[300, 600]
],
src: 'client',
transactionId: '103b2b58-6ed1-45e9-9486-c942d6042e3'
},
data: { bidId: '2d40b8dcd02ade' },
method: 'GET',
url: 'https://test.com',
};
it('Should extract a CPM and currency from the xml', () => {
const cpmData = parseXML(xml);
expect(cpmData).to.not.be.a('null');
expect(cpmData.cpm).to.equal('.23');
expect(cpmData.currency).to.equal('USD');
});
it('It should return no ads when the CPM is less than zero.', () => {
const xmlStr1 = `<?xml version="1.0" encoding="UTF-8"?>
<VAST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vast.xsd" version="3.0">
<Ad id="1">
<Wrapper>
<Companion id="138316138683" width="1" height="1">
<HTMLResource>
<![CDATA[<!doctype html>
<html><head></head>
<body>
<div class="GoogleActiveViewInnerContainer"></div>
<div>
<div data-vidco-metrics="0"
data-taxonomy-ampliffy="AMPP---000017"
data-taxonomy-creator=""
cpmMap=\'{"ES":"-1","MX":"0.0"}\'
cpmCurrency=\'{"ES":"USD","MX":"MXN"}\'></div>
</div>
</body>
</html>
]]>
</HTMLResource>
</Companion>
<VASTAdTagURI><![CDATA[http://localhost:8080?adurl=https://es.ampliffy.com/%3FgeoData%26ct%3DES%26st%3D%26city%3D0%26dma%3D0%26zp%3D08192%26bw%3D4]]></VASTAdTagURI>
<Extensions><Extension type="geo"><Country>ES</Country></Extension></Extensions>
</Wrapper>
</Ad>
</VAST>`;
const serverResponse = {
'body': xmlStr1,
}
const bidResponses = spec.interpretResponse(serverResponse, bidRequest);
expect(bidResponses.length).to.equal(0);
})
it('It should return no ads when the creative url is not in the xml', () => {
const xmlStr1 = `<?xml version="1.0" encoding="UTF-8"?>
<VAST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vast.xsd" version="3.0">
<Ad id="1">
<Wrapper>
<Companion id="138316138683" width="1" height="1">
<HTMLResource>
<![CDATA[<!doctype html><html>
<head></head>
<body>
<div class="GoogleActiveViewInnerContainer"></div>
<div style="display:inline">
<div data-title="Bidder test"
cpmMap=\'{"ES":".10","MX":"0"}\'
cpmCurrency=\'{"ES":"USD","MX":"MXN"}\'>
</div>
</body>
</html>]]>
</HTMLResource>
</Companion>
<Extensions><Extension type="geo"><Country>ES</Country></Extension></Extensions>
</Wrapper>
</Ad>
</VAST>`;
const serverResponse = {
'body': xmlStr1,
}
const bidResponses = spec.interpretResponse(serverResponse, bidRequest);
expect(bidResponses.length).to.equal(0);
})
it('It should return a banner ad.', () => {
const serverResponse = {
'body': xmlStr,
}
setCurrentURL('https://www.sports.com');
const bidResponses = spec.interpretResponse(serverResponse, bidRequest);
expect(bidResponses.length).greaterThan(0);
expect(bidResponses[0].mediaType).to.be.equal(BANNER);
expect(bidResponses[0].ad).not.to.be.null;
})
it('It should return a video ad.', () => {
const serverResponse = {
'body': xmlStr,
}
setCurrentURL('https://www.sports.com');
bidRequest.bidRequest.mediaTypes = {
video: {
sizes: [
[300, 250],
[300, 600]
]
}
}
const bidResponses = spec.interpretResponse(serverResponse, bidRequest);
expect(bidResponses.length).greaterThan(0);
expect(bidResponses[0].mediaType).to.be.equal(VIDEO);
expect(bidResponses[0].vastUrl).not.to.be.null;
})
});
});