Skip to content

Fix data transmission issues on AdYouLike bid adapter #4296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Jan 9, 2020
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
32adbfc
Merge remote-tracking branch 'origin/master'
guiann May 29, 2019
140b538
Remove useless bidderCode in bid response
guiann May 29, 2019
1bd5a3a
Merge remote-tracking branch 'guiann-prebid/master'
guiann May 29, 2019
613824c
Merge remote-tracking branch 'origin/master'
guiann Jun 13, 2019
8fb7857
Merge remote-tracking branch 'origin/master'
guiann Jul 18, 2019
21734b3
Merge branch 'master' into adYouLike-handleMultipleSizes
guiann Jul 18, 2019
e4a5f63
send all the available sizes in the bid request
guiann Jul 22, 2019
111dc49
Merge branch 'adYouLike-handleMultipleSizes'
guiann Jul 22, 2019
908eaab
Merge remote-tracking branch 'origin/master'
guiann Jul 22, 2019
edf4cd3
Use the banner sizes if given
guiann Jul 25, 2019
008ded4
avoid compatibility issue with old bid format
guiann Jul 25, 2019
9664b1a
Merge remote-tracking branch 'origin/master'
guiann Oct 10, 2019
3969709
remove duplicate call to encodeUriComponent
guiann Oct 10, 2019
5f15639
add unit test on refererUrl and mediatype banner size
guiann Oct 10, 2019
de62b48
minor: fix lint error on spec file
guiann Oct 11, 2019
31a9da0
if size is empty read the requested width or height
guiann Oct 14, 2019
2d73cee
add unit tests on multipe ad placement with several sizes
guiann Oct 14, 2019
807d010
Merge branch 'master' into TAG-85_doubleUrlEncode
guiann Oct 14, 2019
c0e9088
Merge remote-tracking branch 'Adyoulike/master'
guiann Oct 14, 2019
60fb40e
Merge branch 'master' into TAG-85_doubleUrlEncode
guiann Oct 14, 2019
d04706c
Merge remote-tracking branch 'origin/master' into TAG-85_doubleUrlEncode
guiann Oct 16, 2019
449f57f
Merge remote-tracking branch 'origin/master' into TAG-85_doubleUrlEncode
guiann Oct 22, 2019
d4d32bd
Merge branch 'master' into TAG-85_doubleUrlEncode
guiann Nov 4, 2019
bebf9c2
add check on bidRequest object in case of error state
guiann Nov 4, 2019
b46765a
Merge remote-tracking branch 'Adyoulike/master'
guiann Dec 24, 2019
67e154b
Merge branch 'master' into TAG-85_doubleUrlEncode
guiann Dec 24, 2019
1a4f452
Merge remote-tracking branch 'Adyoulike/master'
guiann Dec 24, 2019
96457bd
Merge branch 'master' into TAG-85_doubleUrlEncode
guiann Dec 24, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 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,20 @@ 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 (!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 = 'http://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);
});
});
});