Skip to content

Commit

Permalink
pbsBidAdapter currency fix for legacy branch (prebid#4642)
Browse files Browse the repository at this point in the history
* pbsBidAdapter currency fix for legacy branch

* fixed unit tests
  • Loading branch information
bretg authored and Isaac A. Dettman committed Dec 18, 2019
1 parent 094d921 commit bc1f991
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
4 changes: 2 additions & 2 deletions modules/prebidServerBidAdapter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -935,10 +935,10 @@ const OPEN_RTB_PROTOCOL = {
bidObject.creative_id = bid.crid;
bidObject.creativeId = bid.crid;
if (bid.burl) { bidObject.burl = bid.burl; }
bidObject.currency = (response.cur) ? response.cur : DEFAULT_S2S_CURRENCY;

// TODO: Remove when prebid-server returns ttl, currency and netRevenue
// TODO: Remove when prebid-server returns ttl and netRevenue
bidObject.ttl = (bid.ttl) ? bid.ttl : DEFAULT_S2S_TTL;
bidObject.currency = (bid.currency) ? bid.currency : DEFAULT_S2S_CURRENCY;
bidObject.netRevenue = (bid.netRevenue) ? bid.netRevenue : DEFAULT_S2S_NETREVENUE;

bids.push({ adUnit: bid.impid, bid: bidObject });
Expand Down
28 changes: 27 additions & 1 deletion test/spec/modules/prebidServerBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ const RESPONSE_OPENRTB = {
'seat': 'appnexus'
},
],
'cur': 'EUR',
'ext': {
'responsetimemillis': {
'appnexus': 8,
Expand Down Expand Up @@ -1544,9 +1545,34 @@ describe('S2S Adapter', function () {
expect(response).to.have.property('dealId', 'test-dealid');
});

it('should set the bidResponse currency to whats in the PBS response', function() {
server.respondWith(JSON.stringify(RESPONSE_OPENRTB));
let ortb2Config = utils.deepClone(CONFIG);
ortb2Config.endpoint = 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction';
config.setConfig({ s2sConfig: ortb2Config });
adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax);
server.respond();
sinon.assert.calledOnce(addBidResponse);
const pbjsResponse = addBidResponse.firstCall.args[1];
expect(pbjsResponse).to.have.property('currency', 'EUR');
});

it('should set the default bidResponse currency when not specified in OpenRTB', function() {
let modifiedResponse = utils.deepClone(RESPONSE_OPENRTB);
modifiedResponse.cur = '';
let ortb2Config = utils.deepClone(CONFIG);
ortb2Config.endpoint = 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction';
config.setConfig({ s2sConfig: ortb2Config });
server.respondWith(JSON.stringify(modifiedResponse));
adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax);
server.respond();
sinon.assert.calledOnce(addBidResponse);
const pbjsResponse = addBidResponse.firstCall.args[1];
expect(pbjsResponse).to.have.property('currency', 'USD');
});

it('should pass through default adserverTargeting if present in bidObject', function () {
server.respondWith(JSON.stringify(RESPONSE));

config.setConfig({ s2sConfig: CONFIG });
adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax);
server.respond();
Expand Down

0 comments on commit bc1f991

Please sign in to comment.