Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
shakhaltb committed Oct 12, 2022
1 parent cbc2574 commit f5fa3f7
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 12 deletions.
2 changes: 1 addition & 1 deletion modules/taboolaBidAdapter.js
Original file line number Diff line number Diff line change
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 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 f5fa3f7

Please sign in to comment.