diff --git a/modules/sovrnBidAdapter.js b/modules/sovrnBidAdapter.js
index 23571373147..eed9ccb7461 100644
--- a/modules/sovrnBidAdapter.js
+++ b/modules/sovrnBidAdapter.js
@@ -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 {
@@ -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),
@@ -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}
`)
+ } 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
}
},
diff --git a/test/spec/modules/sovrnBidAdapter_spec.js b/test/spec/modules/sovrnBidAdapter_spec.js
index ee25f729a0a..83a13f0db7b 100644
--- a/test/spec/modules/sovrnBidAdapter_spec.js
+++ b/test/spec/modules/sovrnBidAdapter_spec.js
@@ -404,9 +404,29 @@ describe('sovrnBidAdapter', function() {
'currency': 'USD',
'netRevenue': true,
'mediaType': 'banner',
- 'ad': decodeURIComponent(`
`),
'ttl': 90,
- 'meta': { advertiserDomains: [] }
+ 'meta': { advertiserDomains: [] },
+ 'ad': decodeURIComponent(`
`),
+ }
+ const videoBid = {
+ 'id': 'a_403370_332fdb9b064040ddbec05891bd13ab28',
+ 'crid': 'creativelycreatedcreativecreative',
+ 'impid': '263c448586f5a1',
+ 'price': 0.45882675,
+ 'nurl': '',
+ 'adm': 'key%3Dvalue',
+ 'h': 480,
+ 'w': 640
+ }
+ const bannerBid = {
+ 'id': 'a_403370_332fdb9b064040ddbec05891bd13ab28',
+ 'crid': 'creativelycreatedcreativecreative',
+ 'impid': '263c448586f5a1',
+ 'price': 0.45882675,
+ 'nurl': '',
+ 'adm': '',
+ 'h': 90,
+ 'w': 728
}
beforeEach(function () {
response = {
@@ -414,14 +434,7 @@ describe('sovrnBidAdapter', function() {
'id': '37386aade21a71',
'seatbid': [{
'bid': [{
- 'id': 'a_403370_332fdb9b064040ddbec05891bd13ab28',
- 'crid': 'creativelycreatedcreativecreative',
- 'impid': '263c448586f5a1',
- 'price': 0.45882675,
- 'nurl': '',
- 'adm': '',
- 'h': 90,
- 'w': 728
+ ...bannerBid
}]
}]
}
@@ -431,7 +444,6 @@ describe('sovrnBidAdapter', function() {
it('should get the correct bid response', function () {
const expectedResponse = {
...baseResponse,
- 'ad': decodeURIComponent(`
>`),
'ttl': 60000,
};
@@ -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 () {