Skip to content

Commit

Permalink
Feature/normalize size (prebid#2738)
Browse files Browse the repository at this point in the history
* Fix for incorrectly uppercased keys

* normalized the banner sizes param to always be [[h,w]]
  • Loading branch information
mkendall07 authored and AlessandroDG committed Sep 13, 2018
1 parent 027c6f7 commit 53daf9d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/adaptermanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,10 @@ exports.checkBidRequestSizes = (adUnits) => {
if (mediaTypes && mediaTypes.banner) {
const banner = mediaTypes.banner;
if (banner.sizes) {
adUnit.sizes = banner.sizes;
// make sure we always send [[h,w]] format
const normalizedSize = utils.getAdUnitSizes(adUnit);
banner.sizes = normalizedSize;
adUnit.sizes = normalizedSize;
} else {
utils.logError('Detected a mediaTypes.banner object did not include sizes. This is a required field for the mediaTypes.banner object. Removing invalid mediaTypes.banner object from request.');
delete adUnit.mediaTypes.banner;
Expand Down
14 changes: 14 additions & 0 deletions test/spec/unit/core/adapterManager_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,20 @@ describe('adapterManager tests', () => {
expect(result[0].mediaTypes.video).to.exist;
sinon.assert.calledOnce(utils.logInfo);
});

it('should normalize adUnit.sizes and adUnit.mediaTypes.banner.sizes', () => {
let fullAdUnit = [{
sizes: [300, 250],
mediaTypes: {
banner: {
sizes: [300, 250]
}
}
}];
let result = checkBidRequestSizes(fullAdUnit);
expect(result[0].sizes).to.deep.equal([[300, 250]]);
expect(result[0].mediaTypes.banner.sizes).to.deep.equal([[300, 250]]);
});
});

describe('negative tests for validating bid requests', () => {
Expand Down

0 comments on commit 53daf9d

Please sign in to comment.