-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathadtargetBidAdapter_spec.js
More file actions
353 lines (311 loc) · 10.1 KB
/
adtargetBidAdapter_spec.js
File metadata and controls
353 lines (311 loc) · 10.1 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
import { expect } from 'chai';
import { spec } from 'modules/adtargetBidAdapter.js';
import { newBidder } from 'src/adapters/bidderFactory.js';
import { config } from 'src/config.js';
const DISPLAY_REQUEST = {
'bidder': 'adtarget',
'params': {
'aid': 12345
},
'userId': { criteo: 2 },
'mediaTypes': { 'banner': { 'sizes': [300, 250] } },
'bidderRequestId': '7101db09af0db2',
'auctionId': '2e41f65424c87c',
'adUnitCode': 'adunit-code',
'bidId': '84ab500420319d',
};
const VIDEO_REQUEST = {
'bidder': 'adtarget',
'mediaTypes': {
'video': {
'playerSize': [[480, 360], [640, 480]]
}
},
'params': {
'aid': 12345
},
'bidderRequestId': '7101db09af0db2',
'auctionId': '2e41f65424c87c',
'adUnitCode': 'adunit-code',
'bidId': '84ab500420319d'
};
const SERVER_VIDEO_RESPONSE = {
'source': { 'aid': 12345, 'pubId': 54321 },
'bids': [{
'vastUrl': 'https://rtb.adtarget.com/vast/?adid=44F2AEB9BFC881B3',
'requestId': '2e41f65424c87c',
'url': '44F2AEB9BFC881B3',
'creative_id': 342516,
'durationSeconds': 30,
'cmpId': 342516,
'height': 480,
'cur': 'USD',
'width': 640,
'cpm': 0.9,
'adomain': ['a.com']
}]
};
const SERVER_DISPLAY_RESPONSE = {
'source': { 'aid': 12345, 'pubId': 54321 },
'bids': [{
'ad': '<!-- Creative -->',
'requestId': '2e41f65424c87c',
'creative_id': 342516,
'cmpId': 342516,
'height': 250,
'cur': 'USD',
'width': 300,
'cpm': 0.9
}],
'cookieURLs': ['link1', 'link2']
};
const SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS = {
'source': { 'aid': 12345, 'pubId': 54321 },
'bids': [{
'ad': '<!-- Creative -->',
'requestId': '2e41f65424c87c',
'creative_id': 342516,
'cmpId': 342516,
'height': 250,
'cur': 'USD',
'width': 300,
'cpm': 0.9
}],
'cookieURLs': ['link3', 'link4'],
'cookieURLSTypes': ['image', 'iframe']
};
const videoBidderRequest = {
bidderCode: 'bidderCode',
bids: [{ mediaTypes: { video: {} }, bidId: '2e41f65424c87c' }]
};
const displayBidderRequest = {
bidderCode: 'bidderCode',
bids: [{ bidId: '2e41f65424c87c' }]
};
const displayBidderRequestWithConsents = {
bidderCode: 'bidderCode',
bids: [{ bidId: '2e41f65424c87c' }],
gdprConsent: {
gdprApplies: true,
consentString: 'test'
},
uspConsent: 'iHaveIt',
ortb2: {
source: {
ext: {
schain: {
ver: '1.0'
}
}
}
}
};
const videoEqResponse = [{
vastUrl: 'https://rtb.adtarget.com/vast/?adid=44F2AEB9BFC881B3',
requestId: '2e41f65424c87c',
creativeId: 342516,
mediaType: 'video',
netRevenue: true,
currency: 'USD',
height: 480,
width: 640,
ttl: 300,
cpm: 0.9,
meta: {
advertiserDomains: ['a.com']
}
}];
const displayEqResponse = [{
requestId: '2e41f65424c87c',
creativeId: 342516,
mediaType: 'banner',
netRevenue: true,
currency: 'USD',
ad: '<!-- Creative -->',
height: 250,
width: 300,
ttl: 300,
cpm: 0.9,
meta: {
advertiserDomains: []
}
}];
describe('adtargetBidAdapter', () => {
const adapter = newBidder(spec);
describe('inherited functions', () => {
it('exists and is a function', () => {
expect(adapter.callBids).to.exist.and.to.be.a('function');
});
});
describe('user syncs', () => {
describe('as image', () => {
it('should be returned if pixel enabled', () => {
const syncs = spec.getUserSyncs({ pixelEnabled: true }, [{ body: SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS }]);
expect(syncs.map(s => s.url)).to.deep.equal([SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS.cookieURLs[0]]);
expect(syncs.map(s => s.type)).to.deep.equal(['image']);
})
})
describe('as iframe', () => {
it('should be returned if iframe enabled', () => {
const syncs = spec.getUserSyncs({ iframeEnabled: true }, [{ body: SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS }]);
expect(syncs.map(s => s.url)).to.deep.equal([SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS.cookieURLs[1]]);
expect(syncs.map(s => s.type)).to.deep.equal(['iframe']);
})
})
describe('user sync', () => {
it('should not be returned if passed syncs where already used', () => {
const syncs = spec.getUserSyncs({
iframeEnabled: true,
pixelEnabled: true
}, [{ body: SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS }]);
expect(syncs).to.deep.equal([]);
})
it('should not be returned if pixel not set', () => {
const syncs = spec.getUserSyncs({}, [{ body: SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS }]);
expect(syncs).to.be.empty;
});
});
describe('user syncs with both types', () => {
it('should be returned if pixel and iframe enabled', () => {
const mockedServerResponse = Object.assign({}, SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS, { 'cookieURLs': ['link5', 'link6'] });
const syncs = spec.getUserSyncs({
iframeEnabled: true,
pixelEnabled: true
}, [{ body: mockedServerResponse }]);
expect(syncs.map(s => s.url)).to.deep.equal(mockedServerResponse.cookieURLs);
expect(syncs.map(s => s.type)).to.deep.equal(mockedServerResponse.cookieURLSTypes);
});
});
});
describe('isBidRequestValid', () => {
it('should return true when required params found', () => {
expect(spec.isBidRequestValid(VIDEO_REQUEST)).to.equal(true);
});
it('should return false when required params are not passed', () => {
const bid = Object.assign({}, VIDEO_REQUEST);
delete bid.params;
expect(spec.isBidRequestValid(bid)).to.equal(false);
});
});
describe('buildRequests', () => {
const videoBidRequests = [VIDEO_REQUEST];
const displayBidRequests = [DISPLAY_REQUEST];
const videoAndDisplayBidRequests = [DISPLAY_REQUEST, VIDEO_REQUEST];
const displayRequest = spec.buildRequests(displayBidRequests, {});
const videoRequest = spec.buildRequests(videoBidRequests, {});
const videoAndDisplayRequests = spec.buildRequests(videoAndDisplayBidRequests, {});
it('building requests as arrays', () => {
expect(videoRequest).to.be.a('array');
expect(displayRequest).to.be.a('array');
expect(videoAndDisplayRequests).to.be.a('array');
})
it('sending as POST', () => {
const postActionMethod = 'POST'
const comparator = br => br.method === postActionMethod;
expect(videoRequest.every(comparator)).to.be.true;
expect(displayRequest.every(comparator)).to.be.true;
expect(videoAndDisplayRequests.every(comparator)).to.be.true;
});
it('sends correct video bid parameters', () => {
const data = videoRequest[0].data;
const eq = {
CallbackId: '84ab500420319d',
AdType: 'video',
Aid: 12345,
Sizes: '480x360,640x480'
};
expect(data.BidRequests[0]).to.deep.equal(eq);
});
it('sends correct display bid parameters', () => {
const data = displayRequest[0].data;
const eq = {
CallbackId: '84ab500420319d',
AdType: 'display',
Aid: 12345,
Sizes: '300x250'
};
expect(data.BidRequests[0]).to.deep.equal(eq);
});
it('sends correct video and display bid parameters', () => {
const bidRequests = videoAndDisplayRequests[0].data;
const expectedBidReqs = [{
CallbackId: '84ab500420319d',
AdType: 'display',
Aid: 12345,
Sizes: '300x250'
}, {
CallbackId: '84ab500420319d',
AdType: 'video',
Aid: 12345,
Sizes: '480x360,640x480'
}]
expect(bidRequests.BidRequests).to.deep.equal(expectedBidReqs);
});
describe('publisher environment', () => {
const sandbox = sinon.createSandbox();
sandbox.stub(config, 'getConfig').callsFake((key) => {
const config = {
'coppa': true
};
return config[key];
});
const bidRequestWithPubSettingsData = spec.buildRequests([DISPLAY_REQUEST], displayBidderRequestWithConsents)[0].data;
sandbox.restore();
it('sets GDPR', () => {
expect(bidRequestWithPubSettingsData.GDPR).to.be.equal(1);
expect(bidRequestWithPubSettingsData.GDPRConsent).to.be.equal(displayBidderRequestWithConsents.gdprConsent.consentString);
});
it('sets USP', () => {
expect(bidRequestWithPubSettingsData.USP).to.be.equal(displayBidderRequestWithConsents.uspConsent);
})
it('sets Coppa', () => {
expect(bidRequestWithPubSettingsData.Coppa).to.be.equal(1);
})
it('sets Schain', () => {
expect(bidRequestWithPubSettingsData.Schain).to.be.deep.equal(displayBidderRequestWithConsents.ortb2.source.ext.schain);
})
it('sets UserId\'s', () => {
expect(bidRequestWithPubSettingsData.UserIds).to.be.deep.equal(DISPLAY_REQUEST.userId);
})
})
});
describe('interpretResponse', () => {
let serverResponse;
let adapterRequest;
let eqResponse;
afterEach(() => {
serverResponse = null;
adapterRequest = null;
eqResponse = null;
});
it('should get correct video bid response', () => {
serverResponse = SERVER_VIDEO_RESPONSE;
adapterRequest = videoBidderRequest;
eqResponse = videoEqResponse;
bidServerResponseCheck();
});
it('should get correct display bid response', () => {
serverResponse = SERVER_DISPLAY_RESPONSE;
adapterRequest = displayBidderRequest;
eqResponse = displayEqResponse;
bidServerResponseCheck();
});
function bidServerResponseCheck() {
const result = spec.interpretResponse({ body: serverResponse }, { adapterRequest });
expect(result).to.deep.equal(eqResponse);
}
function nobidServerResponseCheck() {
const noBidServerResponse = { bids: [] };
const noBidResult = spec.interpretResponse({ body: noBidServerResponse }, { adapterRequest });
expect(noBidResult.length).to.equal(0);
}
it('handles video nobid responses', () => {
adapterRequest = videoBidderRequest;
nobidServerResponseCheck();
});
it('handles display nobid responses', () => {
adapterRequest = displayBidderRequest;
nobidServerResponseCheck();
});
});
});