Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move test and publisherId parameters to bidder specific config #5692

Merged
merged 1 commit into from
Sep 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions modules/apstreamBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
});
}
Expand All @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions modules/apstreamBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
});
```
22 changes: 22 additions & 0 deletions test/spec/modules/apstreamBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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() {
Expand Down