Skip to content

Commit

Permalink
PubMatic Bid Adapter: Sending allowedAlternateBidderCodes data to AdS…
Browse files Browse the repository at this point in the history
…erver (prebid#8790)

* Changed net revenue to True

* Added bidderCode and adapterCode to bidObject

* setting seat as default adapterCode

* removed bidderCode

* Added unit test cases

* cloned the test object

* send alternateBidderCodes to adserver

* handled blank and duplicate entries

* added test cases

* Handled case for empty biddersArray

Co-authored-by: Azhar <azhar@L1119.local>
  • Loading branch information
2 people authored and jorgeluisrocha committed May 18, 2023
1 parent cb343c4 commit e081666
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 4 deletions.
21 changes: 17 additions & 4 deletions modules/pubmaticBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { logWarn, _each, isBoolean, isStr, isArray, inIframe, mergeDeep, deepAccess, isNumber, deepSetValue, logInfo, logError, deepClone, convertTypes } from '../src/utils.js';
import { logWarn, _each, isBoolean, isStr, isArray, inIframe, mergeDeep, deepAccess, isNumber, deepSetValue, logInfo, logError, deepClone, convertTypes, uniques } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, VIDEO, NATIVE } from '../src/mediaTypes.js';
import {config} from '../src/config.js';
Expand Down Expand Up @@ -177,6 +177,8 @@ let publisherId = 0;
let isInvalidNativeRequest = false;
let NATIVE_ASSET_ID_TO_KEY_MAP = {};
let NATIVE_ASSET_KEY_TO_ASSET_MAP = {};
let biddersList = ['pubmatic'];
const allBiddersList = ['all'];

// loading NATIVE_ASSET_ID_TO_KEY_MAP
_each(NATIVE_ASSETS, anAsset => { NATIVE_ASSET_ID_TO_KEY_MAP[anAsset.ID] = anAsset.KEY });
Expand Down Expand Up @@ -1089,10 +1091,21 @@ export const spec = {
payload.ext.wrapper.wv = $$REPO_AND_VERSION$$;
payload.ext.wrapper.transactionId = conf.transactionId;
payload.ext.wrapper.wp = 'pbjs';
if (bidderRequest && bidderRequest.bidderCode) {
payload.ext.allowAlternateBidderCodes = bidderSettings.get(bidderRequest.bidderCode, 'allowAlternateBidderCodes');
payload.ext.allowedAlternateBidderCodes = bidderSettings.get(bidderRequest.bidderCode, 'allowedAlternateBidderCodes');
const allowAlternateBidder = bidderRequest ? bidderSettings.get(bidderRequest.bidderCode, 'allowAlternateBidderCodes') : undefined;
if (allowAlternateBidder !== undefined) {
payload.ext.marketplace = {};
if (bidderRequest && allowAlternateBidder == true) {
let allowedBiddersList = bidderSettings.get(bidderRequest.bidderCode, 'allowedAlternateBidderCodes');
if (isArray(allowedBiddersList)) {
allowedBiddersList = allowedBiddersList.map(val => val.trim().toLowerCase()).filter(val => !!val).filter(uniques)
biddersList = allowedBiddersList.includes('*') ? allBiddersList : [...biddersList, ...allowedBiddersList];
} else {
biddersList = allBiddersList;
}
}
payload.ext.marketplace.allowedbidders = biddersList.filter(uniques);
}

payload.user.gender = (conf.gender ? conf.gender.trim() : UNDEFINED);
payload.user.geo = {};
payload.user.geo.lat = _parseSlotParam('lat', conf.lat);
Expand Down
57 changes: 57 additions & 0 deletions test/spec/modules/pubmaticBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {spec, checkVideoPlacement} from 'modules/pubmaticBidAdapter.js';
import * as utils from 'src/utils.js';
import {config} from 'src/config.js';
import { createEidsArray } from 'modules/userId/eids.js';
import { bidderSettings } from 'src/bidderSettings.js';
const constants = require('src/constants.json');

describe('PubMatic adapter', function () {
Expand Down Expand Up @@ -1104,6 +1105,62 @@ describe('PubMatic adapter', function () {
expect(data.source.ext.schain).to.deep.equal(bidRequests[0].schain);
});

describe('Marketplace parameters', function() {
let bidderSettingStub;
beforeEach(function() {
bidderSettingStub = sinon.stub(bidderSettings, 'get');
});

afterEach(function() {
bidderSettingStub.restore();
});

it('should not be present when allowAlternateBidderCodes is undefined', function () {
bidderSettingStub.returns(undefined);
let request = spec.buildRequests(bidRequests, {
auctionId: 'new-auction-id'
});
let data = JSON.parse(request.data);
expect(data.ext.marketplace).to.equal(undefined);
});

it('should be pubmatic and groupm when allowedAlternateBidderCodes is \'groupm\'', function () {
bidderSettingStub.withArgs('pubmatic', 'allowAlternateBidderCodes').returns(true);
bidderSettingStub.withArgs('pubmatic', 'allowedAlternateBidderCodes').returns(['groupm']);
let request = spec.buildRequests(bidRequests, {
auctionId: 'new-auction-id',
bidderCode: 'pubmatic'
});
let data = JSON.parse(request.data);
expect(data.ext.marketplace.allowedbidders).to.be.an('array');
expect(data.ext.marketplace.allowedbidders.length).to.equal(2);
expect(data.ext.marketplace.allowedbidders[0]).to.equal('pubmatic');
expect(data.ext.marketplace.allowedbidders[1]).to.equal('groupm');
});

it('should be ALL by default', function () {
bidderSettingStub.returns(true);
let request = spec.buildRequests(bidRequests, {
auctionId: 'new-auction-id'
});
let data = JSON.parse(request.data);
expect(data.ext.marketplace.allowedbidders).to.be.an('array');
expect(data.ext.marketplace.allowedbidders[0]).to.equal('all');
});

it('should be ALL when allowedAlternateBidderCodes is \'*\'', function () {
bidderSettingStub.withArgs('pubmatic', 'allowAlternateBidderCodes').returns(true);
bidderSettingStub.withArgs('pubmatic', 'allowedAlternateBidderCodes').returns(['*']);
let request = spec.buildRequests(bidRequests, {
auctionId: 'new-auction-id',
bidderCode: 'pubmatic'
});
let data = JSON.parse(request.data);
expect(data.ext.marketplace.allowedbidders).to.be.an('array');
expect(data.ext.marketplace.allowedbidders[0]).to.equal('all');
});
})

it('Set content from config, set site.content', function() {
let sandbox = sinon.sandbox.create();
const content = {
Expand Down

0 comments on commit e081666

Please sign in to comment.