Skip to content

Commit

Permalink
Fix data transmission issues on AdYouLike bid adapter (prebid#4296)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
guiann authored and GLStephen committed Jan 9, 2020
1 parent a4d7191 commit 84d44df
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 31 deletions.
27 changes: 23 additions & 4 deletions modules/adyoulikeBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,19 @@ export const spec = {
* @param {*} serverResponse A successful response from the server.
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function (serverResponse, bidRequest) {
interpretResponse: function (serverResponse, request) {
const bidResponses = [];
var bidRequests = {};

try {
bidRequests = JSON.parse(request.data).Bids;
} catch (e) {
// json error initial request can't be read
}

// For this adapter, serverResponse is a list
serverResponse.body.forEach(response => {
const bid = createBid(response);
const bid = createBid(response, bidRequests);
if (bid) {
bidResponses.push(bid);
}
Expand All @@ -98,7 +106,7 @@ function getHostname(bidderRequest) {
function getReferrerUrl(bidderRequest) {
let referer = '';
if (bidderRequest && bidderRequest.refererInfo) {
referer = encodeURIComponent(bidderRequest.refererInfo.referer);
referer = bidderRequest.refererInfo.referer;
}
return referer;
}
Expand Down Expand Up @@ -192,11 +200,22 @@ function getSize(sizesArray) {
}

/* Create bid from response */
function createBid(response) {
function createBid(response, bidRequests) {
if (!response || !response.Ad) {
return
}

// In case we don't retreive the size from the adserver, use the given one.
if (bidRequests && bidRequests[response.BidID]) {
if (!response.Width || response.Width === '0') {
response.Width = bidRequests[response.BidID].Width;
}

if (!response.Height || response.Height === '0') {
response.Height = bidRequests[response.BidID].Height;
}
}

return {
requestId: response.BidID,
width: response.Width,
Expand Down
109 changes: 82 additions & 27 deletions test/spec/modules/adyoulikeBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,31 @@ import { newBidder } from 'src/adapters/bidderFactory';

describe('Adyoulike Adapter', function () {
const canonicalUrl = 'https://canonical.url/?t=%26';
const referrerUrl = 'http://referrer.url/?param=value';
const defaultDC = 'hb-api';
const consentString = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A==';
const bidderRequest = {
'auctionId': '1d1a030790a475',
'bidderRequestId': '22edbae2733bf6',
'timeout': 3000,
'gdprConsent': {
consentString: consentString,
gdprApplies: true
},
refererInfo: {referer: referrerUrl}
};
const bidRequestWithEmptyPlacement = [
{
'bidId': 'bid_id_0',
'bidder': 'adyoulike',
'placementCode': 'adunit/hb-0',
'params': {},
'sizes': '300x250'
'sizes': '300x250',
'mediaTypes':
{ 'banner':
{'sizes': ['300x250', '300x600']
}
}
}
];
const bidRequestWithEmptySizes = {
Expand All @@ -39,6 +56,11 @@ describe('Adyoulike Adapter', function () {
'placement': 'placement_0'
},
'sizes': '300x250',
'mediaTypes':
{ 'banner':
{'sizes': ['300x250']
}
},
'transactionId': 'bid_id_0_transaction_id'
}
];
Expand All @@ -53,6 +75,11 @@ describe('Adyoulike Adapter', function () {
'DC': 'fra01'
},
'sizes': '300x250',
'mediaTypes':
{ 'banner':
{'sizes': ['300x250']
}
},
'transactionId': 'bid_id_0_transaction_id'
}
];
Expand All @@ -66,6 +93,11 @@ describe('Adyoulike Adapter', function () {
'placement': 'placement_0'
},
'sizes': '300x250',
'mediaTypes':
{ 'banner':
{'sizes': ['300x250']
}
},
'transactionId': 'bid_id_0_transaction_id'
},
{
Expand All @@ -76,6 +108,11 @@ describe('Adyoulike Adapter', function () {
'placement': 'placement_1'
},
'sizes': [[300, 600]],
'mediaTypes':
{ 'banner':
{'sizes': ['300x600']
}
},
'transactionId': 'bid_id_1_transaction_id'
},
{
Expand All @@ -97,6 +134,33 @@ describe('Adyoulike Adapter', function () {
}
];

const requestDataOnePlacement = {
'bid_id_0':
{ 'PlacementID': 'e622af275681965d3095808561a1e510',
'TransactionID': '1bca18cc-c0fe-439b-88c2-8247d3448f22',
'Width': 300,
'Height': 600,
'AvailableSizes': '300x600'
}
}

const requestDataMultiPlacement = {
'bid_id_0':
{ 'PlacementID': 'e622af275681965d3095808561a1e510',
'TransactionID': '1bca18cc-c0fe-439b-88c2-8247d3448f22',
'Width': 300,
'Height': 600,
'AvailableSizes': '300x600'
},
'bid_id_1':
{ 'PlacementID': 'e622af275681965d3095808561a1e510',
'TransactionID': 'e63b2d86-ca60-4167-9cf1-497607079634',
'Width': 400,
'Height': 250,
'AvailableSizes': '300x250'
}
}

const responseWithEmptyPlacement = [
{
'Placement': 'placement_0'
Expand All @@ -108,8 +172,7 @@ describe('Adyoulike Adapter', function () {
'Placement': 'placement_0',
'Ad': 'placement_0',
'Price': 0.5,
'Height': 300,
'Width': 300,
'Height': 600,
}
];
const responseWithMultiplePlacements = [
Expand All @@ -118,16 +181,16 @@ describe('Adyoulike Adapter', function () {
'Placement': 'placement_0',
'Ad': 'placement_0',
'Price': 0.5,
'Height': 300,
'Width': 300,
'Height': 0, // test with wrong value
'Width': 300
},
{
'BidID': 'bid_id_1',
'Placement': 'placement_1',
'Ad': 'placement_1',
'Price': 0.6,
'Height': 300,
'Width': 300,
'Height': 250
// 'Width' test with missing value
}
];
const adapter = newBidder(spec);
Expand Down Expand Up @@ -189,16 +252,6 @@ describe('Adyoulike Adapter', function () {
});

it('should add gdpr consent information to the request', function () {
let consentString = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A==';
let bidderRequest = {
'auctionId': '1d1a030790a475',
'bidderRequestId': '22edbae2733bf6',
'timeout': 3000,
'gdprConsent': {
consentString: consentString,
gdprApplies: true
}
};
bidderRequest.bids = bidRequestWithSinglePlacement;

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

it('sends bid request to endpoint with single placement', function () {
const request = spec.buildRequests(bidRequestWithSinglePlacement);
const request = spec.buildRequests(bidRequestWithSinglePlacement, bidderRequest);
const payload = JSON.parse(request.data);

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

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

it('sends bid request to endpoint with single placement without canonical', function () {
canonicalQuery.restore();
const request = spec.buildRequests(bidRequestWithSinglePlacement);
const request = spec.buildRequests(bidRequestWithSinglePlacement, bidderRequest);
const payload = JSON.parse(request.data);

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

it('sends bid request to endpoint with multiple placements', function () {
const request = spec.buildRequests(bidRequestMultiPlacements);
const request = spec.buildRequests(bidRequestMultiPlacements, bidderRequest);
const payload = JSON.parse(request.data);
expect(request.url).to.contain(getEndpoint());
expect(request.method).to.equal('POST');

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

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

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

it('sends bid request to endpoint setted by parameters', function () {
const request = spec.buildRequests(bidRequestWithDCPlacement);
const request = spec.buildRequests(bidRequestWithDCPlacement, bidderRequest);
const payload = JSON.parse(request.data);

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

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

expect(result.length).to.equal(1);
expect(result[0].cpm).to.equal(0.5);
expect(result[0].ad).to.equal('placement_0');
expect(result[0].width).to.equal(300);
expect(result[0].height).to.equal(300);
expect(result[0].height).to.equal(600);
});

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

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

expect(result[0].cpm).to.equal(0.5);
expect(result[0].ad).to.equal('placement_0');
expect(result[0].width).to.equal(300);
expect(result[0].height).to.equal(300);
expect(result[0].height).to.equal(600);

expect(result[1].cpm).to.equal(0.6);
expect(result[1].ad).to.equal('placement_1');
expect(result[1].width).to.equal(300);
expect(result[1].height).to.equal(300);
expect(result[1].width).to.equal(400);
expect(result[1].height).to.equal(250);
});
});
});

0 comments on commit 84d44df

Please sign in to comment.