Skip to content
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

Added tests to ensure buildRequestsand interpretResponse #7

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
24 changes: 21 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,16 @@ 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);
});

if (top.postIASResponse) {
postIASResponse(iasResponse);
}
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);
});
});
});
});