Skip to content

Commit

Permalink
Vox Bid Addapter: add schain, floors, userid support (prebid#10109)
Browse files Browse the repository at this point in the history
* vox bid adapter: add schain, floors, userid support

* vox bid adapter: add schain, floors, userid support

* vox bid adapter: add schain, floors, userid support

* vox bid adapter: add schain, floors, userid support

* vox bid adapter: add schain, floors, userid support
  • Loading branch information
hybrid-ai committed Jul 10, 2023
1 parent bdd0f9d commit 7cf0274
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 5 deletions.
21 changes: 16 additions & 5 deletions modules/voxBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,31 @@ import {BANNER, VIDEO} from '../src/mediaTypes.js';
import {find} from '../src/polyfill.js';
import {auctionManager} from '../src/auctionManager.js';
import {Renderer} from '../src/Renderer.js';
import {config} from '../src/config.js'

const { getConfig } = config;

const BIDDER_CODE = 'vox';
const SSP_ENDPOINT = 'https://ssp.hybrid.ai/auction/prebid';
const VIDEO_RENDERER_URL = 'https://acdn.adnxs.com/video/outstream/ANOutstreamVideo.js';
const TTL = 60;

function buildBidRequests(validBidRequests) {
return _map(validBidRequests, function(validBidRequest) {
const params = validBidRequest.params;
return _map(validBidRequests, function(bid) {
const currency = getConfig('currency.adServerCurrency');
const floorInfo = bid.getFloor ? bid.getFloor({
currency: currency || 'USD'
}) : {};

const params = bid.params;
const bidRequest = {
bidId: validBidRequest.bidId,
floorInfo,
schain: bid.schain,
userId: bid.userId,
bidId: bid.bidId,
// TODO: fix transactionId leak: https://github.com/prebid/Prebid.js/issues/9781
transactionId: validBidRequest.transactionId,
sizes: validBidRequest.sizes,
transactionId: bid.transactionId,
sizes: bid.sizes,
placement: params.placement,
placeId: params.placementId,
imageUrl: params.imageUrl
Expand Down
93 changes: 93 additions & 0 deletions test/spec/modules/voxBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect } from 'chai'
import { spec } from 'modules/voxBidAdapter.js'
import {config} from 'src/config.js'

function getSlotConfigs(mediaTypes, params) {
return {
Expand Down Expand Up @@ -175,6 +176,98 @@ describe('VOX Adapter', function() {
expect(bid.transactionId).to.equal('31a58515-3634-4e90-9c96-f86196db1459')
})
})
it('should not set userid if not specified', function () {
const request = spec.buildRequests(validBidRequests, bidderRequest)
const data = JSON.parse(request.data)
data.bidRequests.forEach(bid => {
expect(bid.userId).to.be.undefined
})
})

it('should set userid if specified', function () {
const requests = validBidRequests.map(bid => ({
...bid,
userId: {
tdid: 'TDID_USER_ID',
pubcid: 'PUBID_USER_ID'
}
}))
const request = spec.buildRequests(requests, bidderRequest)
const data = JSON.parse(request.data)
data.bidRequests.forEach(bid => {
expect(bid.userId.tdid).to.equal('TDID_USER_ID')
expect(bid.userId.pubcid).to.equal('PUBID_USER_ID')
})
})

it('should not set schain if not specified', function () {
const request = spec.buildRequests(validBidRequests, bidderRequest)
const data = JSON.parse(request.data)
data.bidRequests.forEach(bid => {
expect(bid.schain).to.be.undefined
})
})

it('should set schain if not specified', function () {
const requests = validBidRequests.map(bid => ({
...bid,
schain: {
validation: 'strict',
config: {
ver: '1.0'
}
}
}))
const request = spec.buildRequests(requests, bidderRequest)
const data = JSON.parse(request.data)
data.bidRequests.forEach(bid => {
expect(bid.schain.validation).to.equal('strict')
expect(bid.schain.config.ver).to.equal('1.0')
})
})

describe('price floors', function () {
it('should be empty if floors module not configured', function () {
const request = spec.buildRequests(validBidRequests, bidderRequest)
const data = JSON.parse(request.data)
data.bidRequests.forEach(bid => {
expect(bid.floorInfo).to.be.empty
})
})

it('should add correct floor values', function () {
const expectedFloors = [ 2, 2.7, 1.4 ]
const validBidRequests = expectedFloors.map(getBidWithFloor)
const request = spec.buildRequests(validBidRequests, bidderRequest)
const data = JSON.parse(request.data)
expectedFloors.forEach((floor, index) => {
expect(data.bidRequests[index].floorInfo.floor).to.equal(floor)
expect(data.bidRequests[index].floorInfo.currency).to.equal('USD')
})
})

it('should request floor price in adserver currency', function () {
const configCurrency = 'DKK'
config.setConfig({ currency: { adServerCurrency: configCurrency } })
const request = spec.buildRequests([ getBidWithFloor() ], bidderRequest)
const data = JSON.parse(request.data)
data.bidRequests.forEach(bid => {
expect(bid.floorInfo.currency).to.equal(configCurrency)
})
})

function getBidWithFloor(floor) {
return {
...validBidRequests[0],
getFloor: ({ currency }) => {
return {
currency: currency,
floor
}
}
}
}
})

describe('GDPR params', function() {
describe('when there are not consent management platform', function() {
Expand Down

0 comments on commit 7cf0274

Please sign in to comment.