From 9237713b48ac50f34486df9c102b3e6b982e3dd5 Mon Sep 17 00:00:00 2001 From: Nepomuk Seiler Date: Tue, 6 Apr 2021 15:10:14 +0200 Subject: [PATCH] Spread adUnit.ortb2Imp.ext into imp object --- modules/prebidServerBidAdapter/index.js | 10 +++++-- .../modules/prebidServerBidAdapter_spec.js | 26 +++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/modules/prebidServerBidAdapter/index.js b/modules/prebidServerBidAdapter/index.js index ff326f25840..805efe5bd93 100644 --- a/modules/prebidServerBidAdapter/index.js +++ b/modules/prebidServerBidAdapter/index.js @@ -604,6 +604,7 @@ const OPEN_RTB_PROTOCOL = { } // get bidder params in form { : {...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) { @@ -611,7 +612,7 @@ const OPEN_RTB_PROTOCOL = { } 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 }; @@ -622,7 +623,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 diff --git a/test/spec/modules/prebidServerBidAdapter_spec.js b/test/spec/modules/prebidServerBidAdapter_spec.js index 937d67677d9..619c870659c 100644 --- a/test/spec/modules/prebidServerBidAdapter_spec.js +++ b/test/spec/modules/prebidServerBidAdapter_spec.js @@ -1814,6 +1814,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');