Skip to content

Commit

Permalink
fix: consolidate banner format array (#10365)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Corbo <[email protected]>
  • Loading branch information
ccorbo and Chris Corbo committed Aug 16, 2023
1 parent 7fc315f commit 0525202
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
8 changes: 4 additions & 4 deletions modules/ixBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ const MEDIA_TYPES = {
function bidToBannerImp(bid) {
const imp = bidToImp(bid, BANNER);
imp.banner = {};
imp.adunitCode = bid.adUnitCode;
const impSize = deepAccess(bid, 'params.size');
if (impSize) {
imp.banner.w = impSize[0];
Expand Down Expand Up @@ -344,7 +345,6 @@ function bidToImp(bid, mediaType) {
imp.id = bid.bidId;

imp.ext = {};

if (deepAccess(bid, `params.${mediaType}.siteId`) && !isNaN(Number(bid.params[mediaType].siteId))) {
switch (mediaType) {
case BANNER:
Expand Down Expand Up @@ -955,10 +955,10 @@ function addImpressions(impressions, impKeys, r, adUnitIndex) {

if (bannerImpressions.length > 0) {
const bannerImpsKeyed = bannerImpressions.reduce((acc, bannerImp) => {
if (!acc[bannerImp.id]) {
acc[bannerImp.id] = []
if (!acc[bannerImp.adunitCode]) {
acc[bannerImp.adunitCode] = []
}
acc[bannerImp.id].push(bannerImp);
acc[bannerImp.adunitCode].push(bannerImp);
return acc;
}, {});
for (const impId in bannerImpsKeyed) {
Expand Down
37 changes: 34 additions & 3 deletions test/spec/modules/ixBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1983,6 +1983,37 @@ describe('IndexexchangeAdapter', function () {
});
});

it('multi-configured size params should have the correct imp[].banner.format[].ext.siteID', function () {
const bid1 = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]);
const bid2 = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]);
bid1.params.siteId = 1234;
bid1.bidId = '27fc897708d826';
bid2.params.siteId = 4321;
bid2.bidId = '34df030c33dc68';
bid2.params.size = [300, 600];
request = spec.buildRequests([bid1, bid2], DEFAULT_OPTION)[0];

const payload = extractPayload(request);
expect(payload.imp[0].banner.format[0].ext.siteID).to.equal('1234');
expect(payload.imp[0].banner.format[1].ext.siteID).to.equal('4321');
});

it('multi-configured size params should be added to the imp[].banner.format[] array', function () {
const bid1 = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]);
const bid2 = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]);
bid1.params.siteId = 1234;
bid1.bidId = '27fc897708d826';
bid2.params.siteId = 4321;
bid2.bidId = '34df030c33dc68';
bid2.params.size = [300, 600];
request = spec.buildRequests([bid1, bid2], DEFAULT_OPTION)[0];

const payload = extractPayload(request);
expect(payload.imp[0].banner.format.length).to.equal(2);
expect(`${payload.imp[0].banner.format[0].w}x${payload.imp[0].banner.format[0].h}`).to.equal('300x250');
expect(`${payload.imp[0].banner.format[1].w}x${payload.imp[0].banner.format[1].h}`).to.equal('300x600');
});

describe('build requests with price floors', () => {
const highFloor = 4.5;
const lowFloor = 3.5;
Expand Down Expand Up @@ -4121,8 +4152,8 @@ describe('IndexexchangeAdapter', function () {
const bids = [DEFAULT_MULTIFORMAT_BANNER_VALID_BID[0], DEFAULT_MULTIFORMAT_NATIVE_VALID_BID[0]];
bids[0].params.bidFloor = 2.05;
bids[0].params.bidFloorCur = 'USD';
let tid = bids[1].transactionId;
bids[1].transactionId = bids[0].transactionId;
let adunitcode = bids[1].adUnitCode;
bids[1].adUnitCode = bids[0].adUnitCode;
bids[1].params.bidFloor = 2.35;
bids[1].params.bidFloorCur = 'USD';
const request = spec.buildRequests(bids, {});
Expand All @@ -4131,7 +4162,7 @@ describe('IndexexchangeAdapter', function () {
expect(extractPayload(request[0]).imp[0].bidfloor).to.equal(2.05);
expect(extractPayload(request[0]).imp[0].bidfloorcur).to.equal('USD');
expect(extractPayload(request[0]).imp[0].native.ext.bidfloor).to.equal(2.35);
bids[1].transactionId = tid;
bids[1].adUnitCode = adunitcode;
});

it('should return valid banner and video requests, different adunit, creates multiimp request', function () {
Expand Down

0 comments on commit 0525202

Please sign in to comment.