Skip to content

Commit

Permalink
fix: consolidate banenr format array (#10366)
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 243c3dc commit e1fceb1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
7 changes: 4 additions & 3 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 @@ -918,10 +919,10 @@ function addImpressions(impressions, transactionIds, 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
34 changes: 33 additions & 1 deletion test/spec/modules/ixBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1966,6 +1966,38 @@ 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.length).to.equal(1);
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 @@ -4009,7 +4041,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.05);
bids[1].adUnitCode = tid;
bids[1].transactionId = tid;
});

it('multiformat banner / native - bid floors, banner imp less', function () {
Expand Down

0 comments on commit e1fceb1

Please sign in to comment.