From 04a9fd399c0a7c069b909b60ae12604b44a266ed Mon Sep 17 00:00:00 2001 From: "Isaac A. Dettman" Date: Thu, 25 Jul 2019 14:27:09 -0700 Subject: [PATCH] Add oRTB cur to PrebidServer Adapter (#3951) * Add 'cur' to ORTB obj --- modules/prebidServerBidAdapter/index.js | 12 +++++ .../modules/prebidServerBidAdapter_spec.js | 46 ++++++++++++++++++- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/modules/prebidServerBidAdapter/index.js b/modules/prebidServerBidAdapter/index.js index e857bf1d665..582b12e59d7 100644 --- a/modules/prebidServerBidAdapter/index.js +++ b/modules/prebidServerBidAdapter/index.js @@ -533,6 +533,18 @@ const OPEN_RTB_PROTOCOL = { request.ext.prebid = Object.assign(request.ext.prebid, _s2sConfig.extPrebid); } + /** + * @type {(string[]|string|undefined)} - OpenRTB property 'cur', currencies available for bids + */ + const adServerCur = config.getConfig('currency.adServerCurrency'); + if (adServerCur && typeof adServerCur === 'string') { + // if the value is a string, wrap it with an array + request.cur = [adServerCur]; + } else if (Array.isArray(adServerCur) && adServerCur.length) { + // if it's an array, get the first element + request.cur = [adServerCur[0]]; + } + _appendSiteAppDevice(request); const digiTrust = _getDigiTrustQueryParams(bidRequests && bidRequests[0]); diff --git a/test/spec/modules/prebidServerBidAdapter_spec.js b/test/spec/modules/prebidServerBidAdapter_spec.js index 9562b2f4c07..8b077ca796a 100644 --- a/test/spec/modules/prebidServerBidAdapter_spec.js +++ b/test/spec/modules/prebidServerBidAdapter_spec.js @@ -904,9 +904,51 @@ describe('S2S Adapter', function () { expect(Array.isArray(requestBid.user.ext.eids)).to.be.true; expect(requestBid.user.ext.eids.filter(eid => eid.source === 'adserver.org')).is.not.empty; expect(requestBid.user.ext.eids.filter(eid => eid.source === 'adserver.org')[0].uids[0].id).is.equal('abc123'); - expect(requestBid.user.ext.eids.filter(eid => eid.source === 'pubcommon')).is.not.empty; ; + expect(requestBid.user.ext.eids.filter(eid => eid.source === 'pubcommon')).is.not.empty; expect(requestBid.user.ext.eids.filter(eid => eid.source === 'pubcommon')[0].uids[0].id).is.equal('1234'); - }) + }); + + it('when config \'currency.adServerCurrency\' value is an array: ORTB has property \'cur\' value set to a single item array', function () { + let s2sConfig = utils.deepClone(CONFIG); + s2sConfig.endpoint = 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction'; + config.setConfig({ + currency: {adServerCurrency: ['USD', 'GB', 'UK', 'AU']}, + s2sConfig: s2sConfig + }); + + const bidRequests = utils.deepClone(BID_REQUESTS); + adapter.callBids(REQUEST, bidRequests, addBidResponse, done, ajax); + + const parsedRequestBody = JSON.parse(requests[0].requestBody); + expect(parsedRequestBody.cur).to.deep.equal(['USD']); + }); + + it('when config \'currency.adServerCurrency\' value is a string: ORTB has property \'cur\' value set to a single item array', function () { + let s2sConfig = utils.deepClone(CONFIG); + s2sConfig.endpoint = 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction'; + config.setConfig({ + currency: {adServerCurrency: 'NZ'}, + s2sConfig: s2sConfig + }); + + const bidRequests = utils.deepClone(BID_REQUESTS); + adapter.callBids(REQUEST, bidRequests, addBidResponse, done, ajax); + + const parsedRequestBody = JSON.parse(requests[1].requestBody); + expect(parsedRequestBody.cur).to.deep.equal(['NZ']); + }); + + it('when config \'currency.adServerCurrency\' is unset: ORTB should not define a \'cur\' property', function () { + let s2sConfig = utils.deepClone(CONFIG); + s2sConfig.endpoint = 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction'; + config.setConfig({s2sConfig: s2sConfig}); + + const bidRequests = utils.deepClone(BID_REQUESTS); + adapter.callBids(REQUEST, bidRequests, addBidResponse, done, ajax); + + const parsedRequestBody = JSON.parse(requests[0].requestBody); + expect(typeof parsedRequestBody.cur).to.equal('undefined'); + }); it('always add ext.prebid.targeting.includebidderkeys: false for ORTB', function () { const s2sConfig = Object.assign({}, CONFIG, {