From 944383f10ba217d4ca25d5e736a38297013cc865 Mon Sep 17 00:00:00 2001 From: Isaac Dettman Date: Wed, 24 Jul 2019 03:49:18 -0700 Subject: [PATCH 1/3] 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..c3d541d5f3c 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, copy the first element + request.cur = adServerCur.slice(0, 1); + } + _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, { From 9691e12b068c65874dee496f81219026ccc35912 Mon Sep 17 00:00:00 2001 From: "Isaac A. Dettman" Date: Thu, 25 Jul 2019 13:51:02 -0700 Subject: [PATCH 2/3] update array slice to use direct array access --- modules/prebidServerBidAdapter/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/prebidServerBidAdapter/index.js b/modules/prebidServerBidAdapter/index.js index c3d541d5f3c..3b49296e61a 100644 --- a/modules/prebidServerBidAdapter/index.js +++ b/modules/prebidServerBidAdapter/index.js @@ -541,8 +541,8 @@ const OPEN_RTB_PROTOCOL = { // 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, copy the first element - request.cur = adServerCur.slice(0, 1); + // if it's an array, get the first element + request.cur = adServerCur[0]; } _appendSiteAppDevice(request); From dda2ac96f7e07124f976ae631da49f2152a36e29 Mon Sep 17 00:00:00 2001 From: "Isaac A. Dettman" Date: Thu, 25 Jul 2019 14:01:58 -0700 Subject: [PATCH 3/3] update wrap value from array item access in array --- modules/prebidServerBidAdapter/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/prebidServerBidAdapter/index.js b/modules/prebidServerBidAdapter/index.js index 3b49296e61a..582b12e59d7 100644 --- a/modules/prebidServerBidAdapter/index.js +++ b/modules/prebidServerBidAdapter/index.js @@ -542,7 +542,7 @@ const OPEN_RTB_PROTOCOL = { request.cur = [adServerCur]; } else if (Array.isArray(adServerCur) && adServerCur.length) { // if it's an array, get the first element - request.cur = adServerCur[0]; + request.cur = [adServerCur[0]]; } _appendSiteAppDevice(request);