Skip to content

Commit

Permalink
Merge pull request #13 from taboola/Fix_Response
Browse files Browse the repository at this point in the history
fix bid response in case we have multiple impressions
  • Loading branch information
shakhaltb committed Oct 12, 2022
2 parents 35c800a + f5fa3f7 commit a90c2ef
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 15 deletions.
8 changes: 4 additions & 4 deletions modules/taboolaBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
};

Expand Down Expand Up @@ -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 [];
}

Expand All @@ -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
}
Expand Down
121 changes: 110 additions & 11 deletions test/spec/modules/taboolaBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ 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');
cookiesAreEnabled = sinon.stub(userData.storageManager, 'cookiesAreEnabled');
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
Expand All @@ -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 () {
Expand Down Expand Up @@ -132,7 +132,7 @@ describe('Taboola Adapter', function () {

describe('buildRequests', function () {
const defaultBidRequest = {
...commonBidRequest,
...createBidRequest(),
...displayBidRequestParams,
}

Expand Down Expand Up @@ -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 = [
Expand Down

0 comments on commit a90c2ef

Please sign in to comment.