From b7cd6edabb151ec600a8dbde264ae744398ac41b Mon Sep 17 00:00:00 2001 From: Irakli Gotsiridze Date: Wed, 10 Apr 2024 18:46:44 +0400 Subject: [PATCH 1/3] fledge init --- modules/sovrnBidAdapter.js | 35 ++++++- test/spec/modules/sovrnBidAdapter_spec.js | 118 ++++++++++++++++++++++ 2 files changed, 149 insertions(+), 4 deletions(-) diff --git a/modules/sovrnBidAdapter.js b/modules/sovrnBidAdapter.js index 64604618680..1a7cca9d47e 100644 --- a/modules/sovrnBidAdapter.js +++ b/modules/sovrnBidAdapter.js @@ -137,6 +137,16 @@ export const spec = { imp.ext = imp.ext || {} imp.ext.deals = segmentsString.split(',').map(deal => deal.trim()) } + + if (bidderRequest.fledgeEnabled) { + imp.ext = imp.ext || {}; + imp.ext.ae = bid?.ortb2Imp?.ext?.ae + } else { + if (imp.ext?.ae) { + delete imp.ext.ae; + } + } + sovrnImps.push(imp) }) @@ -209,14 +219,14 @@ export const spec = { /** * Format Sovrn responses as Prebid bid responses - * @param {id, seatbid} sovrnResponse A successful response from Sovrn. - * @return {Bid[]} An array of formatted bids. + * @param {id, seatbid, ext} sovrnResponse A successful response from Sovrn. + * @return An array of formatted bids (+ fledgeAuctionConfigs if available) */ - interpretResponse: function({ body: {id, seatbid} }) { + interpretResponse: function({ body: {id, seatbid, ext} }) { if (!id || !seatbid || !Array.isArray(seatbid)) return [] try { - return seatbid + let bids = seatbid .filter(seat => seat) .map(seat => seat.bid.map(sovrnBid => { const bid = { @@ -242,6 +252,23 @@ export const spec = { return bid })) .flat() + + let fledgeAuctionConfigs = deepAccess(ext, 'fledge_auction_configs'); + if (fledgeAuctionConfigs) { + fledgeAuctionConfigs = Object.entries(fledgeAuctionConfigs).map(([bidId, cfg]) => { + return { + bidId, + config: Object.assign({ + auctionSignals: {}, + }, cfg) + } + }); + return { + bids, + fledgeAuctionConfigs, + } + } + return bids } catch (e) { logError('Could not interpret bidresponse, error details:', e) return e diff --git a/test/spec/modules/sovrnBidAdapter_spec.js b/test/spec/modules/sovrnBidAdapter_spec.js index 274192d14a7..1ff453ddaa8 100644 --- a/test/spec/modules/sovrnBidAdapter_spec.js +++ b/test/spec/modules/sovrnBidAdapter_spec.js @@ -240,6 +240,36 @@ describe('sovrnBidAdapter', function() { expect(payload.imp[0]?.ext?.tid).to.equal('1a2c032473f4983') }) + it('when FLEDGE is enabled, should send ortb2imp.ext.ae', function () { + const bidderRequest = { + ...baseBidderRequest, + fledgeEnabled: true + } + const bidRequest = { + ...baseBidRequest, + ortb2Imp: { + ext: { + ae: 2 + } + }, + } + const payload = JSON.parse(spec.buildRequests([bidRequest], bidderRequest).data) + expect(payload.imp[0].ext.ae).to.equal(2) + }) + + it('when FLEDGE is not enabled, should not send ortb2imp.ext.ae', function () { + const bidRequest = { + ...baseBidRequest, + ortb2Imp: { + ext: { + ae: 2 + } + }, + } + const payload = JSON.parse(spec.buildRequests([bidRequest], baseBidderRequest).data) + expect(payload.imp[0].ext.ae).to.be.undefined + }) + it('includes the ad unit code in the request', function() { const impression = payload.imp[0] expect(impression.adunitcode).to.equal('adunit-code') @@ -780,6 +810,94 @@ describe('sovrnBidAdapter', function() { }) }) + describe('fledge response', function () { + let fledgeResponse = { + body: { + id: '37386aade21a71', + seatbid: [{ + bid: [{ + id: 'a_403370_332fdb9b064040ddbec05891bd13ab28', + crid: 'creativelycreatedcreativecreative', + impid: '263c448586f5a1', + price: 0.45882675, + nurl: '', + adm: '', + h: 90, + w: 728 + }] + }], + ext: { + fledge_auction_configs: { + 'test_bid_id': { + seller: 'ap.lijit.com', + interestGroupBuyers: ['dsp1.com'], + sellerTimeout: 0, + perBuyerSignals: { + 'dsp1.com': { + bid_macros: 0.1, + disallowed_adv_ids: [ + '8765', + '4321' + ], + } + } + } + } + } + } + } + let invalidFledgeResponse = { + body: { + id: '37386aade21a71', + seatbid: [{ + bid: [{ + id: 'a_403370_332fdb9b064040ddbec05891bd13ab28', + crid: 'creativelycreatedcreativecreative', + impid: '263c448586f5a1', + price: 0.45882675, + nurl: '', + adm: '', + h: 90, + w: 728 + }] + }], + ext: { + fledge_auction_configs: { + } + } + } + } + it('should return fledge auction configs alongside bids', function () { + const result = spec.interpretResponse(fledgeResponse) + expect(result).to.have.property('bids') + expect(result).to.have.property('fledgeAuctionConfigs') + expect(result.fledgeAuctionConfigs.length).to.equal(1) + expect(result.fledgeAuctionConfigs[0].bidId).to.equal('test_bid_id') + expect(result.fledgeAuctionConfigs[0].config).to.not.be.undefined + expect(result.fledgeAuctionConfigs[0].config).to.contain.keys('seller', 'interestGroupBuyers', 'sellerTimeout', 'perBuyerSignals') + }) + it('should ignore invalid fledge auction configs', function () { + const expectedResponse = { + requestId: '263c448586f5a1', + cpm: 0.45882675, + width: 728, + height: 90, + creativeId: 'creativelycreatedcreativecreative', + dealId: null, + currency: 'USD', + netRevenue: true, + mediaType: 'banner', + ttl: 60000, + meta: { advertiserDomains: [] }, + ad: decodeURIComponent(`>`) + } + const result = spec.interpretResponse(invalidFledgeResponse) + expect(result).to.have.property('bids') + expect(result).to.have.property('fledgeAuctionConfigs') + expect(result.fledgeAuctionConfigs.length).to.equal(0) + }) + }) + describe('interpretResponse video', function () { let videoResponse const bidAdm = 'key%3Dvalue' From 9853b8aa9097775dfd6a36db2cca9cb4464e8066 Mon Sep 17 00:00:00 2001 From: Irakli Gotsiridze Date: Wed, 10 Apr 2024 18:52:50 +0400 Subject: [PATCH 2/3] minor test fix --- test/spec/modules/sovrnBidAdapter_spec.js | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/test/spec/modules/sovrnBidAdapter_spec.js b/test/spec/modules/sovrnBidAdapter_spec.js index 1ff453ddaa8..471060c9dcc 100644 --- a/test/spec/modules/sovrnBidAdapter_spec.js +++ b/test/spec/modules/sovrnBidAdapter_spec.js @@ -877,20 +877,6 @@ describe('sovrnBidAdapter', function() { expect(result.fledgeAuctionConfigs[0].config).to.contain.keys('seller', 'interestGroupBuyers', 'sellerTimeout', 'perBuyerSignals') }) it('should ignore invalid fledge auction configs', function () { - const expectedResponse = { - requestId: '263c448586f5a1', - cpm: 0.45882675, - width: 728, - height: 90, - creativeId: 'creativelycreatedcreativecreative', - dealId: null, - currency: 'USD', - netRevenue: true, - mediaType: 'banner', - ttl: 60000, - meta: { advertiserDomains: [] }, - ad: decodeURIComponent(`>`) - } const result = spec.interpretResponse(invalidFledgeResponse) expect(result).to.have.property('bids') expect(result).to.have.property('fledgeAuctionConfigs') From c00ffaaff7f5d97a2047df184a0d53f7d6aff1a4 Mon Sep 17 00:00:00 2001 From: Irakli Gotsiridze Date: Thu, 11 Apr 2024 15:25:05 +0400 Subject: [PATCH 3/3] additional check and test fixes --- modules/sovrnBidAdapter.js | 9 +++++---- test/spec/modules/sovrnBidAdapter_spec.js | 23 ++++++++++++++++++++--- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/modules/sovrnBidAdapter.js b/modules/sovrnBidAdapter.js index 1a7cca9d47e..89705db6602 100644 --- a/modules/sovrnBidAdapter.js +++ b/modules/sovrnBidAdapter.js @@ -138,12 +138,13 @@ export const spec = { imp.ext.deals = segmentsString.split(',').map(deal => deal.trim()) } - if (bidderRequest.fledgeEnabled) { - imp.ext = imp.ext || {}; - imp.ext.ae = bid?.ortb2Imp?.ext?.ae + const auctionEnvironment = bid?.ortb2Imp?.ext?.ae + if (bidderRequest.fledgeEnabled && isInteger(auctionEnvironment)) { + imp.ext = imp.ext || {} + imp.ext.ae = auctionEnvironment } else { if (imp.ext?.ae) { - delete imp.ext.ae; + delete imp.ext.ae } } diff --git a/test/spec/modules/sovrnBidAdapter_spec.js b/test/spec/modules/sovrnBidAdapter_spec.js index 471060c9dcc..3411a37c967 100644 --- a/test/spec/modules/sovrnBidAdapter_spec.js +++ b/test/spec/modules/sovrnBidAdapter_spec.js @@ -249,12 +249,12 @@ describe('sovrnBidAdapter', function() { ...baseBidRequest, ortb2Imp: { ext: { - ae: 2 + ae: 1 } }, } const payload = JSON.parse(spec.buildRequests([bidRequest], bidderRequest).data) - expect(payload.imp[0].ext.ae).to.equal(2) + expect(payload.imp[0].ext.ae).to.equal(1) }) it('when FLEDGE is not enabled, should not send ortb2imp.ext.ae', function () { @@ -262,7 +262,7 @@ describe('sovrnBidAdapter', function() { ...baseBidRequest, ortb2Imp: { ext: { - ae: 2 + ae: 1 } }, } @@ -270,6 +270,23 @@ describe('sovrnBidAdapter', function() { expect(payload.imp[0].ext.ae).to.be.undefined }) + it('when FLEDGE is enabled, but env is malformed, should not send ortb2imp.ext.ae', function () { + const bidderRequest = { + ...baseBidderRequest, + fledgeEnabled: true + } + const bidRequest = { + ...baseBidRequest, + ortb2Imp: { + ext: { + ae: 'malformed' + } + }, + } + const payload = JSON.parse(spec.buildRequests([bidRequest], bidderRequest).data) + expect(payload.imp[0].ext.ae).to.be.undefined + }) + it('includes the ad unit code in the request', function() { const impression = payload.imp[0] expect(impression.adunitcode).to.equal('adunit-code')