Skip to content

Commit

Permalink
improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcin Komorski authored and Marcin Komorski committed Sep 11, 2024
1 parent 8366048 commit f90c448
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 6 deletions.
12 changes: 7 additions & 5 deletions src/prebid.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,20 @@ function validateSizes(sizes, targLength) {
return cleanSizes;
}

function setBattrForAdUnit(adUnit, mediaType) {
export function setBattrForAdUnit(adUnit, mediaType) {
const ortb2Imp = adUnit.ortb2Imp || {};
const mediaTypes = adUnit.mediaTypes || {};

if (ortb2Imp[mediaType]?.battr && mediaTypes[mediaType]?.battr && (ortb2Imp[mediaType]?.battr !== mediaTypes[mediaType]?.battr)) {
logWarn('battr field differ between ortb2Imp and mediaTypes');
logWarn(`not equal: adUnit.ortb2Imp.${mediaType}.battr: ${ortb2Imp[mediaType].battr} and adUnit.mediaTypes.${mediaType}.battr: ${mediaTypes[mediaType].battr}`);
}

const battr = ortb2Imp[mediaType]?.battr || mediaTypes[mediaType]?.battr;

adUnit.ortb2Imp = {...ortb2Imp, [mediaType]: {...(ortb2Imp[mediaType] || {}), battr}};
adUnit.mediaTypes = {...mediaTypes, [mediaType]: {...(mediaTypes[mediaType] || {}), battr}};

if (battr !== undefined) {
deepSetValue(adUnit, `ortb2Imp.${mediaType}.battr`, battr);
deepSetValue(adUnit, `mediaTypes.${mediaType}.battr`, battr);
}
}

function validateBannerMediaType(adUnit) {
Expand Down
2 changes: 1 addition & 1 deletion test/spec/modules/dsp_genieeBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ describe('Geniee adapter tests', () => {
meta: {
advertiserDomains: ['geniee.co.jp'],
primaryCatId: 'IAB1',
secondaryCatIds: ['IAB1']
secondaryCatIds: []
},
netRevenue: true,
requestId: 'bid-id',
Expand Down
71 changes: 71 additions & 0 deletions test/spec/unit/pbjs_api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {generateUUID} from '../../../src/utils.js';
import {getCreativeRenderer} from '../../../src/creativeRenderers.js';
import {BID_STATUS, EVENTS, GRANULARITY_OPTIONS, PB_LOCATOR, TARGETING_KEYS} from 'src/constants.js';
import {getBidToRender} from '../../../src/adRendering.js';
import { setBattrForAdUnit } from '../../../src/prebid.js';

var assert = require('chai').assert;
var expect = require('chai').expect;
Expand Down Expand Up @@ -3768,4 +3769,74 @@ describe('Unit: Prebid Module', function () {
expect(auctionManager.getBidsReceived().length).to.equal(0);
});
});

describe('setBattrForAdUnit', () => {
it('should set copy battr to both places', () => {
const adUnit = {
ortb2Imp: {
video: {
battr: 'banned attribute'
}
},
mediaTypes: {
video: {}
}
}

setBattrForAdUnit(adUnit, 'video');

expect(adUnit.mediaTypes.video.battr).to.deep.equal('banned attribute');
expect(adUnit.ortb2Imp.video.battr).to.deep.equal('banned attribute');

const adUnit2 = {
mediaTypes: {
video: {
battr: 'banned attribute'
}
},
ortb2Imp: {
video: {}
}
}

setBattrForAdUnit(adUnit2, 'video');

expect(adUnit2.ortb2Imp.video.battr).to.deep.equal('banned attribute');
expect(adUnit2.mediaTypes.video.battr).to.deep.equal('banned attribute');
})

it('should log warn if both are specified and differ from eachother', () => {
let spyLogWarn = sinon.spy(utils, 'logWarn');
const adUnit = {
mediaTypes: {
native: {
battr: 'banned attribute'
}
},
ortb2Imp: {
native: {
battr: 'banned attribute 2'
}
}
}
setBattrForAdUnit(adUnit, 'native');
sinon.assert.calledOnce(spyLogWarn);
spyLogWarn.resetHistory();
utils.logWarn.restore();
})

it('should not copy for undefined battr', () => {
const adUnit = {
mediaTypes: {
native: {}
},
ortb2Imp: {
native: {}
}
}
setBattrForAdUnit(adUnit, 'native');
expect(adUnit.ortb2Imp.native).to.deep.equal({});
expect(adUnit.mediaTypes.native).to.deep.equal({});
})
})
});

0 comments on commit f90c448

Please sign in to comment.