Skip to content

Commit

Permalink
Spread adUnit.ortb2Imp.ext into imp object (prebid#6494)
Browse files Browse the repository at this point in the history
  • Loading branch information
muuki88 authored Apr 29, 2021
1 parent c21ad7e commit d9a7801
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
10 changes: 8 additions & 2 deletions modules/prebidServerBidAdapter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -625,14 +625,15 @@ const OPEN_RTB_PROTOCOL = {
}

// get bidder params in form { <bidder code>: {...params} }
// initialize reduce function with the user defined `ext` properties on the ad unit
const ext = adUnit.bids.reduce((acc, bid) => {
const adapter = adapterManager.bidderRegistry[bid.bidder];
if (adapter && adapter.getSpec().transformBidParams) {
bid.params = adapter.getSpec().transformBidParams(bid.params, true);
}
acc[bid.bidder] = (s2sConfig.adapterOptions && s2sConfig.adapterOptions[bid.bidder]) ? Object.assign({}, bid.params, s2sConfig.adapterOptions[bid.bidder]) : bid.params;
return acc;
}, {});
}, {...utils.deepAccess(adUnit, 'ortb2Imp.ext')});

const imp = { id: adUnit.code, ext, secure: s2sConfig.secure };

Expand All @@ -643,7 +644,12 @@ const OPEN_RTB_PROTOCOL = {
* @type {(string|undefined)}
*/
if (prop === 'pbadslot') {
if (typeof ortb2[prop] === 'string' && ortb2[prop]) utils.deepSetValue(imp, 'ext.data.pbadslot', ortb2[prop]);
if (typeof ortb2[prop] === 'string' && ortb2[prop]) {
utils.deepSetValue(imp, 'ext.data.pbadslot', ortb2[prop]);
} else {
// remove pbadslot property if it doesn't meet the spec
delete imp.ext.data.pbadslot;
}
} else if (prop === 'adserver') {
/**
* Copy GAM AdUnit and Name to imp
Expand Down
26 changes: 26 additions & 0 deletions test/spec/modules/prebidServerBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1825,6 +1825,32 @@ describe('S2S Adapter', function () {
});
});

describe('ext.prebid config', function () {
it('should send \"imp.ext.prebid.storedrequest.id\" if \"ortb2Imp.ext.prebid.storedrequest.id\" is set', function () {
const consentConfig = { s2sConfig: CONFIG };
config.setConfig(consentConfig);
const bidRequest = utils.deepClone(REQUEST);
const storedRequestId = 'my-id';
bidRequest.ad_units[0].ortb2Imp = {
ext: {
prebid: {
storedrequest: {
id: storedRequestId
}
}
}
};

adapter.callBids(bidRequest, BID_REQUESTS, addBidResponse, done, ajax);
const parsedRequestBody = JSON.parse(server.requests[0].requestBody);

expect(parsedRequestBody.imp).to.be.a('array');
expect(parsedRequestBody.imp[0]).to.be.a('object');
expect(parsedRequestBody.imp[0]).to.have.deep.nested.property('ext.prebid.storedrequest.id');
expect(parsedRequestBody.imp[0].ext.prebid.storedrequest.id).to.equal(storedRequestId);
});
});

describe('response handler', function () {
beforeEach(function () {
sinon.stub(utils, 'triggerPixel');
Expand Down

0 comments on commit d9a7801

Please sign in to comment.