From cbc2574640ea7a3457fefb80909e2a14fe748af2 Mon Sep 17 00:00:00 2001 From: "jenny.l" Date: Tue, 11 Oct 2022 16:58:25 +0300 Subject: [PATCH 1/2] fix bid response in case we have multiple impressions --- modules/taboolaBidAdapter.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/taboolaBidAdapter.js b/modules/taboolaBidAdapter.js index 13f04848d..296ef1a1a 100644 --- a/modules/taboolaBidAdapter.js +++ b/modules/taboolaBidAdapter.js @@ -147,7 +147,7 @@ export const spec = { return []; } - return bids.map((bid, id) => getBid(bid.bidId, currency, bidResponses[id])).filter(Boolean); + return bidResponses.map((bidResponse) => getBid(bids, currency, bidResponse)).filter(Boolean); }, }; @@ -214,14 +214,14 @@ function getBidResponses({body}) { }; } -function getBid(requestId, currency, bidResponse) { +function getBid(bids, currency, bidResponse) { if (!bidResponse) { return; } const { price: cpm, crid: creativeId, adm: ad, w: width, h: height, exp: ttl, adomain: advertiserDomains, meta = {} } = bidResponse; - + let requestId = bids[bidResponse.impid - 1].bidId; if (advertiserDomains && advertiserDomains.length > 0) { meta.advertiserDomains = advertiserDomains } From f5fa3f7e53163d443ba354d873074215a638b2fc Mon Sep 17 00:00:00 2001 From: Shakhal Levinson Date: Wed, 12 Oct 2022 15:49:55 +0300 Subject: [PATCH 2/2] add test --- modules/taboolaBidAdapter.js | 2 +- test/spec/modules/taboolaBidAdapter_spec.js | 121 ++++++++++++++++++-- 2 files changed, 111 insertions(+), 12 deletions(-) diff --git a/modules/taboolaBidAdapter.js b/modules/taboolaBidAdapter.js index 296ef1a1a..d4bf6623f 100644 --- a/modules/taboolaBidAdapter.js +++ b/modules/taboolaBidAdapter.js @@ -204,7 +204,7 @@ function getBidResponses({body}) { const {seatbid, cur} = body; - if (!seatbid.length || !seatbid[0].bid) { + if (!seatbid.length || !seatbid[0].bid || !seatbid[0].bid.length) { return []; } diff --git a/test/spec/modules/taboolaBidAdapter_spec.js b/test/spec/modules/taboolaBidAdapter_spec.js index b41a17a8e..be612543e 100644 --- a/test/spec/modules/taboolaBidAdapter_spec.js +++ b/test/spec/modules/taboolaBidAdapter_spec.js @@ -4,7 +4,7 @@ import {config} from '../../../src/config' import * as utils from '../../../src/utils' describe('Taboola Adapter', function () { - let hasLocalStorage, cookiesAreEnabled, getDataFromLocalStorage, localStorageIsEnabled, getCookie; + let hasLocalStorage, cookiesAreEnabled, getDataFromLocalStorage, localStorageIsEnabled, getCookie, commonBidRequest; beforeEach(() => { hasLocalStorage = sinon.stub(userData.storageManager, 'hasLocalStorage'); @@ -12,7 +12,7 @@ describe('Taboola Adapter', function () { getCookie = sinon.stub(userData.storageManager, 'getCookie'); getDataFromLocalStorage = sinon.stub(userData.storageManager, 'getDataFromLocalStorage'); localStorageIsEnabled = sinon.stub(userData.storageManager, 'localStorageIsEnabled'); - + commonBidRequest = createBidRequest(); $$PREBID_GLOBAL$$.bidderSettings = { taboola: { storageAllowed: true @@ -30,19 +30,19 @@ describe('Taboola Adapter', function () { $$PREBID_GLOBAL$$.bidderSettings = {}; }) - const commonBidRequest = { + const displayBidRequestParams = { + sizes: [[300, 250], [300, 600]] + } + + const createBidRequest = () => ({ bidder: 'taboola', params: { publisherId: 'publisherId', tagId: 'placement name' }, - bidId: 'aa43860a-4644-442a-b5e0-93f268cs4d19', - auctionId: '65746dca-26f3-4186-be13-dfa63469b1b7', - } - - const displayBidRequestParams = { - sizes: [[300, 250], [300, 600]] - } + bidId: utils.generateUUID(), + auctionId: utils.generateUUID(), + }); describe('isBidRequestValid', function () { it('should fail when bid is invalid - tagId isn`t defined', function () { @@ -132,7 +132,7 @@ describe('Taboola Adapter', function () { describe('buildRequests', function () { const defaultBidRequest = { - ...commonBidRequest, + ...createBidRequest(), ...displayBidRequestParams, } @@ -441,6 +441,105 @@ describe('Taboola Adapter', function () { overriddenServerResponse.body.seatbid[0].bid = bid; }); + it('should interpret multi impression request', function () { + const multiRequest = { + bids: [ + { + ...createBidRequest(), + ...displayBidRequestParams + }, + { + ...createBidRequest(), + ...displayBidRequestParams + } + ] + } + + const multiServerResponse = { + body: { + 'id': '49ffg4d58ef9a163a69fhgfghd4fad03621b9e036f24f7_15', + 'seatbid': [ + { + 'bid': [ + { + 'id': '0b3dd94348-134b-435f-8db5-6bf5afgfc39e86c', + 'impid': '2', + 'price': 0.342068, + 'adid': '2785119545551083381', + 'adm': 'ADM2', + 'adomain': [ + 'example.xyz' + ], + 'cid': '15744349', + 'crid': '278195503434041083381', + 'w': 300, + 'h': 250, + 'exp': 60, + 'lurl': 'http://us-trc.taboola.com/sample' + }, + { + 'id': '0b3dd94348-134b-435f-8db5-6bf5afgfc39e86c', + 'impid': '1', + 'price': 0.342068, + 'adid': '2785119545551083381', + 'adm': 'ADM1', + 'adomain': [ + 'example.xyz' + ], + 'cid': '15744349', + 'crid': '278195503434041083381', + 'w': 300, + 'h': 250, + 'exp': 60, + 'lurl': 'http://us-trc.taboola.com/sample' + } + ], + 'seat': '14204545260' + } + ], + 'bidid': 'da43860a-4644-442a-b5e0-93f268cf8d19', + 'cur': 'USD' + } + }; + + const [bid] = multiServerResponse.body.seatbid[0].bid; + const expectedRes = [ + { + requestId: multiRequest.bids[1].bidId, + cpm: bid.price, + creativeId: bid.crid, + ttl: 60, + netRevenue: true, + currency: multiServerResponse.body.cur, + mediaType: 'banner', + ad: multiServerResponse.body.seatbid[0].bid[0].adm, + width: bid.w, + height: bid.h, + meta: { + 'advertiserDomains': bid.adomain + }, + }, + { + requestId: multiRequest.bids[0].bidId, + cpm: bid.price, + creativeId: bid.crid, + ttl: 60, + netRevenue: true, + currency: multiServerResponse.body.cur, + mediaType: 'banner', + ad: multiServerResponse.body.seatbid[0].bid[1].adm, + width: bid.w, + height: bid.h, + meta: { + 'advertiserDomains': bid.adomain + }, + } + ] + + const res = spec.interpretResponse(multiServerResponse, multiRequest) + expect(res).to.deep.equal(expectedRes) + }); + it('should interpret display response', function () { const [bid] = serverResponse.body.seatbid[0].bid; const expectedRes = [