Skip to content

Commit 84d44df

Browse files
guiannGLStephen
authored andcommitted
Fix data transmission issues on AdYouLike bid adapter (prebid#4296)
* Remove useless bidderCode in bid response * send all the available sizes in the bid request * Use the banner sizes if given * avoid compatibility issue with old bid format * remove duplicate call to encodeUriComponent * add unit test on refererUrl and mediatype banner size * minor: fix lint error on spec file * if size is empty read the requested width or height * add unit tests on multipe ad placement with several sizes * add check on bidRequest object in case of error state
1 parent a4d7191 commit 84d44df

File tree

2 files changed

+105
-31
lines changed

2 files changed

+105
-31
lines changed

modules/adyoulikeBidAdapter.js

+23-4
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,19 @@ export const spec = {
7272
* @param {*} serverResponse A successful response from the server.
7373
* @return {Bid[]} An array of bids which were nested inside the server.
7474
*/
75-
interpretResponse: function (serverResponse, bidRequest) {
75+
interpretResponse: function (serverResponse, request) {
7676
const bidResponses = [];
77+
var bidRequests = {};
78+
79+
try {
80+
bidRequests = JSON.parse(request.data).Bids;
81+
} catch (e) {
82+
// json error initial request can't be read
83+
}
84+
7785
// For this adapter, serverResponse is a list
7886
serverResponse.body.forEach(response => {
79-
const bid = createBid(response);
87+
const bid = createBid(response, bidRequests);
8088
if (bid) {
8189
bidResponses.push(bid);
8290
}
@@ -98,7 +106,7 @@ function getHostname(bidderRequest) {
98106
function getReferrerUrl(bidderRequest) {
99107
let referer = '';
100108
if (bidderRequest && bidderRequest.refererInfo) {
101-
referer = encodeURIComponent(bidderRequest.refererInfo.referer);
109+
referer = bidderRequest.refererInfo.referer;
102110
}
103111
return referer;
104112
}
@@ -192,11 +200,22 @@ function getSize(sizesArray) {
192200
}
193201

194202
/* Create bid from response */
195-
function createBid(response) {
203+
function createBid(response, bidRequests) {
196204
if (!response || !response.Ad) {
197205
return
198206
}
199207

208+
// In case we don't retreive the size from the adserver, use the given one.
209+
if (bidRequests && bidRequests[response.BidID]) {
210+
if (!response.Width || response.Width === '0') {
211+
response.Width = bidRequests[response.BidID].Width;
212+
}
213+
214+
if (!response.Height || response.Height === '0') {
215+
response.Height = bidRequests[response.BidID].Height;
216+
}
217+
}
218+
200219
return {
201220
requestId: response.BidID,
202221
width: response.Width,

test/spec/modules/adyoulikeBidAdapter_spec.js

+82-27
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,31 @@ import { newBidder } from 'src/adapters/bidderFactory';
66

77
describe('Adyoulike Adapter', function () {
88
const canonicalUrl = 'https://canonical.url/?t=%26';
9+
const referrerUrl = 'http://referrer.url/?param=value';
910
const defaultDC = 'hb-api';
11+
const consentString = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A==';
12+
const bidderRequest = {
13+
'auctionId': '1d1a030790a475',
14+
'bidderRequestId': '22edbae2733bf6',
15+
'timeout': 3000,
16+
'gdprConsent': {
17+
consentString: consentString,
18+
gdprApplies: true
19+
},
20+
refererInfo: {referer: referrerUrl}
21+
};
1022
const bidRequestWithEmptyPlacement = [
1123
{
1224
'bidId': 'bid_id_0',
1325
'bidder': 'adyoulike',
1426
'placementCode': 'adunit/hb-0',
1527
'params': {},
16-
'sizes': '300x250'
28+
'sizes': '300x250',
29+
'mediaTypes':
30+
{ 'banner':
31+
{'sizes': ['300x250', '300x600']
32+
}
33+
}
1734
}
1835
];
1936
const bidRequestWithEmptySizes = {
@@ -39,6 +56,11 @@ describe('Adyoulike Adapter', function () {
3956
'placement': 'placement_0'
4057
},
4158
'sizes': '300x250',
59+
'mediaTypes':
60+
{ 'banner':
61+
{'sizes': ['300x250']
62+
}
63+
},
4264
'transactionId': 'bid_id_0_transaction_id'
4365
}
4466
];
@@ -53,6 +75,11 @@ describe('Adyoulike Adapter', function () {
5375
'DC': 'fra01'
5476
},
5577
'sizes': '300x250',
78+
'mediaTypes':
79+
{ 'banner':
80+
{'sizes': ['300x250']
81+
}
82+
},
5683
'transactionId': 'bid_id_0_transaction_id'
5784
}
5885
];
@@ -66,6 +93,11 @@ describe('Adyoulike Adapter', function () {
6693
'placement': 'placement_0'
6794
},
6895
'sizes': '300x250',
96+
'mediaTypes':
97+
{ 'banner':
98+
{'sizes': ['300x250']
99+
}
100+
},
69101
'transactionId': 'bid_id_0_transaction_id'
70102
},
71103
{
@@ -76,6 +108,11 @@ describe('Adyoulike Adapter', function () {
76108
'placement': 'placement_1'
77109
},
78110
'sizes': [[300, 600]],
111+
'mediaTypes':
112+
{ 'banner':
113+
{'sizes': ['300x600']
114+
}
115+
},
79116
'transactionId': 'bid_id_1_transaction_id'
80117
},
81118
{
@@ -97,6 +134,33 @@ describe('Adyoulike Adapter', function () {
97134
}
98135
];
99136

137+
const requestDataOnePlacement = {
138+
'bid_id_0':
139+
{ 'PlacementID': 'e622af275681965d3095808561a1e510',
140+
'TransactionID': '1bca18cc-c0fe-439b-88c2-8247d3448f22',
141+
'Width': 300,
142+
'Height': 600,
143+
'AvailableSizes': '300x600'
144+
}
145+
}
146+
147+
const requestDataMultiPlacement = {
148+
'bid_id_0':
149+
{ 'PlacementID': 'e622af275681965d3095808561a1e510',
150+
'TransactionID': '1bca18cc-c0fe-439b-88c2-8247d3448f22',
151+
'Width': 300,
152+
'Height': 600,
153+
'AvailableSizes': '300x600'
154+
},
155+
'bid_id_1':
156+
{ 'PlacementID': 'e622af275681965d3095808561a1e510',
157+
'TransactionID': 'e63b2d86-ca60-4167-9cf1-497607079634',
158+
'Width': 400,
159+
'Height': 250,
160+
'AvailableSizes': '300x250'
161+
}
162+
}
163+
100164
const responseWithEmptyPlacement = [
101165
{
102166
'Placement': 'placement_0'
@@ -108,8 +172,7 @@ describe('Adyoulike Adapter', function () {
108172
'Placement': 'placement_0',
109173
'Ad': 'placement_0',
110174
'Price': 0.5,
111-
'Height': 300,
112-
'Width': 300,
175+
'Height': 600,
113176
}
114177
];
115178
const responseWithMultiplePlacements = [
@@ -118,16 +181,16 @@ describe('Adyoulike Adapter', function () {
118181
'Placement': 'placement_0',
119182
'Ad': 'placement_0',
120183
'Price': 0.5,
121-
'Height': 300,
122-
'Width': 300,
184+
'Height': 0, // test with wrong value
185+
'Width': 300
123186
},
124187
{
125188
'BidID': 'bid_id_1',
126189
'Placement': 'placement_1',
127190
'Ad': 'placement_1',
128191
'Price': 0.6,
129-
'Height': 300,
130-
'Width': 300,
192+
'Height': 250
193+
// 'Width' test with missing value
131194
}
132195
];
133196
const adapter = newBidder(spec);
@@ -189,16 +252,6 @@ describe('Adyoulike Adapter', function () {
189252
});
190253

191254
it('should add gdpr consent information to the request', function () {
192-
let consentString = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A==';
193-
let bidderRequest = {
194-
'auctionId': '1d1a030790a475',
195-
'bidderRequestId': '22edbae2733bf6',
196-
'timeout': 3000,
197-
'gdprConsent': {
198-
consentString: consentString,
199-
gdprApplies: true
200-
}
201-
};
202255
bidderRequest.bids = bidRequestWithSinglePlacement;
203256

204257
const request = spec.buildRequests(bidRequestWithSinglePlacement, bidderRequest);
@@ -210,12 +263,13 @@ describe('Adyoulike Adapter', function () {
210263
});
211264

212265
it('sends bid request to endpoint with single placement', function () {
213-
const request = spec.buildRequests(bidRequestWithSinglePlacement);
266+
const request = spec.buildRequests(bidRequestWithSinglePlacement, bidderRequest);
214267
const payload = JSON.parse(request.data);
215268

216269
expect(request.url).to.contain(getEndpoint());
217270
expect(request.method).to.equal('POST');
218271
expect(request.url).to.contains('CanonicalUrl=' + encodeURIComponent(canonicalUrl));
272+
expect(request.url).to.contains('RefererUrl=' + encodeURIComponent(referrerUrl));
219273

220274
expect(payload.Version).to.equal('1.0');
221275
expect(payload.Bids['bid_id_0'].PlacementID).to.be.equal('placement_0');
@@ -225,7 +279,7 @@ describe('Adyoulike Adapter', function () {
225279

226280
it('sends bid request to endpoint with single placement without canonical', function () {
227281
canonicalQuery.restore();
228-
const request = spec.buildRequests(bidRequestWithSinglePlacement);
282+
const request = spec.buildRequests(bidRequestWithSinglePlacement, bidderRequest);
229283
const payload = JSON.parse(request.data);
230284

231285
expect(request.url).to.contain(getEndpoint());
@@ -239,12 +293,13 @@ describe('Adyoulike Adapter', function () {
239293
});
240294

241295
it('sends bid request to endpoint with multiple placements', function () {
242-
const request = spec.buildRequests(bidRequestMultiPlacements);
296+
const request = spec.buildRequests(bidRequestMultiPlacements, bidderRequest);
243297
const payload = JSON.parse(request.data);
244298
expect(request.url).to.contain(getEndpoint());
245299
expect(request.method).to.equal('POST');
246300

247301
expect(request.url).to.contains('CanonicalUrl=' + encodeURIComponent(canonicalUrl));
302+
expect(request.url).to.contains('RefererUrl=' + encodeURIComponent(referrerUrl));
248303

249304
expect(payload.Version).to.equal('1.0');
250305

@@ -259,7 +314,7 @@ describe('Adyoulike Adapter', function () {
259314
});
260315

261316
it('sends bid request to endpoint setted by parameters', function () {
262-
const request = spec.buildRequests(bidRequestWithDCPlacement);
317+
const request = spec.buildRequests(bidRequestWithDCPlacement, bidderRequest);
263318
const payload = JSON.parse(request.data);
264319

265320
expect(request.url).to.contain(getEndpoint(`${defaultDC}-fra01`));
@@ -288,30 +343,30 @@ describe('Adyoulike Adapter', function () {
288343

289344
it('receive reponse with single placement', function () {
290345
serverResponse.body = responseWithSinglePlacement;
291-
let result = spec.interpretResponse(serverResponse, bidRequestWithSinglePlacement);
346+
let result = spec.interpretResponse(serverResponse, {data: '{"Bids":' + JSON.stringify(requestDataOnePlacement) + '}'});
292347

293348
expect(result.length).to.equal(1);
294349
expect(result[0].cpm).to.equal(0.5);
295350
expect(result[0].ad).to.equal('placement_0');
296351
expect(result[0].width).to.equal(300);
297-
expect(result[0].height).to.equal(300);
352+
expect(result[0].height).to.equal(600);
298353
});
299354

300355
it('receive reponse with multiple placement', function () {
301356
serverResponse.body = responseWithMultiplePlacements;
302-
let result = spec.interpretResponse(serverResponse, bidRequestMultiPlacements);
357+
let result = spec.interpretResponse(serverResponse, {data: '{"Bids":' + JSON.stringify(requestDataMultiPlacement) + '}'});
303358

304359
expect(result.length).to.equal(2);
305360

306361
expect(result[0].cpm).to.equal(0.5);
307362
expect(result[0].ad).to.equal('placement_0');
308363
expect(result[0].width).to.equal(300);
309-
expect(result[0].height).to.equal(300);
364+
expect(result[0].height).to.equal(600);
310365

311366
expect(result[1].cpm).to.equal(0.6);
312367
expect(result[1].ad).to.equal('placement_1');
313-
expect(result[1].width).to.equal(300);
314-
expect(result[1].height).to.equal(300);
368+
expect(result[1].width).to.equal(400);
369+
expect(result[1].height).to.equal(250);
315370
});
316371
});
317372
});

0 commit comments

Comments
 (0)