Skip to content

Commit

Permalink
Eskimi Bid Adapter: fix ORTB blocking param forwarding
Browse files Browse the repository at this point in the history
  • Loading branch information
mrobakowski committed Jun 6, 2023
1 parent acfd635 commit 053df1d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 22 deletions.
30 changes: 15 additions & 15 deletions modules/eskimiBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ortbConverter } from '../libraries/ortbConverter/converter.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import {ortbConverter} from '../libraries/ortbConverter/converter.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER, VIDEO} from '../src/mediaTypes.js';
import * as utils from '../src/utils.js';

const BIDDER_CODE = 'eskimi';
Expand Down Expand Up @@ -114,14 +114,14 @@ function buildRequests(validBids, bidderRequest) {
}

function interpretResponse(response, request) {
return CONVERTER.fromORTB({ request: request.data, response: response.body }).bids;
return CONVERTER.fromORTB({request: request.data, response: response.body}).bids;
}

function buildVideoImp(bidRequest, imp) {
const videoAdUnitParams = utils.deepAccess(bidRequest, `mediaTypes.${VIDEO}`, {});
const videoBidderParams = utils.deepAccess(bidRequest, `params.${VIDEO}`, {});

const videoParams = { ...videoAdUnitParams, ...videoBidderParams };
const videoParams = {...videoAdUnitParams, ...videoBidderParams};

const videoSizes = (videoAdUnitParams && videoAdUnitParams.playerSize) || [];

Expand All @@ -140,14 +140,14 @@ function buildVideoImp(bidRequest, imp) {
imp.video.placement = imp.video.placement || 4;
}

return { ...imp };
return {...imp};
}

function buildBannerImp(bidRequest, imp) {
const bannerAdUnitParams = utils.deepAccess(bidRequest, `mediaTypes.${BANNER}`, {});
const bannerBidderParams = utils.deepAccess(bidRequest, `params.${BANNER}`, {});

const bannerParams = { ...bannerAdUnitParams, ...bannerBidderParams };
const bannerParams = {...bannerAdUnitParams, ...bannerBidderParams};

let sizes = bidRequest.mediaTypes.banner.sizes;

Expand All @@ -162,15 +162,15 @@ function buildBannerImp(bidRequest, imp) {
}
});

return { ...imp };
return {...imp};
}

function createRequest(bidRequests, bidderRequest, mediaType) {
const data = CONVERTER.toORTB({ bidRequests, bidderRequest, context: { mediaType } })
const data = CONVERTER.toORTB({bidRequests, bidderRequest, context: {mediaType}})

let bid = bidRequests.find((b) => b.params.placementId)
const bid = bidRequests.find((b) => b.params.placementId)
if (!data.site) data.site = {}
data.site.ext = { placementId: bid.params.placementId }
data.site.ext = {placementId: bid.params.placementId}

if (bidderRequest.gdprConsent) {
if (!data.user) data.user = {};
Expand All @@ -181,15 +181,15 @@ function createRequest(bidRequests, bidderRequest, mediaType) {
data.regs.ext.gdpr = bidderRequest.gdprConsent.gdprApplies ? 1 : 0;
}

if (bid.bcat) data.bcat = bid.bcat;
if (bid.badv) data.badv = bid.badv;
if (bid.bapp) data.bapp = bid.bapp;
if (bid.params.bcat) data.bcat = bid.params.bcat;
if (bid.params.badv) data.badv = bid.params.badv;
if (bid.params.bapp) data.bapp = bid.params.bapp;

return {
method: 'POST',
url: ENDPOINT,
data: data,
options: { contentType: 'application/json;charset=UTF-8', withCredentials: false }
options: {contentType: 'application/json;charset=UTF-8', withCredentials: false}
}
}

Expand Down
31 changes: 24 additions & 7 deletions test/spec/modules/eskimiBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import { spec } from 'modules/eskimiBidAdapter.js';
import {expect} from 'chai';
import {spec} from 'modules/eskimiBidAdapter.js';
import * as utils from 'src/utils';

const BANNER_BID = {
Expand Down Expand Up @@ -138,14 +138,14 @@ describe('Eskimi bid adapter', function () {
};
expect(spec.isBidRequestValid(bid)).to.equal(false);
});
});

describe('buildRequests()', function () {
it('should return true when required params found', () => {
expect(spec.isBidRequestValid(BANNER_BID)).to.equal(true);
expect(spec.isBidRequestValid(VIDEO_BID)).to.equal(true);
});
});

describe('buildRequests()', function () {
it('should have gdpr data if applicable', function () {
const bid = utils.deepClone(BANNER_BID);

Expand All @@ -162,6 +162,23 @@ describe('Eskimi bid adapter', function () {
expect(payload.regs.ext).to.have.property('gdpr', 1);
});

it('should properly forward ORTB blocking params', function () {
let bid = utils.deepClone(BANNER_BID);
bid = utils.mergeDeep(bid, {
params: {bcat: ['IAB1-1'], badv: ['example.com'], bapp: ['com.example']},
mediaTypes: {banner: {battr: [1]}}
});

let [request] = spec.buildRequests([bid], BIDDER_REQUEST);

expect(request).to.exist.and.to.be.an('object');
const payload = request.data;
expect(payload).to.have.deep.property('bcat', ['IAB1-1']);
expect(payload).to.have.deep.property('badv', ['example.com']);
expect(payload).to.have.deep.property('bapp', ['com.example']);
expect(payload.imp[0].banner).to.have.deep.property('battr', [1]);
});

context('when mediaType is banner', function () {
it('should build correct request for banner bid with both w, h', () => {
const bid = utils.deepClone(BANNER_BID);
Expand Down Expand Up @@ -236,7 +253,7 @@ describe('Eskimi bid adapter', function () {
const [request] = spec.buildRequests([bid], BIDDER_REQUEST);
const response = utils.deepClone(BANNER_BID_RESPONSE);

const bids = spec.interpretResponse({ body: response }, request);
const bids = spec.interpretResponse({body: response}, request);
expect(bids).to.be.an('array').that.is.not.empty;

expect(bids[0].mediaType).to.equal('banner');
Expand All @@ -257,7 +274,7 @@ describe('Eskimi bid adapter', function () {
const bid = utils.deepClone(BANNER_BID);

let request = spec.buildRequests([bid], BIDDER_REQUEST)[0];
const EMPTY_RESP = Object.assign({}, BANNER_BID_RESPONSE, { 'body': {} });
const EMPTY_RESP = Object.assign({}, BANNER_BID_RESPONSE, {'body': {}});
const bids = spec.interpretResponse(EMPTY_RESP, request);
expect(bids).to.be.empty;
});
Expand All @@ -268,7 +285,7 @@ describe('Eskimi bid adapter', function () {
const bid = utils.deepClone(VIDEO_BID);

const [request] = spec.buildRequests([bid], BIDDER_REQUEST);
const bids = spec.interpretResponse({ body: VIDEO_BID_RESPONSE }, request);
const bids = spec.interpretResponse({body: VIDEO_BID_RESPONSE}, request);
expect(bids).to.be.an('array').that.is.not.empty;

expect(bids[0].mediaType).to.equal('video');
Expand Down

0 comments on commit 053df1d

Please sign in to comment.