From 637b747dcf73eb1fd140495f21114823b74a0fdb Mon Sep 17 00:00:00 2001 From: Nick Jacob Date: Wed, 5 Jun 2024 15:46:20 -0400 Subject: [PATCH 1/2] add support for overriding bidderCode (allowAlternateBidderCodes) in AMX Bid adapter --- modules/amxBidAdapter.js | 7 ++++ test/spec/modules/amxBidAdapter_spec.js | 49 +++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/modules/amxBidAdapter.js b/modules/amxBidAdapter.js index 6e14f65b0c8..f2d44c68d08 100644 --- a/modules/amxBidAdapter.js +++ b/modules/amxBidAdapter.js @@ -454,6 +454,10 @@ export const spec = { setUIDSafe(response.am); } + const bidderSettings = config.getConfig('bidderSettings'); + const settings = bidderSettings?.amx ?? bidderSettings?.standard ?? {};; + const allowAlternateBidderCodes = !!settings.allowAlternateBidderCodes; + return flatMap(Object.keys(response.r), (bidID) => { return flatMap(response.r[bidID], (siteBid) => siteBid.b.map((bid) => { @@ -466,8 +470,10 @@ export const spec = { const size = resolveSize(bid, request.data, bidID); const defaultExpiration = mediaType === BANNER ? 240 : 300; + const { bc: bidderCode, ds: demandSource } = bid.ext ?? {}; return { + ...(bidderCode != null && allowAlternateBidderCodes ? { bidderCode } : {}), requestId: bidID, cpm: bid.price, width: size[0], @@ -479,6 +485,7 @@ export const spec = { meta: { advertiserDomains: bid.adomain, mediaType, + ...(demandSource != null ? { demandSource } : {}), }, mediaType, ttl: typeof bid.exp === 'number' ? bid.exp : defaultExpiration, diff --git a/test/spec/modules/amxBidAdapter_spec.js b/test/spec/modules/amxBidAdapter_spec.js index 21fa2e2617c..a84a30a945a 100644 --- a/test/spec/modules/amxBidAdapter_spec.js +++ b/test/spec/modules/amxBidAdapter_spec.js @@ -583,6 +583,55 @@ describe('AmxBidAdapter', () => { expect(parsed).to.eql([]); }); + it('will read an bidderCode override from bid.ext.prebid.meta', () => { + const currentConfig = config.getConfig(); + config.setConfig({ + ...currentConfig, + bidderSettings: { + amx: { + allowAlternateBidderCodes: true + } + } + }); + + const parsed = spec.interpretResponse( + { body: { + ...sampleServerResponse, + r: { + [sampleRequestId]: [{ + ...sampleServerResponse.r[sampleRequestId][0], + b: [{ + ...sampleServerResponse.r[sampleRequestId][0].b[0], + ext: { + bc: 'amx-pmp', + ds: 'example', + } + }] + }] + }}}, + baseRequest + ); + + config.setConfig(currentConfig); + expect(parsed.length).to.equal(1); // we removed one + + // we should have display, video, display + expect(parsed[0]).to.deep.equal({ + ...baseBidResponse, + meta: { + ...baseBidResponse.meta, + mediaType: BANNER, + demandSource: 'example' + }, + mediaType: BANNER, + bidderCode: 'amx-pmp', + width: 300, + height: 600, // from the bid itself + ttl: 90, + ad: sampleDisplayAd, + }); + }); + it('can parse a display ad', () => { const parsed = spec.interpretResponse( { body: sampleServerResponse }, From e3de68210aa8935df16da179579c183de19ae367 Mon Sep 17 00:00:00 2001 From: Nick Jacob Date: Thu, 6 Jun 2024 10:39:14 -0400 Subject: [PATCH 2/2] fix formatting and actually run tests --- modules/amxBidAdapter.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/amxBidAdapter.js b/modules/amxBidAdapter.js index f2d44c68d08..df260958104 100644 --- a/modules/amxBidAdapter.js +++ b/modules/amxBidAdapter.js @@ -455,7 +455,7 @@ export const spec = { } const bidderSettings = config.getConfig('bidderSettings'); - const settings = bidderSettings?.amx ?? bidderSettings?.standard ?? {};; + const settings = bidderSettings?.amx ?? bidderSettings?.standard ?? {}; const allowAlternateBidderCodes = !!settings.allowAlternateBidderCodes; return flatMap(Object.keys(response.r), (bidID) => { @@ -473,7 +473,7 @@ export const spec = { const { bc: bidderCode, ds: demandSource } = bid.ext ?? {}; return { - ...(bidderCode != null && allowAlternateBidderCodes ? { bidderCode } : {}), + ...(bidderCode != null && allowAlternateBidderCodes ? { bidderCode } : {}), requestId: bidID, cpm: bid.price, width: size[0],