Skip to content

Commit

Permalink
Support for InBannerVideo (IBV) Field in Bid Response (#12453)
Browse files Browse the repository at this point in the history
  • Loading branch information
pm-nitin-shirsat authored Nov 15, 2024
1 parent ee12e82 commit f44c6cf
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 1 deletion.
9 changes: 9 additions & 0 deletions modules/pubmaticBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,14 @@ function _handleEids(payload, validBidRequests) {
}
}

// Setting IBV field into the bid response
export function setIBVField(bid, newBid) {
if (bid?.ext?.ibv) {
newBid.ext = newBid.ext || {};
newBid.ext['ibv'] = bid.ext.ibv;
}
}

function _checkMediaType(bid, newBid) {
// Create a regex here to check the strings
if (bid.ext && bid.ext['bidtype'] != undefined) {
Expand Down Expand Up @@ -1401,6 +1409,7 @@ export const spec = {
}
});
}
setIBVField(bid, newBid);
if (bid.ext && bid.ext.deal_channel) {
newBid['dealChannel'] = dealChannelValues[bid.ext.deal_channel] || null;
}
Expand Down
72 changes: 71 additions & 1 deletion test/spec/modules/pubmaticBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import { spec, checkVideoPlacement, _getDomainFromURL, assignDealTier, prepareMetaObject, getDeviceConnectionType } from 'modules/pubmaticBidAdapter.js';
import { spec, checkVideoPlacement, _getDomainFromURL, assignDealTier, prepareMetaObject, getDeviceConnectionType, setIBVField } from 'modules/pubmaticBidAdapter.js';
import * as utils from 'src/utils.js';
import { config } from 'src/config.js';
import { createEidsArray } from 'modules/userId/eids.js';
Expand Down Expand Up @@ -3579,6 +3579,30 @@ describe('PubMatic adapter', function () {
expect(response[0].renderer).to.not.exist;
});

it('should set ibv field in bid.ext when bid.ext.ibv exists', function() {
let request = spec.buildRequests(bidRequests, {
auctionId: 'new-auction-id'
});

let copyOfBidResponse = utils.deepClone(bannerBidResponse);
let bidExt = utils.deepClone(copyOfBidResponse.body.seatbid[0].bid[0].ext);
copyOfBidResponse.body.seatbid[0].bid[0].ext = Object.assign(bidExt, {
ibv: true
});

let response = spec.interpretResponse(copyOfBidResponse, request);
expect(response[0].ext.ibv).to.equal(true);
});

it('should not set ibv field when bid.ext does not exist ', function() {
let request = spec.buildRequests(bidRequests, {
auctionId: 'new-auction-id'
});

let response = spec.interpretResponse(bannerBidResponse, request);
expect(response[0].ext).to.not.exist;
});

if (FEATURES.VIDEO) {
it('should check for valid video mediaType in case of multiformat request', function() {
let request = spec.buildRequests(videoBidRequests, {
Expand Down Expand Up @@ -4176,6 +4200,52 @@ describe('PubMatic adapter', function () {
expect(data.imp[0]['banner']['battr']).to.equal(undefined);
});
});

describe('setIBVField', function() {
it('should set ibv field in newBid.ext when bid.ext.ibv exists', function() {
const bid = {
ext: {
ibv: true
}
};
const newBid = {};
setIBVField(bid, newBid);
expect(newBid.ext).to.exist;
expect(newBid.ext.ibv).to.equal(true);
});

it('should not set ibv field when bid.ext.ibv does not exist', function() {
const bid = {
ext: {}
};
const newBid = {};
setIBVField(bid, newBid);
expect(newBid.ext).to.not.exist;
});

it('should not set ibv field when bid.ext does not exist', function() {
const bid = {};
const newBid = {};
setIBVField(bid, newBid);
expect(newBid.ext).to.not.exist;
});

it('should preserve existing newBid.ext properties', function() {
const bid = {
ext: {
ibv: true
}
};
const newBid = {
ext: {
existingProp: 'should remain'
}
};
setIBVField(bid, newBid);
expect(newBid.ext.existingProp).to.equal('should remain');
expect(newBid.ext.ibv).to.equal(true);
});
});
});

if (FEATURES.VIDEO) {
Expand Down

0 comments on commit f44c6cf

Please sign in to comment.