Skip to content

Commit

Permalink
add bidderDefaultFunction (prebid#7628)
Browse files Browse the repository at this point in the history
  • Loading branch information
eknis authored and Chris Pabst committed Jan 10, 2022
1 parent 1c1ed18 commit ef5d3e2
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
31 changes: 31 additions & 0 deletions modules/imRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,34 @@ function setImDataInCookie(value) {
);
}

/**
* @param {string} bidderName
*/
export function getBidderFunction(bidderName) {
const biddersFunction = {
ix: function (bid, data) {
if (data.im_segments && data.im_segments.length) {
config.setConfig({
ix: {firstPartyData: {im_segments: data.im_segments}},
});
}
return bid
},
pubmatic: function (bid, data) {
if (data.im_segments && data.im_segments.length) {
const dctr = deepAccess(bid, 'params.dctr');
deepSetValue(
bid,
'params.dctr',
`${dctr ? dctr + '|' : ''}im_segments=${data.im_segments.join(',')}`
);
}
return bid
}
}
return biddersFunction[bidderName] || null;
}

export function getCustomBidderFunction(config, bidder) {
const overwriteFn = deepAccess(config, `params.overwrites.${bidder}`)

Expand Down Expand Up @@ -73,9 +101,12 @@ export function setRealTimeData(bidConfig, moduleConfig, data) {

adUnits.forEach(adUnit => {
adUnit.bids.forEach(bid => {
const bidderFunction = getBidderFunction(bid.bidder);
const overwriteFunction = getCustomBidderFunction(moduleConfig, bid.bidder);
if (overwriteFunction) {
overwriteFunction(bid, data, utils, config);
} else if (bidderFunction) {
bidderFunction(bid, data);
}
})
});
Expand Down
25 changes: 25 additions & 0 deletions test/spec/modules/imRtdProvider_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
imRtdSubmodule,
storage,
getBidderFunction,
getCustomBidderFunction,
setRealTimeData,
getRealTimeData,
Expand Down Expand Up @@ -47,6 +48,30 @@ describe('imRtdProvider', function () {
})
})

describe('getBidderFunction', function () {
const assumedBidder = [
'ix',
'pubmatic'
];
assumedBidder.forEach(bidderName => {
it(`should return bidderFunction with assumed bidder: ${bidderName}`, function () {
expect(getBidderFunction(bidderName)).to.exist.and.to.be.a('function');
});

it(`should return bid with correct key data: ${bidderName}`, function () {
const bid = {bidder: bidderName};
expect(getBidderFunction(bidderName)(bid, {'im_segments': ['12345', '67890']})).to.equal(bid);
});
it(`should return bid without data: ${bidderName}`, function () {
const bid = {bidder: bidderName};
expect(getBidderFunction(bidderName)(bid, '')).to.equal(bid);
});
});
it(`should return null with unexpected bidder`, function () {
expect(getBidderFunction('test')).to.equal(null);
});
})

describe('getCustomBidderFunction', function () {
it('should return config function', function () {
const config = {
Expand Down

0 comments on commit ef5d3e2

Please sign in to comment.