From a37be5a78f17f9a8e1ac924fd28e36ab9b107d19 Mon Sep 17 00:00:00 2001 From: Demetrio Girardi Date: Thu, 12 Dec 2024 09:07:29 -0800 Subject: [PATCH] optimizations --- .../prebidServerBidAdapter/bidderConfig.js | 14 ++- .../modules/prebidServerBidAdapter_spec.js | 110 +++++++++++++----- 2 files changed, 90 insertions(+), 34 deletions(-) diff --git a/modules/prebidServerBidAdapter/bidderConfig.js b/modules/prebidServerBidAdapter/bidderConfig.js index dfe67f5a609..44ab2f90d42 100644 --- a/modules/prebidServerBidAdapter/bidderConfig.js +++ b/modules/prebidServerBidAdapter/bidderConfig.js @@ -56,8 +56,9 @@ export function extractEids({global, bidder}) { entries.push(entry); } if (bySource[eid.source] == null) { - bySource[eid.source] = eid; - } else if (!conflicts.has(eid.source) && !deepEqual(bySource[eid.source], eid)) { + bySource[eid.source] = entry.eid; + } else if (entry.eid === eid) { + // if this is the first time we see this eid, but not the first time we see its source, we have a conflict conflicts.add(eid.source); } return entry; @@ -138,19 +139,20 @@ function replaceEids({global, bidder}) { } Object.entries(consolidated.bidder).forEach(([bidderCode, bidderEids]) => { if (bidderEids.length) { - deepSetValue(bidder[bidderCode], 'user.ext.eids', consolidated.global.concat(bidderEids)); + deepSetValue(bidder[bidderCode], 'user.ext.eids', bidderEids); } }) return {global, bidder} } export function premergeFpd(ortb2Fragments) { - if (ortb2Fragments == null || ortb2Fragments.bidder == null) { + if (ortb2Fragments == null || Object.keys(ortb2Fragments.bidder || {}).length === 0) { return ortb2Fragments; } else { - return replaceEids({ + ortb2Fragments = replaceEids(ortb2Fragments); + return { ...ortb2Fragments, bidder: getPBSBidderConfig(ortb2Fragments) - }) + }; } } diff --git a/test/spec/modules/prebidServerBidAdapter_spec.js b/test/spec/modules/prebidServerBidAdapter_spec.js index 290acc45165..058175b878c 100644 --- a/test/spec/modules/prebidServerBidAdapter_spec.js +++ b/test/spec/modules/prebidServerBidAdapter_spec.js @@ -2070,41 +2070,95 @@ describe('S2S Adapter', function () { }); }); - it('should pass user.ext.eids from FPD', function () { - config.setConfig({s2sConfig: CONFIG}); - const req = { - ...REQUEST, - ortb2Fragments: { - global: { - user: { - ext: { - eids: [{source: '1', id: 1}, {source: '2', id: 2}] - } - } - }, - bidder: { - appnexus: { + describe('user.ext.eids', () => { + let req; + beforeEach(() => { + const s2sConfig = { + ...CONFIG, + bidders: ['appnexus', 'rubicon'] + } + config.setConfig({s2sConfig}); + req = { + ...REQUEST, + s2sConfig, + ortb2Fragments: { + global: { user: { ext: { - eids: [{source: '3', id: 3}] + eids: [{source: 'idA', id: 1}, {source: 'idB', id: 2}] + } + } + }, + bidder: { + appnexus: { + user: { + ext: { + eids: [{source: 'idC', id: 3}] + } } } } } } - } - adapter.callBids(req, BID_REQUESTS, addBidResponse, done, ajax); - const payload = JSON.parse(server.requests[0].requestBody); - expect(payload.user.ext.eids).to.eql([ - {source: '1', id: 1}, - {source: '2', id: 2}, - {source: '3', id: 3} - ]); - expect(payload.ext.prebid.data.eidpermissions).to.eql([{ - bidders: ['appnexus'], - source: '3' - }]); - }); + }) + it('should get picked up from from FPD', function () { + adapter.callBids(req, BID_REQUESTS, addBidResponse, done, ajax); + const payload = JSON.parse(server.requests[0].requestBody); + expect(payload.user.ext.eids).to.eql([ + {source: 'idA', id: 1}, + {source: 'idB', id: 2}, + {source: 'idC', id: 3} + ]); + expect(payload.ext.prebid.data.eidpermissions).to.eql([{ + bidders: ['appnexus'], + source: 'idC' + }]); + }); + + it('should repeat global EIDs when bidder-specific EIDs conflict', () => { + BID_REQUESTS.push({ + ...BID_REQUESTS[0], + bidderCode: 'rubicon', + bids: [{ + bidder: 'rubicon', + params: {} + }] + }) + req.ortb2Fragments.bidder.rubicon = { + user: { + ext: { + eids: [{source: 'idC', id: 4}] + } + } + } + adapter.callBids(req, BID_REQUESTS, addBidResponse, done, ajax); + const payload = JSON.parse(server.requests[0].requestBody); + const globalEids = [ + {source: 'idA', id: 1}, + {source: 'idB', id: 2}, + ] + expect(payload.user.ext.eids).to.eql(globalEids); + expect(payload.ext.prebid?.data?.eidpermissions).to.not.exist; + expect(payload.ext.prebid.bidderconfig).to.have.deep.members([ + { + bidders: ['appnexus'], + config: { + ortb2: { + user: {ext: {eids: globalEids.concat([{source: 'idC', id: 3}])}} + } + } + }, + { + bidders: ['rubicon'], + config: { + ortb2: { + user: {ext: {eids: globalEids.concat([{source: 'idC', id: 4}])}} + } + } + } + ]) + }) + }) it('when config \'currency.adServerCurrency\' value is a string: ORTB has property \'cur\' value set to a single item array', function () { config.setConfig({