Skip to content

Commit

Permalink
viantOrtbBidAdapter': deals support (#11864)
Browse files Browse the repository at this point in the history
* Added deals support in viantOrtbBidAdapter

* refactoring

* refactor

* refactor

* refactor

* refactor

* added test case

* refactor

* refactor test file

* added test case and addressed suggestions
  • Loading branch information
skapoorViant committed Jun 28, 2024
1 parent 2f72b57 commit 75e3375
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 6 deletions.
20 changes: 20 additions & 0 deletions modules/viantOrtbBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {deepAccess, getBidIdParameter, logError} from '../src/utils.js';

const BIDDER_CODE = 'viant';
const ENDPOINT = 'https://bidders-us-east-1.adelphic.net/d/rtb/v25/prebid/bidder'
const ADAPTER_VERSION = '2.0.0';

const DEFAULT_BID_TTL = 300;
const DEFAULT_CURRENCY = 'USD';
Expand Down Expand Up @@ -85,6 +86,25 @@ function createRequest(bidRequests, bidderRequest, mediaType) {
if (!data.regs.ext) data.regs.ext = {};
data.regs.ext.us_privacy = bidderRequest.uspConsent;
}
let imp = data.imp || [];
let dealsMap = new Map();
if (bidderRequest.bids) {
bidderRequest.bids.forEach(bid => {
if (bid.ortb2Imp && bid.ortb2Imp.pmp) {
dealsMap.set(bid.bidId, bid.ortb2Imp.pmp);
}
});
}
imp.forEach((element) => {
let deals = dealsMap.get(element.id);
if (deals) {
element.pmp = deals;
}
});
data.ext = data.ext || {};
data.ext.viant = {
adapterVersion: ADAPTER_VERSION
};
return {
method: 'POST',
url: ENDPOINT,
Expand Down
93 changes: 87 additions & 6 deletions test/spec/modules/viantOrtbBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { spec, converter } from 'modules/viantOrtbBidAdapter.js';
import {spec, converter} from 'modules/viantOrtbBidAdapter.js';
import {assert, expect} from 'chai';
import { deepClone } from '../../../src/utils';
import {deepClone} from '../../../src/utils';
import {buildWindowTree} from '../../helpers/refererDetectionHelper';
import {detectReferer} from '../../../src/refererDetection';

describe('viantOrtbBidAdapter', function () {
function testBuildRequests(bidRequests, bidderRequestBase) {
let clonedBidderRequest = deepClone(bidderRequestBase);
clonedBidderRequest.bids = bidRequests;
let requests = spec.buildRequests(bidRequests, clonedBidderRequest);
return requests
}
describe('isBidRequestValid', function() {

describe('isBidRequestValid', function () {
function makeBid() {
return {
'bidder': 'viant',
Expand Down Expand Up @@ -46,9 +48,7 @@ describe('viantOrtbBidAdapter', function () {
it('should return true if placementId is not passed ', function () {
let bid = makeBid();
delete bid.params.placementId;
bid.ortb2Imp = {

}
bid.ortb2Imp = {}
expect(spec.isBidRequestValid(bid)).to.equal(true);
});

Expand Down Expand Up @@ -98,6 +98,7 @@ describe('viantOrtbBidAdapter', function () {
'transactionId': '4008d88a-8137-410b-aa35-fbfdabcb478e'
}
}

it('should return true when required params found', function () {
expect(spec.isBidRequestValid(makeBid())).to.equal(true);
});
Expand Down Expand Up @@ -141,6 +142,7 @@ describe('viantOrtbBidAdapter', function () {
'transactionId': '4008d88a-8137-410b-aa35-fbfdabcb478e'
}
}

it('should return true when required params found', function () {
expect(spec.isBidRequestValid(makeBid())).to.equal(true);
});
Expand Down Expand Up @@ -180,6 +182,57 @@ describe('viantOrtbBidAdapter', function () {
'src': 'client',
'bidRequestsCount': 1
}];
const basePMPDealsBidRequests = [{
'bidder': 'viant',
'params': {
'publisherId': '464',
'placementId': '1'
},
'ortb2Imp': {
'pmp': {
'private_auction': 0,
'deals': [
{
'id': '1234567',
'at': 3,
'bidfloor': 25,
'bidfloorcur': 'USD',
'ext': {
'must_bid': 1,
'private_auction': 1
}
},
{
'id': '1234568',
'at': 3,
'bidfloor': 25,
'bidfloorcur': 'USD',
'ext': {
'must_bid': 0
}
}
]
},
},
'mediaTypes': {
'banner': {
'sizes': [[728, 90]]
}
},
'gdprConsent': {
'consentString': 'consentString',
'gdprApplies': true,
},
'uspConsent': '1YYY',
'sizes': [[728, 90]],
'transactionId': '1111474f-58b1-4368-b812-84f8c937a099',
'adUnitCode': 'div-gpt-ad-1460505748561-0',
'bidId': '243310435309b5',
'bidderRequestId': '18084284054531',
'auctionId': 'e7b34fa3-8654-424e-8c49-03e509e53d8c',
'src': 'client',
'bidRequestsCount': 1
}];

const testWindow = buildWindowTree(['https://www.example.com/test', 'https://www.example.com/other/page', 'https://www.example.com/third/page'], 'https://othersite.com/', 'https://example.com/canonical/page');
const baseBidderRequestReferer = detectReferer(testWindow)();
Expand Down Expand Up @@ -236,6 +289,34 @@ describe('viantOrtbBidAdapter', function () {
const requestBody = testBuildRequests(clonedBannerRequests, baseBidderRequest)[0].data;
expect(requestBody.imp[0].banner.pos).to.equal(1);
});
it('includes the deals in the bid request', function () {
const requestBody = testBuildRequests(basePMPDealsBidRequests, baseBidderRequest)[0].data;
expect(requestBody.imp[0].pmp).to.be.not.null;
expect(requestBody.imp[0].pmp).to.deep.equal({
'private_auction': 0,
'deals': [
{
'id': '1234567',
'at': 3,
'bidfloor': 25,
'bidfloorcur': 'USD',
'ext': {
'must_bid': 1,
'private_auction': 1
}
},
{
'id': '1234568',
'at': 3,
'bidfloor': 25,
'bidfloorcur': 'USD',
'ext': {
'must_bid': 0
}
}
]
});
});
});

if (FEATURES.VIDEO) {
Expand Down

0 comments on commit 75e3375

Please sign in to comment.