forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadstirBidAdapter_spec.js
More file actions
413 lines (393 loc) · 12.8 KB
/
adstirBidAdapter_spec.js
File metadata and controls
413 lines (393 loc) · 12.8 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
import { expect } from 'chai';
import { spec } from '../../../modules/adstirBidAdapter.js';
import * as utils from 'src/utils.js';
import { config } from 'src/config.js';
describe('AdstirAdapter', function () {
describe('isBidRequestValid', function () {
it('should return true if appId is non-empty string and adSpaceNo is integer', function () {
const bid = {
params: {
appId: 'MEDIA-XXXXXX',
adSpaceNo: 6,
}
}
expect(spec.isBidRequestValid(bid)).to.equal(true);
});
it('should return false if appId is non-empty string, but adSpaceNo is not integer', function () {
const bid = {
params: {
appId: 'MEDIA-XXXXXX',
adSpaceNo: 'a',
}
}
expect(spec.isBidRequestValid(bid)).to.equal(false);
});
it('should return false if appId is non-empty string, but adSpaceNo is null', function () {
const bid = {
params: {
appId: 'MEDIA-XXXXXX',
adSpaceNo: null,
}
}
expect(spec.isBidRequestValid(bid)).to.equal(false);
});
it('should return false if appId is non-empty string, but adSpaceNo is undefined', function () {
const bid = {
params: {
appId: 'MEDIA-XXXXXX'
}
}
expect(spec.isBidRequestValid(bid)).to.equal(false);
});
it('should return false if adSpaceNo is integer, but appId is empty string', function () {
const bid = {
params: {
appId: '',
adSpaceNo: 6,
}
}
expect(spec.isBidRequestValid(bid)).to.equal(false);
});
it('should return false if adSpaceNo is integer, but appId is not string', function () {
const bid = {
params: {
appId: 123,
adSpaceNo: 6,
}
}
expect(spec.isBidRequestValid(bid)).to.equal(false);
});
it('should return false if adSpaceNo is integer, but appId is null', function () {
const bid = {
params: {
appId: null,
adSpaceNo: 6,
}
}
expect(spec.isBidRequestValid(bid)).to.equal(false);
});
it('should return false if adSpaceNo is integer, but appId is undefined', function () {
const bid = {
params: {
adSpaceNo: 6,
}
}
expect(spec.isBidRequestValid(bid)).to.equal(false);
});
it('should return false if params is empty', function () {
const bid = {
params: {}
}
expect(spec.isBidRequestValid(bid)).to.equal(false);
});
});
describe('buildRequests', function () {
const validBidRequests = [
{
auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917',
bidder: 'adstir',
bidId: 'bidid1111',
params: {
appId: 'MEDIA-XXXXXX',
adSpaceNo: 1,
},
transactionId: 'transactionid-1111',
mediaTypes: {
banner: {
sizes: [
[300, 250],
[336, 280],
],
}
},
sizes: [
[300, 250],
[336, 280],
],
},
{
auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917',
bidder: 'adstir',
bidId: 'bidid2222',
params: {
appId: 'MEDIA-XXXXXX',
adSpaceNo: 2,
},
transactionId: 'transactionid-2222',
mediaTypes: {
banner: {
sizes: [
[320, 50],
[320, 100],
],
}
},
sizes: [
[320, 50],
[320, 100],
],
},
];
const bidderRequest = {
auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917',
refererInfo: {
page: 'https://ad-stir.com/contact',
topmostLocation: 'https://ad-stir.com/contact',
reachedTop: true,
ref: 'https://test.example/q=adstir',
isAmp: false,
numIframes: 0,
stack: [
'https://ad-stir.com/contact',
],
},
};
it('one entry in validBidRequests corresponds to one server request object.', function () {
const requests = spec.buildRequests(validBidRequests, bidderRequest);
expect(requests.length).to.equal(validBidRequests.length);
requests.forEach(function (r, i) {
expect(r.method).to.equal('POST');
expect(r.url).to.equal('https://ad.ad-stir.com/prebid');
const d = JSON.parse(r.data);
expect(d.auctionId).to.equal('b06c5141-fe8f-4cdf-9d7d-54415490a917');
const v = validBidRequests[i];
expect(d.appId).to.equal(v.params.appId);
expect(d.adSpaceNo).to.equal(v.params.adSpaceNo);
expect(d.bidId).to.equal(v.bidId);
expect(d.transactionId).to.equal(v.transactionId);
expect(d.mediaTypes).to.deep.equal(v.mediaTypes);
expect(d.sizes).to.deep.equal(v.sizes);
expect(d.ref.page).to.equal(bidderRequest.refererInfo.page);
expect(d.ref.tloc).to.equal(bidderRequest.refererInfo.topmostLocation);
expect(d.ref.referrer).to.equal(bidderRequest.refererInfo.ref);
expect(d.sua).to.equal(null);
expect(d.user).to.equal(null);
expect(d.gdpr).to.equal(false);
expect(d.usp).to.equal(false);
expect(d.schain).to.equal(null);
expect(d.eids).to.deep.equal([]);
});
});
it('ref.page, ref.tloc and ref.referrer correspond to refererInfo', function () {
const [request] = spec.buildRequests([validBidRequests[0]], {
auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917',
refererInfo: {
page: null,
topmostLocation: 'https://adserver.example/iframe1.html',
reachedTop: false,
ref: null,
isAmp: false,
numIframes: 2,
stack: [
null,
'https://adserver.example/iframe1.html',
'https://adserver.example/iframe2.html'
],
},
});
const { ref } = JSON.parse(request.data);
expect(ref.page).to.equal(null);
expect(ref.tloc).to.equal('https://adserver.example/iframe1.html');
expect(ref.referrer).to.equal(null);
});
it('when config.pageUrl is not set, ref.topurl equals to refererInfo.reachedTop', function () {
const bidderRequestClone = utils.deepClone(bidderRequest);
[true, false].forEach(function (reachedTop) {
bidderRequestClone.refererInfo.reachedTop = reachedTop;
const requests = spec.buildRequests(validBidRequests, bidderRequestClone);
const d = JSON.parse(requests[0].data);
expect(d.ref.topurl).to.equal(reachedTop);
});
});
describe('when config.pageUrl is set, ref.topurl is always false', function () {
before(function () {
config.setConfig({ pageUrl: 'https://ad-stir.com/register' });
});
after(function () {
config.resetConfig();
});
it('ref.topurl should be false', function () {
const bidderRequestClone = utils.deepClone(bidderRequest);
[true, false].forEach(function (reachedTop) {
bidderRequestClone.refererInfo.reachedTop = reachedTop;
const requests = spec.buildRequests(validBidRequests, bidderRequestClone);
const d = JSON.parse(requests[0].data);
expect(d.ref.topurl).to.equal(false);
});
});
});
it('gdprConsent.gdprApplies is sent', function () {
const bidderRequestClone = utils.deepClone(bidderRequest);
[true, false].forEach(function (gdprApplies) {
bidderRequestClone.gdprConsent = { gdprApplies };
const requests = spec.buildRequests(validBidRequests, bidderRequestClone);
const d = JSON.parse(requests[0].data);
expect(d.gdpr).to.equal(gdprApplies);
});
});
it('includes in the request parameters whether CCPA applies', function () {
const bidderRequestClone = utils.deepClone(bidderRequest);
const cases = [
{ uspConsent: '1---', expected: false },
{ uspConsent: '1YYY', expected: true },
{ uspConsent: '1YNN', expected: true },
{ uspConsent: '1NYN', expected: true },
{ uspConsent: '1-Y-', expected: true },
];
cases.forEach(function ({ uspConsent, expected }) {
bidderRequestClone.uspConsent = uspConsent;
const requests = spec.buildRequests(validBidRequests, bidderRequestClone);
const d = JSON.parse(requests[0].data);
expect(d.usp).to.equal(expected);
});
});
it('should add schain if available', function() {
const schain = {
'ver': '1.0',
'complete': 1,
'nodes': [
{
'asi': 'exchange1.example',
'sid': '1234!abcd',
'hp': 1,
'rid': 'bid-request-1',
'name': 'publisher, Inc.',
'domain': 'publisher.example'
},
{
'asi': 'exchange2.example',
'sid': 'abcd',
'hp': 1,
'rid': 'bid-request-2',
'name': 'intermediary',
'domain': 'intermediary.example'
}
]
};
const serializedSchain = '1.0,1!exchange1.example,1234%21abcd,1,bid-request-1,publisher%2C%20Inc.,publisher.example!exchange2.example,abcd,1,bid-request-2,intermediary,intermediary.example';
const [request] = spec.buildRequests([utils.mergeDeep(utils.deepClone(validBidRequests[0]), { ortb2: { source: { ext: { schain } } } })], bidderRequest);
const d = JSON.parse(request.data);
expect(d.schain).to.deep.equal(serializedSchain);
});
it('should add schain even if some nodes params are blank', function() {
const schain = {
'ver': '1.0',
'complete': 1,
'nodes': [
{
'asi': 'exchange1.example',
'sid': '1234!abcd',
'hp': 1,
},
{
},
{
'asi': 'exchange2.example',
'sid': 'abcd',
'hp': 1,
},
]
};
const serializedSchain = '1.0,1!exchange1.example,1234%21abcd,1,,,!,,,,,!exchange2.example,abcd,1,,,';
const [request] = spec.buildRequests([utils.mergeDeep(utils.deepClone(validBidRequests[0]), { ortb2: { source: { ext: { schain } } } })], bidderRequest);
const d = JSON.parse(request.data);
expect(d.schain).to.deep.equal(serializedSchain);
});
it('should add UA client hints to payload if available', function () {
const sua = {
browsers: [
{
brand: 'Not?A_Brand',
version: [
'8',
'0',
'0',
'0'
]
},
{
version: [
'108',
'0',
'5359',
'40'
]
},
{
brand: 'Google Chrome',
version: [
'108',
'0',
'5359',
'40'
]
}
],
platform: {
brand: 'Android',
version: [
'11'
]
},
mobile: 1,
architecture: '',
bitness: '64',
model: 'Pixel 5',
source: 2
}
const validBidRequestsClone = utils.deepClone(validBidRequests);
validBidRequestsClone[0] = utils.mergeDeep(validBidRequestsClone[0], {
ortb2: {
device: { sua },
}
});
const requests = spec.buildRequests(validBidRequestsClone, bidderRequest);
requests.forEach(function (r) {
const d = JSON.parse(r.data);
expect(d.sua).to.deep.equal(sua);
});
});
});
describe('interpretResponse', function () {
it('return empty array when no content', function () {
const bids = spec.interpretResponse({ body: '' });
expect(bids).to.deep.equal([]);
});
it('return empty array when seatbid empty', function () {
const bids = spec.interpretResponse({ body: { seatbid: [] } });
expect(bids).to.deep.equal([]);
});
it('return valid bids when serverResponse is valid', function () {
const serverResponse = {
'body': {
'seatbid': [
{
'bid': {
'ad': '<div>test response</div>',
'cpm': 5250,
'creativeId': '5_1234ABCD',
'currency': 'JPY',
'height': 250,
'meta': {
'advertiserDomains': [
'adv.example'
],
'mediaType': 'banner',
'networkId': 5
},
'netRevenue': true,
'requestId': '22a9457aed98a4',
'transactionId': 'f18c078e-4d2a-4ecb-a886-2a0c52187213',
'ttl': 60,
'width': 300,
}
}
]
},
'headers': {}
};
const bids = spec.interpretResponse(serverResponse);
expect(bids[0]).to.deep.equal(serverResponse.body.seatbid[0].bid);
});
});
});