Skip to content

Commit

Permalink
Pet 239 ias bid adapter bug fix for multiple slots (prebid#2653)
Browse files Browse the repository at this point in the history
* PET-239 IAS bid adapter multiple slot fix (#1)

* PET-239 Fix.
Performs the request for multiple slots on 1 call.

* PET-239 Fixed Prebid tests

* PET-239 Additional unit tests

* Fixed errors for PR 2653 (#2)

* Pet 239 ias bid adapter bug fix for multiple slots (#3)

* Fixed errors for PR 2653

* Removed unnecessary block from iasBidAdapter from the comments in pull
2653
  • Loading branch information
bengel-ias authored and snapwich committed Jul 9, 2018
1 parent a2bb255 commit d5d5e34
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 5 deletions.
21 changes: 18 additions & 3 deletions modules/iasBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { registerBidder } from 'src/adapters/bidderFactory';

const BIDDER_CODE = 'ias';

const otherBidIds = [];

function isBidRequestValid(bid) {
const { pubId, adUnitPath } = bid.params;
return !!(pubId && adUnitPath);
Expand Down Expand Up @@ -37,11 +39,11 @@ function stringifySlot(bidRequest) {
}

function stringifyWindowSize() {
return [window.innerWidth || -1, window.innerHeight || -1].join('.');
return [ window.innerWidth || -1, window.innerHeight || -1 ].join('.');
}

function stringifyScreenSize() {
return [(window.screen && window.screen.width) || -1, (window.screen && window.screen.height) || -1].join('.');
return [ (window.screen && window.screen.width) || -1, (window.screen && window.screen.height) || -1 ].join('.');
}

function buildRequests(bidRequests) {
Expand All @@ -60,12 +62,18 @@ function buildRequests(bidRequests) {

const queryString = encodeURI(queries.map(qs => qs.join('=')).join('&'));

bidRequests.forEach(function (request) {
if (bidRequests[0].bidId != request.bidId) {
otherBidIds.push(request.bidId);
}
});

return {
method: 'GET',
url: IAS_HOST,
data: queryString,
bidRequest: bidRequests[0]
}
};
}

function getPageLevelKeywords(response) {
Expand Down Expand Up @@ -103,6 +111,13 @@ function interpretResponse(serverResponse, request) {
shallowMerge(commonBidResponse, getPageLevelKeywords(iasResponse));
commonBidResponse.slots = iasResponse.slots;
bidResponses.push(commonBidResponse);

otherBidIds.forEach(function (bidId) {
var otherResponse = Object.assign({}, commonBidResponse);
otherResponse.requestId = bidId;
bidResponses.push(otherResponse);
});

return bidResponses;
}

Expand Down
45 changes: 43 additions & 2 deletions test/spec/modules/iasBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ describe('iasBidAdapter is an adapter that', () => {
url: IAS_HOST
});
});
it('only includes the first `bidRequest` as the bidRequest variable on a multiple slot request', () => {
expect(spec.buildRequests(bidRequests).bidRequest.adUnitCode).to.equal(bidRequests[0].adUnitCode);
});
describe('has property `data` that is an encode query string containing information such as', () => {
let val;
const ANID_PARAM = 'anId';
Expand Down Expand Up @@ -124,8 +127,41 @@ describe('iasBidAdapter is an adapter that', () => {
expect(spec.interpretResponse).to.be.a('function');
});
describe('returns a list of bid response that', () => {
let bidResponse, slots;
let bidRequests, bidResponse, slots, serverResponse;
beforeEach(() => {
bidRequests = [
{
adUnitCode: 'one-div-id',
auctionId: 'someAuctionId',
bidId: 'someBidId1',
bidder: 'ias',
bidderRequestId: 'someBidderRequestId',
params: {
pubId: '1234',
adUnitPath: '/a/b/c'
},
sizes: [
[10, 20],
[300, 400]
],
transactionId: 'someTransactionId'
},
{
adUnitCode: 'two-div-id',
auctionId: 'someAuctionId',
bidId: 'someBidId2',
bidder: 'ias',
bidderRequestId: 'someBidderRequestId',
params: {
pubId: '1234',
adUnitPath: '/d/e/f'
},
sizes: [
[50, 60]
],
transactionId: 'someTransactionId'
}
];
const request = {
bidRequest: {
bidId: '102938'
Expand All @@ -140,7 +176,7 @@ describe('iasBidAdapter is an adapter that', () => {
id: '5678',
vw: ['80', '90']
};
const serverResponse = {
serverResponse = {
body: {
brandSafety: {
adt: 'adtVal',
Expand Down Expand Up @@ -185,6 +221,11 @@ describe('iasBidAdapter is an adapter that', () => {
it('has property `slots`', () => {
expect(bidResponse[0]).to.deep.include({ slots: slots });
});
it('response is the same for multiple slots', () => {
var adapter = spec;
var requests = adapter.buildRequests(bidRequests);
expect(adapter.interpretResponse(serverResponse, requests)).to.length(2);
});
});
});
});

0 comments on commit d5d5e34

Please sign in to comment.