From b6eac4259d8942d85fdbe008c5e72370334fc5a6 Mon Sep 17 00:00:00 2001 From: Yevhenii Tykhostup Date: Thu, 3 Sep 2020 09:14:18 +0300 Subject: [PATCH] Move test and piblisherId parameters to bidder specific config --- modules/apstreamBidAdapter.js | 19 ++++++++++------- modules/apstreamBidAdapter.md | 14 +++++++++++++ test/spec/modules/apstreamBidAdapter_spec.js | 22 ++++++++++++++++++++ 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/modules/apstreamBidAdapter.js b/modules/apstreamBidAdapter.js index 324c125f5ef..4fb89b9c720 100644 --- a/modules/apstreamBidAdapter.js +++ b/modules/apstreamBidAdapter.js @@ -378,23 +378,27 @@ function getBids(bids) { function getEndpointsGroups(bidRequests) { let endpoints = []; const getEndpoint = bid => { - if (bid.params.test) { - return `https://mock-bapi.userreport.com/v2/${bid.params.publisherId}/bid`; + const publisherId = bid.params.publisherId || config.getConfig('apstream.publisherId'); + const isTestConfig = bid.params.test || config.getConfig('apstream.test'); + + if (isTestConfig) { + return `https://mock-bapi.userreport.com/v2/${publisherId}/bid`; } if (bid.params.endpoint) { - return `${bid.params.endpoint}${bid.params.publisherId}/bid`; + return `${bid.params.endpoint}${publisherId}/bid`; } - return `https://bapi.userreport.com/v2/${bid.params.publisherId}/bid`; + return `https://bapi.userreport.com/v2/${publisherId}/bid`; } bidRequests.forEach(bid => { - const exist = endpoints.filter(item => item.endpoint.indexOf(bid.params.endpoint) > -1)[0]; + const endpoint = getEndpoint(bid); + const exist = endpoints.filter(item => item.endpoint.indexOf(endpoint) > -1)[0]; if (exist) { exist.bids.push(bid); } else { endpoints.push({ - endpoint: getEndpoint(bid), + endpoint: endpoint, bids: [bid] }); } @@ -404,7 +408,8 @@ function getEndpointsGroups(bidRequests) { } function isBidRequestValid(bid) { - const isPublisherIdExist = !!bid.params.publisherId; + const publisherId = config.getConfig('apstream.publisherId'); + const isPublisherIdExist = !!(publisherId || bid.params.publisherId); const isOneMediaType = Object.keys(bid.mediaTypes).length === 1; return isPublisherIdExist && isOneMediaType; diff --git a/modules/apstreamBidAdapter.md b/modules/apstreamBidAdapter.md index e528307a003..6b87b33489a 100644 --- a/modules/apstreamBidAdapter.md +++ b/modules/apstreamBidAdapter.md @@ -95,3 +95,17 @@ To disable DSU use config option: } }); ``` + +To set `test` and `publisherId` parameters globally use config options (it can be overrided if set in specific bid): + +``` +pbjs.setBidderConfig({ + bidders: ["apstream"], + config: { + appstream: { + publisherId: '1234 + test: true + } + } +}); +``` diff --git a/test/spec/modules/apstreamBidAdapter_spec.js b/test/spec/modules/apstreamBidAdapter_spec.js index c6546a3bd83..e640c009989 100644 --- a/test/spec/modules/apstreamBidAdapter_spec.js +++ b/test/spec/modules/apstreamBidAdapter_spec.js @@ -31,6 +31,22 @@ describe('AP Stream adapter', function() { } }; + let mockConfig; + beforeEach(function () { + mockConfig = { + apstream: { + publisherId: '4321' + } + }; + sinon.stub(config, 'getConfig').callsFake((key) => { + return utils.deepAccess(mockConfig, key); + }); + }); + + afterEach(function () { + config.getConfig.restore(); + }); + it('should return true when publisherId is configured and one media type', function() { bid.params.publisherId = '1234'; assert(spec.isBidRequestValid(bid)) @@ -40,6 +56,12 @@ describe('AP Stream adapter', function() { bid.mediaTypes.video = {sizes: [300, 250]}; assert.isFalse(spec.isBidRequestValid(bid)) }); + + it('should return true when publisherId is configured via config', function() { + delete bid.mediaTypes.video; + delete bid.params.publisherId; + assert.isTrue(spec.isBidRequestValid(bid)) + }); }); describe('buildRequests', function() {