Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions modules/targetVideoBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {_each, deepAccess, getDefinedParams, parseGPTSingleSizeArrayToRtbSize} from '../src/utils.js';
import {_each, deepAccess, getDefinedParams, isFn, isPlainObject, parseGPTSingleSizeArrayToRtbSize} from '../src/utils.js';
import {BANNER, VIDEO} from '../src/mediaTypes.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {formatRequest, getRtbBid, getSiteObj, getSyncResponse, videoBid, bannerBid, createVideoTag} from '../libraries/targetVideoUtils/bidderUtils.js';
Expand All @@ -9,6 +9,22 @@ import {SOURCE, GVLID, BIDDER_CODE, VIDEO_PARAMS, BANNER_ENDPOINT_URL, VIDEO_END
* @typedef {import('../src/adapters/bidderFactory.js').Bid} Bid
*/

function getBidFloor(bid) {
if (!isFn(bid.getFloor)) {
return (bid.params.floor) ? bid.params.floor : null;
}

const floor = bid.getFloor({
currency: 'EUR',
mediaType: '*',
size: '*'
});
if (isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === 'EUR') {
return floor.floor;
}
return null;
}

export const spec = {

code: BIDDER_CODE,
Expand Down Expand Up @@ -38,13 +54,15 @@ export const spec = {
version: '$prebid.version$'
};

for (let {params, bidId, sizes, mediaTypes, ...bid} of bidRequests) {
for (let {bidId, sizes, mediaTypes, ...bid} of bidRequests) {
for (const mediaType in mediaTypes) {
switch (mediaType) {
case VIDEO: {
const params = bid.params;
const video = mediaTypes[VIDEO];
const placementId = params.placementId;
const site = getSiteObj();
const floor = getBidFloor(bid);

if (sizes && !Array.isArray(sizes[0])) sizes = [sizes];

Expand All @@ -71,6 +89,12 @@ export const spec = {
video: getDefinedParams(video, VIDEO_PARAMS)
}

const bidFloor = typeof floor === 'string' ? Number(floor.trim())
: typeof floor === 'number' ? floor
: NaN;

if (Number.isFinite(bidFloor) && bidFloor > 0) imp.bidfloor = bidFloor;

if (video.playerSize) {
imp.video = Object.assign(
imp.video, parseGPTSingleSizeArrayToRtbSize(video.playerSize[0]) || {}
Expand Down
1 change: 1 addition & 0 deletions modules/targetVideoBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var adUnits = [
bidder: 'targetVideo',
params: {
placementId: 12345,
floor: 2,
reserve: 0,
}
}]
Expand Down
54 changes: 47 additions & 7 deletions test/spec/modules/targetVideoBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ describe('TargetVideo Bid Adapter', function() {
const params = {
placementId: 12345,
};
const videoMediaTypes = {
video: {
playerSize: [[640, 360]],
context: 'instream',
playbackmethod: [1, 2, 3, 4]
}
}

const defaultBidderRequest = {
bidderRequestId: 'mock-uuid',
Expand All @@ -25,13 +32,7 @@ describe('TargetVideo Bid Adapter', function() {
const videoRequest = [{
bidder,
params,
mediaTypes: {
video: {
playerSize: [[640, 360]],
context: 'instream',
playbackmethod: [1, 2, 3, 4]
}
}
mediaTypes: videoMediaTypes,
}];

it('Test the bid validation function', function() {
Expand Down Expand Up @@ -353,4 +354,43 @@ describe('TargetVideo Bid Adapter', function() {
const userSyncs = spec.getUserSyncs({iframeEnabled: false});
expect(userSyncs).to.have.lengthOf(0);
});

it('Test the VIDEO request floor param', function() {
const requests = [
{
bidder,
params: {
...params,
floor: 2.12,
},
mediaTypes: videoMediaTypes,
},
{
bidder,
params: {
...params,
floor: "1.55",
},
mediaTypes: videoMediaTypes,
},
{
bidder,
params: {
...params,
floor: "abc",
},
mediaTypes: videoMediaTypes,
}
]

const bids = spec.buildRequests(requests, defaultBidderRequest)

const payload1 = JSON.parse(bids[0].data);
const payload2 = JSON.parse(bids[1].data);
const payload3 = JSON.parse(bids[2].data);

expect(payload1.imp[0].bidfloor).to.exist.and.equal(2.12);
expect(payload2.imp[0].bidfloor).to.exist.and.equal(1.55);
expect(payload3.imp[0].bidfloor).to.not.exist;
});
});
Loading