From 32b8db4332e6d3a5e225adaa895d78b3a5bf4c4f Mon Sep 17 00:00:00 2001 From: mikhalovich Date: Tue, 7 Dec 2021 12:50:00 +0300 Subject: [PATCH 1/3] EX-1752 Add seatbid array support in sovrn adapter --- modules/sovrnBidAdapter.js | 28 +++++++++- test/spec/modules/sovrnBidAdapter_spec.js | 64 +++++++++++++++++++---- 2 files changed, 80 insertions(+), 12 deletions(-) diff --git a/modules/sovrnBidAdapter.js b/modules/sovrnBidAdapter.js index 23571373147..02e8afc6ae5 100644 --- a/modules/sovrnBidAdapter.js +++ b/modules/sovrnBidAdapter.js @@ -192,6 +192,7 @@ 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 && @@ -224,8 +225,33 @@ export const spec = { }); } return sovrnBidResponses + return seatbid + .filter(seat => seat) + .map(seat => seat.bid.map(sovrnBid => { + const bid = { + requestId: sovrnBid.impid, + cpm: parseFloat(sovrnBid.price), + width: parseInt(sovrnBid.w), + height: parseInt(sovrnBid.h), + creativeId: sovrnBid.crid || sovrnBid.id, + dealId: sovrnBid.dealid || null, + currency: 'USD', + netRevenue: true, + mediaType: sovrnBid.nurl ? BANNER : VIDEO, + ttl: sovrnBid.ext?.ttl || 90, + meta: { advertiserDomains: sovrnBid && sovrnBid.adomain ? sovrnBid.adomain : [] } + } + if (sovrnBid.nurl) { + bid.ad = decodeURIComponent(`${sovrnBid.adm}`) + } else { + bid.vastXml = decodeURIComponent(sovrnBid.adm) + } + return bid + })) + .flat() } catch (e) { - logError('Could not intrepret bidresponse, error deatils:', e); + logError('Could not intrepret bidresponse, error deatils:', 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 () { From c36ae98e9ac33a8363ed2cf97176460ccae64fcd Mon Sep 17 00:00:00 2001 From: Chris Pabst Date: Tue, 12 Apr 2022 10:25:37 -0600 Subject: [PATCH 2/3] Resolved conflicts. --- modules/sovrnBidAdapter.js | 85 +++++++++++++------------------------- 1 file changed, 29 insertions(+), 56 deletions(-) diff --git a/modules/sovrnBidAdapter.js b/modules/sovrnBidAdapter.js index 02e8afc6ae5..25015dbd9e6 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,65 +193,37 @@ 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 => { - const bid = { - requestId: sovrnBid.impid, - cpm: parseFloat(sovrnBid.price), - width: parseInt(sovrnBid.w), - height: parseInt(sovrnBid.h), - creativeId: sovrnBid.crid || sovrnBid.id, - dealId: sovrnBid.dealid || null, - currency: 'USD', - netRevenue: true, - ttl: sovrnBid.ext ? (sovrnBid.ext.ttl || 90) : 90, - meta: { advertiserDomains: sovrnBid && sovrnBid.adomain ? sovrnBid.adomain : [] } - } + if (!id || !seatbid || !Array.isArray(seatbid)) return [] - if (!sovrnBid.nurl) { - bid.mediaType = VIDEO - bid.vastXml = decodeURIComponent(sovrnBid.adm) - } else { - bid.mediaType = BANNER - bid.ad = decodeURIComponent(`${sovrnBid.adm}`) - } - sovrnBidResponses.push(bid); - }); - } - return sovrnBidResponses + try { return seatbid - .filter(seat => seat) - .map(seat => seat.bid.map(sovrnBid => { - const bid = { - requestId: sovrnBid.impid, - cpm: parseFloat(sovrnBid.price), - width: parseInt(sovrnBid.w), - height: parseInt(sovrnBid.h), - creativeId: sovrnBid.crid || sovrnBid.id, - dealId: sovrnBid.dealid || null, - currency: 'USD', - netRevenue: true, - mediaType: sovrnBid.nurl ? BANNER : VIDEO, - ttl: sovrnBid.ext?.ttl || 90, - meta: { advertiserDomains: sovrnBid && sovrnBid.adomain ? sovrnBid.adomain : [] } - } - if (sovrnBid.nurl) { - bid.ad = decodeURIComponent(`${sovrnBid.adm}`) - } else { - bid.vastXml = decodeURIComponent(sovrnBid.adm) - } - return bid - })) + .filter(seat => seat) + .map(seat => seat.bid.map(sovrnBid => { + const bid = { + requestId: sovrnBid.impid, + cpm: parseFloat(sovrnBid.price), + width: parseInt(sovrnBid.w), + height: parseInt(sovrnBid.h), + creativeId: sovrnBid.crid || sovrnBid.id, + dealId: sovrnBid.dealid || null, + currency: 'USD', + netRevenue: true, + mediaType: sovrnBid.nurl ? BANNER : VIDEO, + ttl: sovrnBid.ext?.ttl || 90, + meta: { advertiserDomains: sovrnBid && sovrnBid.adomain ? sovrnBid.adomain : [] } + } + + if (sovrnBid.nurl) { + bid.ad = decodeURIComponent(`${sovrnBid.adm}`) + } else { + bid.vastXml = decodeURIComponent(sovrnBid.adm) + } + + return bid + })) .flat() } catch (e) { - logError('Could not intrepret bidresponse, error deatils:', e) + logError('Could not interpret bidresponse, error details:', e) return e } }, From 64351cbb42bf59547a8fa308e5b30a0c405b2f89 Mon Sep 17 00:00:00 2001 From: Chris Pabst Date: Wed, 13 Apr 2022 18:11:12 -0600 Subject: [PATCH 3/3] Fix indentation --- modules/sovrnBidAdapter.js | 44 +++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/modules/sovrnBidAdapter.js b/modules/sovrnBidAdapter.js index 25015dbd9e6..eed9ccb7461 100644 --- a/modules/sovrnBidAdapter.js +++ b/modules/sovrnBidAdapter.js @@ -197,30 +197,30 @@ export const spec = { try { return seatbid - .filter(seat => seat) - .map(seat => seat.bid.map(sovrnBid => { - const bid = { - requestId: sovrnBid.impid, - cpm: parseFloat(sovrnBid.price), - width: parseInt(sovrnBid.w), - height: parseInt(sovrnBid.h), - creativeId: sovrnBid.crid || sovrnBid.id, - dealId: sovrnBid.dealid || null, - currency: 'USD', - netRevenue: true, - mediaType: sovrnBid.nurl ? BANNER : VIDEO, - ttl: sovrnBid.ext?.ttl || 90, - meta: { advertiserDomains: sovrnBid && sovrnBid.adomain ? sovrnBid.adomain : [] } - } + .filter(seat => seat) + .map(seat => seat.bid.map(sovrnBid => { + const bid = { + requestId: sovrnBid.impid, + cpm: parseFloat(sovrnBid.price), + width: parseInt(sovrnBid.w), + height: parseInt(sovrnBid.h), + creativeId: sovrnBid.crid || sovrnBid.id, + dealId: sovrnBid.dealid || null, + currency: 'USD', + netRevenue: true, + mediaType: sovrnBid.nurl ? BANNER : VIDEO, + ttl: sovrnBid.ext?.ttl || 90, + meta: { advertiserDomains: sovrnBid && sovrnBid.adomain ? sovrnBid.adomain : [] } + } - if (sovrnBid.nurl) { - bid.ad = decodeURIComponent(`${sovrnBid.adm}`) - } else { - bid.vastXml = decodeURIComponent(sovrnBid.adm) - } + if (sovrnBid.nurl) { + bid.ad = decodeURIComponent(`${sovrnBid.adm}`) + } else { + bid.vastXml = decodeURIComponent(sovrnBid.adm) + } - return bid - })) + return bid + })) .flat() } catch (e) { logError('Could not interpret bidresponse, error details:', e)