From 2dedab6b7f67b1c77009ef4e8feaba4c32c4a57d Mon Sep 17 00:00:00 2001 From: pm-nitin-shirsat Date: Wed, 12 Oct 2022 11:21:17 +0530 Subject: [PATCH 1/3] Implement functionality for deal priority --- modules/pubmaticBidAdapter.js | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/modules/pubmaticBidAdapter.js b/modules/pubmaticBidAdapter.js index 7f346b1c7b0..11163d4ac43 100644 --- a/modules/pubmaticBidAdapter.js +++ b/modules/pubmaticBidAdapter.js @@ -1,10 +1,11 @@ -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'; +import { INSTREAM } from '../src/video.js'; const BIDDER_CODE = 'pubmatic'; const LOG_WARN_PREFIX = 'PubMatic: '; @@ -953,6 +954,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) { @@ -1265,6 +1289,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); From afae8882289465cd29e5f7e53ef7b2b716f648be Mon Sep 17 00:00:00 2001 From: pm-nitin-shirsat Date: Wed, 12 Oct 2022 14:31:01 +0530 Subject: [PATCH 2/3] Update test cases --- modules/pubmaticBidAdapter.js | 1 - test/spec/modules/pubmaticBidAdapter_spec.js | 63 ++++++++++++++++++-- 2 files changed, 59 insertions(+), 5 deletions(-) diff --git a/modules/pubmaticBidAdapter.js b/modules/pubmaticBidAdapter.js index 11163d4ac43..02198042474 100644 --- a/modules/pubmaticBidAdapter.js +++ b/modules/pubmaticBidAdapter.js @@ -5,7 +5,6 @@ import { config } from '../src/config.js'; import { Renderer } from '../src/Renderer.js'; import { bidderSettings } from '../src/bidderSettings.js'; import { convertOrtbRequestToProprietaryNative } from '../src/native.js'; -import { INSTREAM } from '../src/video.js'; const BIDDER_CODE = 'pubmatic'; const LOG_WARN_PREFIX = 'PubMatic: '; diff --git a/test/spec/modules/pubmaticBidAdapter_spec.js b/test/spec/modules/pubmaticBidAdapter_spec.js index 3f341fd259f..f554d57290d 100644 --- a/test/spec/modules/pubmaticBidAdapter_spec.js +++ b/test/spec/modules/pubmaticBidAdapter_spec.js @@ -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'); @@ -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); From 9447e84c683e36351258e450b4475690fac0d5eb Mon Sep 17 00:00:00 2001 From: Chris Huie Date: Thu, 13 Oct 2022 08:11:59 -0700 Subject: [PATCH 3/3] kick off test manually --- test/spec/modules/pubmaticBidAdapter_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/spec/modules/pubmaticBidAdapter_spec.js b/test/spec/modules/pubmaticBidAdapter_spec.js index f554d57290d..13b4e31b5c7 100644 --- a/test/spec/modules/pubmaticBidAdapter_spec.js +++ b/test/spec/modules/pubmaticBidAdapter_spec.js @@ -4137,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' });