From 486b03ab5b9a6f04fce46c01c6ccb069705a127f Mon Sep 17 00:00:00 2001 From: Mikael Lundin Date: Tue, 20 Apr 2021 17:51:51 +0200 Subject: [PATCH] Adnuntius Bid Adapter: Bug fix ordered response. (#6625) * Added automatic tzo and targetId to adserver request. * Fixing issues with bid price being too low. * Fixing issues with bid price being too low. * Ad server response places bids in correct placement * Adnuntius Bid Adapter ordered responses * Ad server response places bids in correct placement * Adnuntius Bid Adapter ordered responses * RTD Provider rebase * wrongly merged to master --- modules/adnuntiusBidAdapter.js | 50 +++++++++++-------- test/spec/modules/adnuntiusBidAdapter_spec.js | 20 +++++--- 2 files changed, 42 insertions(+), 28 deletions(-) diff --git a/modules/adnuntiusBidAdapter.js b/modules/adnuntiusBidAdapter.js index 362442015f6d..e5878ad047dd 100644 --- a/modules/adnuntiusBidAdapter.js +++ b/modules/adnuntiusBidAdapter.js @@ -1,5 +1,5 @@ - import { registerBidder } from '../src/adapters/bidderFactory.js'; + const BIDDER_CODE = 'adnuntius'; const ENDPOINT_URL = 'https://delivery.adnuntius.com/i?tzo='; @@ -7,7 +7,7 @@ export const spec = { code: BIDDER_CODE, isBidRequestValid: function (bid) { - return !!(bid.params.auId || (bid.params.member && bid.params.invCode)); + return !!(bid.bidId || (bid.params.member && bid.params.invCode)); }, buildRequests: function (validBidRequests) { @@ -42,28 +42,34 @@ export const spec = { }, interpretResponse: function (serverResponse, bidRequest) { - const bidResponses = []; - const serverBody = serverResponse.body; - - for (var k = 0; k < serverBody.adUnits.length; k++) { - const adUnit = serverBody.adUnits[k] - if (adUnit.matchedAdCount > 0) { + const adUnits = serverResponse.body.adUnits; + const bidResponsesById = adUnits.reduce((response, adUnit) => { + if (adUnit.matchedAdCount >= 1) { const bid = adUnit.ads[0]; const effectiveCpm = (bid.cpc && bid.cpm) ? bid.bid.amount + bid.cpm.amount : (bid.cpc) ? bid.bid.amount : (bid.cpm) ? bid.cpm.amount : 0; - bidResponses.push({ - requestId: bidRequest.bid[k].bidId, - cpm: effectiveCpm, - width: Number(bid.creativeWidth), - height: Number(bid.creativeHeight), - creativeId: bid.creativeId, - currency: (bid.bid) ? bid.bid.currency : 'EUR', - netRevenue: false, - ttl: 360, - ad: adUnit.html - }); - } - } - return bidResponses; + return { + ...response, + [adUnit.targetId]: { + requestId: adUnit.targetId, + cpm: effectiveCpm, + width: Number(bid.creativeWidth), + height: Number(bid.creativeHeight), + creativeId: bid.creativeId, + currency: (bid.bid) ? bid.bid.currency : 'EUR', + netRevenue: false, + ttl: 360, + ad: adUnit.html + } + } + } else return response + }, {}); + + const bidResponse = bidRequest.bid.map(bid => bid.bidId) + .reduce((request, adunitId) => + request.concat(bidResponsesById[adunitId]) + , []); + + return bidResponse }, } diff --git a/test/spec/modules/adnuntiusBidAdapter_spec.js b/test/spec/modules/adnuntiusBidAdapter_spec.js index c2aa09fafaa7..44afa5c59e4a 100644 --- a/test/spec/modules/adnuntiusBidAdapter_spec.js +++ b/test/spec/modules/adnuntiusBidAdapter_spec.js @@ -7,23 +7,33 @@ describe('adnuntiusBidAdapter', function () { const tzo = new Date().getTimezoneOffset(); const ENDPOINT_URL = `https://delivery.adnuntius.com/i?tzo=${tzo}&format=json`; const adapter = newBidder(spec); + const bidRequests = [ { + bidId: '123', bidder: 'adnuntius', params: { auId: '8b6bc', network: 'adnuntius', }, - bidId: '123' + } - ]; + ] + + const singleBidRequest = { + bid: [ + { + bidId: '123', + } + ] + } const serverResponse = { body: { 'adUnits': [ { 'auId': '000000000008b6bc', - 'targetId': '', + 'targetId': '123', 'html': '

hi!

', 'matchedAdCount': 1, 'responseId': 'adn-rsp-1460129238', @@ -103,10 +113,8 @@ describe('adnuntiusBidAdapter', function () { describe('interpretResponse', function () { it('should return valid response when passed valid server response', function () { - const request = spec.buildRequests(bidRequests); - const interpretedResponse = spec.interpretResponse(serverResponse, request[0]); + const interpretedResponse = spec.interpretResponse(serverResponse, singleBidRequest); const ad = serverResponse.body.adUnits[0].ads[0] - const cpm = (ad.cpc && ad.cpm) ? ad.bid.amount + ad.cpm.amount : (ad.cpm) ? ad.cpm.amount : 0; expect(interpretedResponse).to.have.lengthOf(1); expect(interpretedResponse[0].cpm).to.equal(ad.cpm.amount);