From 0c378417b4131ffa25d6d009a017f08fd4c4843d Mon Sep 17 00:00:00 2001 From: Jason Snellbaker Date: Wed, 4 Apr 2018 15:44:19 -0400 Subject: [PATCH 1/3] initial commit - send usePaymentRule info to pbs --- src/adaptermanager.js | 4 + test/spec/unit/core/adapterManager_spec.js | 85 +++++++++++++++++++++- 2 files changed, 88 insertions(+), 1 deletion(-) diff --git a/src/adaptermanager.js b/src/adaptermanager.js index cef1635f100..d1ee4bfce28 100644 --- a/src/adaptermanager.js +++ b/src/adaptermanager.js @@ -105,6 +105,10 @@ function getAdUnitCopyForPrebidServer(adUnits) { return includes(adaptersServerSide, bid.bidder) && (!doingS2STesting() || bid.finalSource !== s2sTestingModule.CLIENT); }).map((bid) => { bid.bid_id = utils.getUniqueIdentifierStr(); + if (bid.bidder === 'appnexus') { + bid.params.use_pmt_rule = (bid.params.usePaymentRule) ? bid.params.usePaymentRule : false; + if (bid.params.usePaymentRule) { delete bid.params.usePaymentRule; } + } return bid; }); }); diff --git a/test/spec/unit/core/adapterManager_spec.js b/test/spec/unit/core/adapterManager_spec.js index d11dfc02c4c..38d8e63ef17 100644 --- a/test/spec/unit/core/adapterManager_spec.js +++ b/test/spec/unit/core/adapterManager_spec.js @@ -851,7 +851,90 @@ describe('adapterManager tests', () => { expect(bidRequests[0].bids.length).to.equal(1); expect(bidRequests[0].bids[0].adUnitCode).to.equal(adUnits[1].code); }); - }) + }); + + describe('other checks', () => { + afterEach(() => { + config.resetConfig(); + }); + + it('checks payment rule field is set for s2s bidders', () => { + config.setConfig({ + s2sConfig: { + bidders: ['appnexus', 'rubicon'], + enabled: true + } + }); + + let adUnits = [{ + 'code': '/19968336/header-bid-tag1', + 'sizes': [[728, 90], [970, 90]], + 'bids': [ + { + 'bidder': 'appnexus', + 'params': { + 'placementId': '543221', + }, + + } + ] + }, { + 'code': '/19968336/header-bid-tag-0', + 'sizes': [[300, 250], [300, 600]], + 'bids': [ + { + 'bidder': 'appnexus', + 'params': { + 'placementId': '5324321', + 'usePaymentRule': true + }, + + }, { + 'bidder': 'rubicon', + 'params': { + 'accountId': '123456', + 'siteId': '345678', + 'zoneId': '234567', + 'userId': '12346', + 'keywords': ['a', 'b', 'c'], + 'inventory': { + 'rating': '5-star', + 'prodtype': 'tech' + }, + 'visitor': { + 'ucat': 'new', + 'search': 'iphone' + }, + 'sizes': [15, 10], + 'usePaymentRule': true + }, + + }, + ] + }]; + + let bidRequests = AdapterManager.makeBidRequests( + adUnits, + Date.now(), + utils.getUniqueIdentifierStr(), + function callback() {}, + [] + ); + + // checks for payment rule field + // if usePaymentRule was not present, use_pmt_rule will still be set automatically to false for appnexus bidder + expect(bidRequests[0].adUnitsS2SCopy[0].bids[0].params.use_pmt_rule).to.exist.and.to.be.false; + expect(bidRequests[0].adUnitsS2SCopy[0].bids[0].params.usePaymentRule).to.be.undefined; + + // if usePaymentRule was present, should be renamed to use_pmt_rule for appnexus bidder + expect(bidRequests[0].adUnitsS2SCopy[1].bids[0].params.use_pmt_rule).to.exist.and.to.be.true; + expect(bidRequests[0].adUnitsS2SCopy[1].bids[0].params.usePaymentRule).to.be.undefined; + + // should not be modified for non-appnexus bidders + expect(bidRequests[0].adUnitsS2SCopy[1].bids[1].params.use_pmt_rule).to.be.undefined; + expect(bidRequests[0].adUnitsS2SCopy[1].bids[1].params.usePaymentRule).to.exist.and.to.be.true; + }); + }); }); }); From 620f756355c5a5158617231aed173ebdbbf8b16b Mon Sep 17 00:00:00 2001 From: Jason Snellbaker Date: Tue, 17 Apr 2018 13:10:01 -0400 Subject: [PATCH 2/3] move code changes to pbs adapter --- modules/prebidServerBidAdapter.js | 3 + src/adaptermanager.js | 4 - .../modules/prebidServerBidAdapter_spec.js | 6 +- test/spec/unit/core/adapterManager_spec.js | 164 +++++++++--------- 4 files changed, 89 insertions(+), 88 deletions(-) diff --git a/modules/prebidServerBidAdapter.js b/modules/prebidServerBidAdapter.js index 8e1a5a07560..a7ad11babe7 100644 --- a/modules/prebidServerBidAdapter.js +++ b/modules/prebidServerBidAdapter.js @@ -472,6 +472,9 @@ const OPEN_RTB_PROTOCOL = { // TODO: move this bidder specific out to a more ideal location (submodule?); issue# pending // convert all AppNexus keys to underscore format for pbs if (bid.bidder === 'appnexus') { + bid.params.use_pmt_rule = (typeof bid.params.usePaymentRule === 'boolean') ? bid.params.usePaymentRule : false; + if (bid.params.usePaymentRule) { delete bid.params.usePaymentRule; } + Object.keys(bid.params).forEach(paramKey => { let convertedKey = utils.convertCamelToUnderscore(paramKey); if (convertedKey !== paramKey) { diff --git a/src/adaptermanager.js b/src/adaptermanager.js index d1ee4bfce28..cef1635f100 100644 --- a/src/adaptermanager.js +++ b/src/adaptermanager.js @@ -105,10 +105,6 @@ function getAdUnitCopyForPrebidServer(adUnits) { return includes(adaptersServerSide, bid.bidder) && (!doingS2STesting() || bid.finalSource !== s2sTestingModule.CLIENT); }).map((bid) => { bid.bid_id = utils.getUniqueIdentifierStr(); - if (bid.bidder === 'appnexus') { - bid.params.use_pmt_rule = (bid.params.usePaymentRule) ? bid.params.usePaymentRule : false; - if (bid.params.usePaymentRule) { delete bid.params.usePaymentRule; } - } return bid; }); }); diff --git a/test/spec/modules/prebidServerBidAdapter_spec.js b/test/spec/modules/prebidServerBidAdapter_spec.js index a1392989ad7..eef8a266b68 100644 --- a/test/spec/modules/prebidServerBidAdapter_spec.js +++ b/test/spec/modules/prebidServerBidAdapter_spec.js @@ -551,19 +551,21 @@ describe('S2S Adapter', () => { }); }); - it('converts appnexus params to underscore syntax', () => { + it('converts appnexus params to expected format for PBS', () => { const s2sConfig = Object.assign({}, CONFIG, { endpoint: 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction' }); config.setConfig({s2sConfig}); const myRequest = utils.deepClone(REQUEST); + myRequest.ad_units[0].bids[0].params.usePaymentRule = true; - adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax); + adapter.callBids(myRequest, BID_REQUESTS, addBidResponse, done, ajax); const requestBid = JSON.parse(requests[0].requestBody); expect(requestBid.imp[0].ext.appnexus).to.exist; expect(requestBid.imp[0].ext.appnexus.placement_id).to.exist.and.to.equal(10433394); + expect(requestBid.imp[0].ext.appnexus.use_pmt_rule).to.exist.and.to.be.true; expect(requestBid.imp[0].ext.appnexus.member).to.exist; }); }); diff --git a/test/spec/unit/core/adapterManager_spec.js b/test/spec/unit/core/adapterManager_spec.js index 38d8e63ef17..a832a245d60 100644 --- a/test/spec/unit/core/adapterManager_spec.js +++ b/test/spec/unit/core/adapterManager_spec.js @@ -853,88 +853,88 @@ describe('adapterManager tests', () => { }); }); - describe('other checks', () => { - afterEach(() => { - config.resetConfig(); - }); - - it('checks payment rule field is set for s2s bidders', () => { - config.setConfig({ - s2sConfig: { - bidders: ['appnexus', 'rubicon'], - enabled: true - } - }); - - let adUnits = [{ - 'code': '/19968336/header-bid-tag1', - 'sizes': [[728, 90], [970, 90]], - 'bids': [ - { - 'bidder': 'appnexus', - 'params': { - 'placementId': '543221', - }, - - } - ] - }, { - 'code': '/19968336/header-bid-tag-0', - 'sizes': [[300, 250], [300, 600]], - 'bids': [ - { - 'bidder': 'appnexus', - 'params': { - 'placementId': '5324321', - 'usePaymentRule': true - }, - - }, { - 'bidder': 'rubicon', - 'params': { - 'accountId': '123456', - 'siteId': '345678', - 'zoneId': '234567', - 'userId': '12346', - 'keywords': ['a', 'b', 'c'], - 'inventory': { - 'rating': '5-star', - 'prodtype': 'tech' - }, - 'visitor': { - 'ucat': 'new', - 'search': 'iphone' - }, - 'sizes': [15, 10], - 'usePaymentRule': true - }, - - }, - ] - }]; - - let bidRequests = AdapterManager.makeBidRequests( - adUnits, - Date.now(), - utils.getUniqueIdentifierStr(), - function callback() {}, - [] - ); - - // checks for payment rule field - // if usePaymentRule was not present, use_pmt_rule will still be set automatically to false for appnexus bidder - expect(bidRequests[0].adUnitsS2SCopy[0].bids[0].params.use_pmt_rule).to.exist.and.to.be.false; - expect(bidRequests[0].adUnitsS2SCopy[0].bids[0].params.usePaymentRule).to.be.undefined; - - // if usePaymentRule was present, should be renamed to use_pmt_rule for appnexus bidder - expect(bidRequests[0].adUnitsS2SCopy[1].bids[0].params.use_pmt_rule).to.exist.and.to.be.true; - expect(bidRequests[0].adUnitsS2SCopy[1].bids[0].params.usePaymentRule).to.be.undefined; - - // should not be modified for non-appnexus bidders - expect(bidRequests[0].adUnitsS2SCopy[1].bids[1].params.use_pmt_rule).to.be.undefined; - expect(bidRequests[0].adUnitsS2SCopy[1].bids[1].params.usePaymentRule).to.exist.and.to.be.true; - }); - }); + // describe('other checks', () => { + // afterEach(() => { + // config.resetConfig(); + // }); + + // it('checks payment rule field is set for s2s bidders', () => { + // config.setConfig({ + // s2sConfig: { + // bidders: ['appnexus', 'rubicon'], + // enabled: true + // } + // }); + + // let adUnits = [{ + // 'code': '/19968336/header-bid-tag1', + // 'sizes': [[728, 90], [970, 90]], + // 'bids': [ + // { + // 'bidder': 'appnexus', + // 'params': { + // 'placementId': '543221', + // }, + + // } + // ] + // }, { + // 'code': '/19968336/header-bid-tag-0', + // 'sizes': [[300, 250], [300, 600]], + // 'bids': [ + // { + // 'bidder': 'appnexus', + // 'params': { + // 'placementId': '5324321', + // 'usePaymentRule': true + // }, + + // }, { + // 'bidder': 'rubicon', + // 'params': { + // 'accountId': '123456', + // 'siteId': '345678', + // 'zoneId': '234567', + // 'userId': '12346', + // 'keywords': ['a', 'b', 'c'], + // 'inventory': { + // 'rating': '5-star', + // 'prodtype': 'tech' + // }, + // 'visitor': { + // 'ucat': 'new', + // 'search': 'iphone' + // }, + // 'sizes': [15, 10], + // 'usePaymentRule': true + // }, + + // }, + // ] + // }]; + + // let bidRequests = AdapterManager.makeBidRequests( + // adUnits, + // Date.now(), + // utils.getUniqueIdentifierStr(), + // function callback() {}, + // [] + // ); + + // // checks for payment rule field + // // if usePaymentRule was not present, use_pmt_rule will still be set automatically to false for appnexus bidder + // expect(bidRequests[0].adUnitsS2SCopy[0].bids[0].params.use_pmt_rule).to.exist.and.to.be.false; + // expect(bidRequests[0].adUnitsS2SCopy[0].bids[0].params.usePaymentRule).to.be.undefined; + + // // if usePaymentRule was present, should be renamed to use_pmt_rule for appnexus bidder + // expect(bidRequests[0].adUnitsS2SCopy[1].bids[0].params.use_pmt_rule).to.exist.and.to.be.true; + // expect(bidRequests[0].adUnitsS2SCopy[1].bids[0].params.usePaymentRule).to.be.undefined; + + // // should not be modified for non-appnexus bidders + // expect(bidRequests[0].adUnitsS2SCopy[1].bids[1].params.use_pmt_rule).to.be.undefined; + // expect(bidRequests[0].adUnitsS2SCopy[1].bids[1].params.usePaymentRule).to.exist.and.to.be.true; + // }); + // }); }); }); From c64d8b9e034e5de1c0acfc766f80413a9cb8fa15 Mon Sep 17 00:00:00 2001 From: Jason Snellbaker Date: Tue, 17 Apr 2018 13:19:11 -0400 Subject: [PATCH 3/3] removed commented unit test --- test/spec/unit/core/adapterManager_spec.js | 83 ---------------------- 1 file changed, 83 deletions(-) diff --git a/test/spec/unit/core/adapterManager_spec.js b/test/spec/unit/core/adapterManager_spec.js index a832a245d60..39e468d4959 100644 --- a/test/spec/unit/core/adapterManager_spec.js +++ b/test/spec/unit/core/adapterManager_spec.js @@ -852,89 +852,6 @@ describe('adapterManager tests', () => { expect(bidRequests[0].bids[0].adUnitCode).to.equal(adUnits[1].code); }); }); - - // describe('other checks', () => { - // afterEach(() => { - // config.resetConfig(); - // }); - - // it('checks payment rule field is set for s2s bidders', () => { - // config.setConfig({ - // s2sConfig: { - // bidders: ['appnexus', 'rubicon'], - // enabled: true - // } - // }); - - // let adUnits = [{ - // 'code': '/19968336/header-bid-tag1', - // 'sizes': [[728, 90], [970, 90]], - // 'bids': [ - // { - // 'bidder': 'appnexus', - // 'params': { - // 'placementId': '543221', - // }, - - // } - // ] - // }, { - // 'code': '/19968336/header-bid-tag-0', - // 'sizes': [[300, 250], [300, 600]], - // 'bids': [ - // { - // 'bidder': 'appnexus', - // 'params': { - // 'placementId': '5324321', - // 'usePaymentRule': true - // }, - - // }, { - // 'bidder': 'rubicon', - // 'params': { - // 'accountId': '123456', - // 'siteId': '345678', - // 'zoneId': '234567', - // 'userId': '12346', - // 'keywords': ['a', 'b', 'c'], - // 'inventory': { - // 'rating': '5-star', - // 'prodtype': 'tech' - // }, - // 'visitor': { - // 'ucat': 'new', - // 'search': 'iphone' - // }, - // 'sizes': [15, 10], - // 'usePaymentRule': true - // }, - - // }, - // ] - // }]; - - // let bidRequests = AdapterManager.makeBidRequests( - // adUnits, - // Date.now(), - // utils.getUniqueIdentifierStr(), - // function callback() {}, - // [] - // ); - - // // checks for payment rule field - // // if usePaymentRule was not present, use_pmt_rule will still be set automatically to false for appnexus bidder - // expect(bidRequests[0].adUnitsS2SCopy[0].bids[0].params.use_pmt_rule).to.exist.and.to.be.false; - // expect(bidRequests[0].adUnitsS2SCopy[0].bids[0].params.usePaymentRule).to.be.undefined; - - // // if usePaymentRule was present, should be renamed to use_pmt_rule for appnexus bidder - // expect(bidRequests[0].adUnitsS2SCopy[1].bids[0].params.use_pmt_rule).to.exist.and.to.be.true; - // expect(bidRequests[0].adUnitsS2SCopy[1].bids[0].params.usePaymentRule).to.be.undefined; - - // // should not be modified for non-appnexus bidders - // expect(bidRequests[0].adUnitsS2SCopy[1].bids[1].params.use_pmt_rule).to.be.undefined; - // expect(bidRequests[0].adUnitsS2SCopy[1].bids[1].params.usePaymentRule).to.exist.and.to.be.true; - // }); - // }); }); });