Skip to content

Commit

Permalink
Pubmatic Bid Adapter: use new dealpriority in deal tier module execut…
Browse files Browse the repository at this point in the history
…ion (prebid#9103)

* Implement functionality for deal priority

* Update test cases

* kick off test manually

Co-authored-by: Chris Huie <phoenixtechnerd@gmail.com>
  • Loading branch information
2 people authored and JacobKlein26 committed Feb 8, 2023
1 parent 1a577a6 commit 4f6c826
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 8 deletions.
30 changes: 27 additions & 3 deletions modules/pubmaticBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { logWarn, _each, isBoolean, isStr, isArray, inIframe, mergeDeep, deepAccess, isNumber, deepSetValue, logInfo, logError, deepClone, convertTypes, uniques } from '../src/utils.js';
import { getBidRequest, logWarn, _each, isBoolean, isStr, isArray, inIframe, mergeDeep, deepAccess, isNumber, deepSetValue, logInfo, logError, deepClone, convertTypes, uniques } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, VIDEO, NATIVE } from '../src/mediaTypes.js';
import {config} from '../src/config.js';
import { BANNER, VIDEO, NATIVE, ADPOD } from '../src/mediaTypes.js';
import { config } from '../src/config.js';
import { Renderer } from '../src/Renderer.js';
import { bidderSettings } from '../src/bidderSettings.js';
import { convertOrtbRequestToProprietaryNative } from '../src/native.js';
Expand Down Expand Up @@ -953,6 +953,29 @@ function _assignRenderer(newBid, request) {
}
}

/**
* In case of adpod video context, assign prebiddealpriority to the dealtier property of adpod-video bid,
* so that adpod module can set the hb_pb_cat_dur targetting key.
* @param {*} newBid
* @param {*} bid
* @param {*} request
* @returns
*/
export function assignDealTier(newBid, bid, request) {
if (!bid?.ext?.prebiddealpriority) return;
const bidRequest = getBidRequest(newBid.requestId, [request.bidderRequest]);
const videoObj = deepAccess(bidRequest, 'mediaTypes.video');
if (videoObj?.context != ADPOD) return;

const duration = bid?.ext?.video?.duration || videoObj?.maxduration;
// if (!duration) return;
newBid.video = {
context: ADPOD,
durationSeconds: duration,
dealTier: bid.ext.prebiddealpriority
};
}

function isNonEmptyArray(test) {
if (isArray(test) === true) {
if (test.length > 0) {
Expand Down Expand Up @@ -1265,6 +1288,7 @@ export const spec = {
newBid.height = bid.hasOwnProperty('h') ? bid.h : req.video.h;
newBid.vastXml = bid.adm;
_assignRenderer(newBid, request);
assignDealTier(newBid, bid, request);
break;
case NATIVE:
_parseNativeResponse(bid, newBid);
Expand Down
65 changes: 60 additions & 5 deletions test/spec/modules/pubmaticBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {expect} from 'chai';
import {spec, checkVideoPlacement, _getDomainFromURL} from 'modules/pubmaticBidAdapter.js';
import { expect } from 'chai';
import { spec, checkVideoPlacement, _getDomainFromURL, assignDealTier } from 'modules/pubmaticBidAdapter.js';
import * as utils from 'src/utils.js';
import {config} from 'src/config.js';
import { config } from 'src/config.js';
import { createEidsArray } from 'modules/userId/eids.js';
import { bidderSettings } from 'src/bidderSettings.js';
const constants = require('src/constants.json');
Expand Down Expand Up @@ -4063,9 +4063,64 @@ describe('PubMatic adapter', function () {
expect(data.imp[0]['video']['h']).to.equal(videoBidRequests[0].mediaTypes.video.playerSize[1]);
expect(data.imp[0]['video']['battr']).to.equal(undefined);
});

describe('Assign Deal Tier (i.e. prebidDealPriority)', function () {
let videoSeatBid, request, newBid;
// let data = JSON.parse(request.data);
beforeEach(function () {
videoSeatBid = videoBidResponse.body.seatbid[0].bid[0];
// const adpodValidOutstreamBidRequest = validOutstreamBidRequest.bids[0].mediaTypes.video.context = 'adpod';
request = spec.buildRequests(bidRequests, validOutstreamBidRequest);
newBid = {
requestId: '47acc48ad47af5'
};
videoSeatBid.ext = videoSeatBid.ext || {};
videoSeatBid.ext.video = videoSeatBid.ext.video || {};
// videoBidRequests[0].mediaTypes.video = videoBidRequests[0].mediaTypes.video || {};
});

it('should not assign video object if deal priority is missing', function () {
assignDealTier(newBid, videoSeatBid, request);
expect(newBid.video).to.equal(undefined);
expect(newBid.video).to.not.exist;
});

it('should not assign video object if context is not a adpod', function () {
videoSeatBid.ext.prebiddealpriority = 5;
assignDealTier(newBid, videoSeatBid, request);
expect(newBid.video).to.equal(undefined);
expect(newBid.video).to.not.exist;
});

describe('when video deal tier object is present', function () {
beforeEach(function () {
videoSeatBid.ext.prebiddealpriority = 5;
request.bidderRequest.bids[0].mediaTypes.video = {
...request.bidderRequest.bids[0].mediaTypes.video,
context: 'adpod',
maxduration: 50
};
});

it('should set video deal tier object, when maxduration is present in ext', function () {
assignDealTier(newBid, videoSeatBid, request);
expect(newBid.video.durationSeconds).to.equal(50);
expect(newBid.video.context).to.equal('adpod');
expect(newBid.video.dealTier).to.equal(5);
});

it('should set video deal tier object, when duration is present in ext', function () {
videoSeatBid.ext.video.duration = 20;
assignDealTier(newBid, videoSeatBid, request);
expect(newBid.video.durationSeconds).to.equal(20);
expect(newBid.video.context).to.equal('adpod');
expect(newBid.video.dealTier).to.equal(5);
});
});
});
});

describe('Marketplace params', function() {
describe('Marketplace params', function () {
let sandbox, utilsMock, newBidRequests, newBidResponses;
beforeEach(() => {
utilsMock = sinon.mock(utils);
Expand All @@ -4082,7 +4137,7 @@ describe('PubMatic adapter', function () {
sandbox.restore();
})

it('Should add bidder code as groupm for marketplace groupm response', function () {
it('Should add bidder code as groupm for marketplace groupm response ', function () {
let request = spec.buildRequests(newBidRequests, {
auctionId: 'new-auction-id'
});
Expand Down

0 comments on commit 4f6c826

Please sign in to comment.