Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 18 additions & 19 deletions modules/sovrnBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ export const spec = {

/**
* Format the bid request object for our endpoint
* @param {BidRequest[]} bidRequests Array of Sovrn bidders
* @return object of parameters for Prebid AJAX request
* @param bidReqs
* @param bidderRequest
*/
buildRequests: function(bidReqs, bidderRequest) {
try {
Expand Down Expand Up @@ -192,14 +193,12 @@ export const spec = {
* @return {Bid[]} An array of formatted bids.
*/
interpretResponse: function({ body: {id, seatbid} }) {
if (!id || !seatbid || !Array.isArray(seatbid)) return []

try {
let sovrnBidResponses = [];
if (id &&
seatbid &&
seatbid.length > 0 &&
seatbid[0].bid &&
seatbid[0].bid.length > 0) {
seatbid[0].bid.map(sovrnBid => {
return seatbid
.filter(seat => seat)
.map(seat => seat.bid.map(sovrnBid => {
const bid = {
requestId: sovrnBid.impid,
cpm: parseFloat(sovrnBid.price),
Expand All @@ -209,23 +208,23 @@ export const spec = {
dealId: sovrnBid.dealid || null,
currency: 'USD',
netRevenue: true,
ttl: sovrnBid.ext ? (sovrnBid.ext.ttl || 90) : 90,
mediaType: sovrnBid.nurl ? BANNER : VIDEO,
ttl: sovrnBid.ext?.ttl || 90,
meta: { advertiserDomains: sovrnBid && sovrnBid.adomain ? sovrnBid.adomain : [] }
}

if (!sovrnBid.nurl) {
bid.mediaType = VIDEO
bid.vastXml = decodeURIComponent(sovrnBid.adm)
} else {
bid.mediaType = BANNER
if (sovrnBid.nurl) {
bid.ad = decodeURIComponent(`${sovrnBid.adm}<img src="${sovrnBid.nurl}">`)
} else {
bid.vastXml = decodeURIComponent(sovrnBid.adm)
}
sovrnBidResponses.push(bid);
});
}
return sovrnBidResponses

return bid
}))
.flat()
} catch (e) {
logError('Could not intrepret bidresponse, error deatils:', e);
logError('Could not interpret bidresponse, error details:', e)
return e
}
},

Expand Down
64 changes: 53 additions & 11 deletions test/spec/modules/sovrnBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,24 +404,37 @@ describe('sovrnBidAdapter', function() {
'currency': 'USD',
'netRevenue': true,
'mediaType': 'banner',
'ad': decodeURIComponent(`<!-- Creative --><img src="<!-- NURL -->">`),
'ttl': 90,
'meta': { advertiserDomains: [] }
'meta': { advertiserDomains: [] },
'ad': decodeURIComponent(`<!-- Creative --><img src="<!-- NURL -->">`),
}
const videoBid = {
'id': 'a_403370_332fdb9b064040ddbec05891bd13ab28',
'crid': 'creativelycreatedcreativecreative',
'impid': '263c448586f5a1',
'price': 0.45882675,
'nurl': '',
'adm': '<VAST version="4.2" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.iab.com/VAST">key%3Dvalue</VAST>',
'h': 480,
'w': 640
}
const bannerBid = {
'id': 'a_403370_332fdb9b064040ddbec05891bd13ab28',
'crid': 'creativelycreatedcreativecreative',
'impid': '263c448586f5a1',
'price': 0.45882675,
'nurl': '<!-- NURL -->',
'adm': '<!-- Creative -->',
'h': 90,
'w': 728
}
beforeEach(function () {
response = {
body: {
'id': '37386aade21a71',
'seatbid': [{
'bid': [{
'id': 'a_403370_332fdb9b064040ddbec05891bd13ab28',
'crid': 'creativelycreatedcreativecreative',
'impid': '263c448586f5a1',
'price': 0.45882675,
'nurl': '<!-- NURL -->',
'adm': '<!-- Creative -->',
'h': 90,
'w': 728
...bannerBid
}]
}]
}
Expand All @@ -431,7 +444,6 @@ describe('sovrnBidAdapter', function() {
it('should get the correct bid response', function () {
const expectedResponse = {
...baseResponse,
'ad': decodeURIComponent(`<!-- Creative --><img src=<!-- NURL -->>`),
'ttl': 60000,
};

Expand Down Expand Up @@ -491,6 +503,36 @@ describe('sovrnBidAdapter', function() {

expect(result.length).to.equal(0);
});

it('should get the correct bid response with 2 different bids', function () {
const expectedVideoResponse = {
...baseResponse,
'vastXml': decodeURIComponent(videoBid.adm)
}
delete expectedVideoResponse.ad

const expectedBannerResponse = {
...baseResponse
}

response.body.seatbid = [{ bid: [bannerBid] }, { bid: [videoBid] }]
const result = spec.interpretResponse(response)

expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedBannerResponse))
expect(Object.keys(result[1])).to.deep.equal(Object.keys(expectedVideoResponse))
})

it('should get the correct bid response with 2 seatbid items', function () {
const expectedResponse = {
...baseResponse
}
response.body.seatbid = [response.body.seatbid[0], response.body.seatbid[0]]

const result = spec.interpretResponse(response)

expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse))
expect(Object.keys(result[1])).to.deep.equal(Object.keys(expectedResponse))
})
});

describe('interpretResponse video', function () {
Expand Down