Skip to content

Commit

Permalink
Sovrn Bid Adapter: Fledge module integration (prebid#11382)
Browse files Browse the repository at this point in the history
* fledge init

* minor test fix

* additional check and test fixes
  • Loading branch information
ikagotso authored Apr 26, 2024
1 parent 2be3f29 commit c835325
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 4 deletions.
36 changes: 32 additions & 4 deletions modules/sovrnBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,17 @@ export const spec = {
imp.ext = imp.ext || {}
imp.ext.deals = segmentsString.split(',').map(deal => deal.trim())
}

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
}
}

sovrnImps.push(imp)
})

Expand Down Expand Up @@ -209,14 +220,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 = {
Expand All @@ -242,6 +253,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
Expand Down
121 changes: 121 additions & 0 deletions test/spec/modules/sovrnBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,53 @@ 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: 1
}
},
}
const payload = JSON.parse(spec.buildRequests([bidRequest], bidderRequest).data)
expect(payload.imp[0].ext.ae).to.equal(1)
})

it('when FLEDGE is not enabled, should not send ortb2imp.ext.ae', function () {
const bidRequest = {
...baseBidRequest,
ortb2Imp: {
ext: {
ae: 1
}
},
}
const payload = JSON.parse(spec.buildRequests([bidRequest], baseBidderRequest).data)
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')
Expand Down Expand Up @@ -780,6 +827,80 @@ 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: '<!-- NURL -->',
adm: '<!-- Creative -->',
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: '<!-- NURL -->',
adm: '<!-- Creative -->',
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 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 = '<VAST version="4.2" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.iab.com/VAST">key%3Dvalue</VAST>'
Expand Down

0 comments on commit c835325

Please sign in to comment.