Skip to content

Commit

Permalink
Add 'cur' to ORTB obj
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaac Dettman committed Jul 24, 2019
1 parent c2bdb94 commit 944383f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
12 changes: 12 additions & 0 deletions modules/prebidServerBidAdapter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
46 changes: 44 additions & 2 deletions test/spec/modules/prebidServerBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down

0 comments on commit 944383f

Please sign in to comment.