Skip to content

Commit

Permalink
PrebidServer Bid Adapter : update to use gloablly defined alias or s2…
Browse files Browse the repository at this point in the history
…sConfig defined alias (#12159)

* update to use gloablly defined alias or s2sConfig defined alias

* Add test case

---------

Co-authored-by: Demetrio Girardi <[email protected]>
  • Loading branch information
mmoschovas and dgirardi authored Aug 22, 2024
1 parent 95c8118 commit 23ac002
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 61 deletions.
3 changes: 2 additions & 1 deletion modules/prebidServerBidAdapter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,9 @@ export function PrebidServer() {

if (Array.isArray(_s2sConfigs)) {
if (s2sBidRequest.s2sConfig && s2sBidRequest.s2sConfig.syncEndpoint && getMatchingConsentUrl(s2sBidRequest.s2sConfig.syncEndpoint, gdprConsent)) {
const s2sAliases = (s2sBidRequest.s2sConfig.extPrebid && s2sBidRequest.s2sConfig.extPrebid.aliases) ?? {};
let syncBidders = s2sBidRequest.s2sConfig.bidders
.map(bidder => adapterManager.aliasRegistry[bidder] || bidder)
.map(bidder => adapterManager.aliasRegistry[bidder] || s2sAliases[bidder] || bidder)
.filter((bidder, index, array) => (array.indexOf(bidder) === index));

queueSync(syncBidders, gdprConsent, uspConsent, gppConsent, s2sBidRequest.s2sConfig);
Expand Down
137 changes: 77 additions & 60 deletions test/spec/modules/prebidServerBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3925,77 +3925,94 @@ describe('S2S Adapter', function () {
expect(typeof config.getConfig('s2sConfig').syncUrlModifier.appnexus).to.equal('function')
});

it('should set correct bidder names to bidders property when using an alias for that bidder', function () {
const s2sConfig = utils.deepClone(CONFIG);

// Add syncEndpoint so that the request goes to the User Sync endpoint
// Modify the bidders property to include an alias for Rubicon adapter
s2sConfig.syncEndpoint = { p1Consent: 'https://prebid.adnxs.com/pbs/v1/cookie_sync' };
s2sConfig.bidders = ['appnexus', 'rubicon-alias'];

const s2sBidRequest = utils.deepClone(REQUEST);
s2sBidRequest.s2sConfig = s2sConfig;

// Add another bidder, `rubicon-alias`
s2sBidRequest.ad_units[0].bids.push({
bidder: 'rubicon-alias',
params: {
accoundId: 14062,
siteId: 70608,
zoneId: 498816
Object.entries({
'an alias'() {
adapterManager.aliasBidAdapter('rubicon', 'rubicon-alias');
},
'a server side alias'(s2sConfig) {
s2sConfig.extPrebid = {
aliases: {
'rubicon-alias': 'rubicon'
}
}
});

// create an alias for the Rubicon Bid Adapter
adapterManager.aliasBidAdapter('rubicon', 'rubicon-alias');
}
}).forEach(([t, setupAlias]) => {
describe(`when using ${t}`, () => {
afterEach(() => {
delete adapterManager.aliasRegistry['rubicon-alias'];
});
it(`should set correct bidder names to bidders property`, function () {
const s2sConfig = utils.deepClone(CONFIG);

// Add syncEndpoint so that the request goes to the User Sync endpoint
// Modify the bidders property to include an alias for Rubicon adapter
s2sConfig.syncEndpoint = {p1Consent: 'https://prebid.adnxs.com/pbs/v1/cookie_sync'};
s2sConfig.bidders = ['appnexus', 'rubicon-alias'];

setupAlias(s2sConfig);

const s2sBidRequest = utils.deepClone(REQUEST);
s2sBidRequest.s2sConfig = s2sConfig;

// Add another bidder, `rubicon-alias`
s2sBidRequest.ad_units[0].bids.push({
bidder: 'rubicon-alias',
params: {
accoundId: 14062,
siteId: 70608,
zoneId: 498816
}
});

const bidRequest = utils.deepClone(BID_REQUESTS);
bidRequest.push({
'bidderCode': 'rubicon-alias',
'auctionId': '4146ab2b-9422-4040-9b1c-966fffbfe2d4',
'bidderRequestId': '4b1a4f9c3e4546',
'tid': 'd7fa8342-ae22-4ca1-b237-331169350f84',
'bids': [
{
'bidder': 'rubicon-alias',
'params': {
'accountId': 14062,
'siteId': 70608,
'zoneId': 498816
},
'bid_id': '2a9523915411c3',
'mediaTypes': {
'banner': {
const bidRequest = utils.deepClone(BID_REQUESTS);
bidRequest.push({
'bidderCode': 'rubicon-alias',
'auctionId': '4146ab2b-9422-4040-9b1c-966fffbfe2d4',
'bidderRequestId': '4b1a4f9c3e4546',
'tid': 'd7fa8342-ae22-4ca1-b237-331169350f84',
'bids': [
{
'bidder': 'rubicon-alias',
'params': {
'accountId': 14062,
'siteId': 70608,
'zoneId': 498816
},
'bid_id': '2a9523915411c3',
'mediaTypes': {
'banner': {
'sizes': [
[
300,
250
]
]
}
},
'adUnitCode': 'div-gpt-ad-1460505748561-0',
'transactionId': '78ddc106-b7d8-45d1-bd29-86993098e53d',
'sizes': [
[
300,
250
]
]
],
'bidId': '2a9523915411c3',
'bidderRequestId': '4b1a4f9c3e4546',
'auctionId': '4146ab2b-9422-4040-9b1c-966fffbfe2d4'
}
},
'adUnitCode': 'div-gpt-ad-1460505748561-0',
'transactionId': '78ddc106-b7d8-45d1-bd29-86993098e53d',
'sizes': [
[
300,
250
]
],
'bidId': '2a9523915411c3',
'bidderRequestId': '4b1a4f9c3e4546',
'auctionId': '4146ab2b-9422-4040-9b1c-966fffbfe2d4'
}
],
'auctionStart': 1569234122602,
'timeout': 1000,
'src': 's2s'
});
'auctionStart': 1569234122602,
'timeout': 1000,
'src': 's2s'
});

adapter.callBids(s2sBidRequest, bidRequest, addBidResponse, done, ajax);
adapter.callBids(s2sBidRequest, bidRequest, addBidResponse, done, ajax);

const requestBid = JSON.parse(server.requests[0].requestBody);
expect(requestBid.bidders).to.deep.equal(['appnexus', 'rubicon']);
const requestBid = JSON.parse(server.requests[0].requestBody);
expect(requestBid.bidders).to.deep.equal(['appnexus', 'rubicon']);
});
});
});

it('should add cooperative sync flag to cookie_sync request if property is present', function () {
Expand Down

0 comments on commit 23ac002

Please sign in to comment.