Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added video media type support for connatix bid adapter #6

Draft
wants to merge 10 commits into
base: connatix
Choose a base branch
from
16 changes: 0 additions & 16 deletions gannet-modules.json

This file was deleted.

63 changes: 0 additions & 63 deletions modules.json

This file was deleted.

44 changes: 36 additions & 8 deletions modules/connatixBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import {
} from '../src/utils.js';

import {
ADPOD,
BANNER,
VIDEO,
} from '../src/mediaTypes.js';

const BIDDER_CODE = 'connatix';
Expand Down Expand Up @@ -41,10 +43,28 @@ export function getBidFloor(bid) {
}
}

export function validateBanner(mediaTypes) {
if (!mediaTypes[BANNER]) {
return true;
}

const banner = deepAccess(mediaTypes, BANNER, {});
return (Boolean(banner.sizes) && isArray(mediaTypes[BANNER].sizes) && mediaTypes[BANNER].sizes.length > 0);
}

export function validateVideo(mediaTypes) {
const video = mediaTypes[VIDEO];
if (!video) {
return true;
}

return video.context !== ADPOD;
}

export const spec = {
code: BIDDER_CODE,
gvlid: 143,
supportedMediaTypes: [BANNER],
supportedMediaTypes: [BANNER, VIDEO],

/*
* Validate the bid request.
Expand All @@ -57,17 +77,24 @@ export const spec = {
const params = deepAccess(bid, 'params', {});
const bidder = deepAccess(bid, 'bidder');

const banner = deepAccess(mediaTypes, BANNER, {});

const hasBidId = Boolean(bidId);
const isValidBidder = (bidder === BIDDER_CODE);
const isValidSize = (Boolean(banner.sizes) && isArray(mediaTypes[BANNER].sizes) && mediaTypes[BANNER].sizes.length > 0);
const hasSizes = mediaTypes[BANNER] ? isValidSize : false;
const hasMediaTypes = Boolean(mediaTypes) && (Boolean(mediaTypes[BANNER]) || Boolean(mediaTypes[VIDEO]));
const isValidBanner = validateBanner(mediaTypes);
const isValidVideo = validateVideo(mediaTypes);
const hasRequiredBidParams = Boolean(params.placementId);

const isValid = isValidBidder && hasBidId && hasSizes && hasRequiredBidParams;
const isValid = isValidBidder && hasBidId && hasMediaTypes && isValidBanner && isValidVideo && hasRequiredBidParams;
if (!isValid) {
logError(`Invalid bid request: isValidBidder: ${isValidBidder} hasBidId: ${hasBidId}, hasSizes: ${hasSizes}, hasRequiredBidParams: ${hasRequiredBidParams}`);
logError(
`Invalid bid request:
isValidBidder: ${isValidBidder},
hasBidId: ${hasBidId},
hasMediaTypes: ${hasMediaTypes},
isValidBanner: ${isValidBanner},
isValidVideo: ${isValidVideo},
hasRequiredBidParams: ${hasRequiredBidParams}`
);
}
return isValid;
},
Expand Down Expand Up @@ -128,12 +155,13 @@ export const spec = {
cpm: bidResponse.Cpm,
ttl: bidResponse.Ttl || DEFAULT_MAX_TTL,
currency: 'USD',
mediaType: BANNER,
mediaType: bidResponse.VastXml ? VIDEO : BANNER,
netRevenue: true,
width: bidResponse.Width,
height: bidResponse.Height,
creativeId: bidResponse.CreativeId,
ad: bidResponse.Ad,
vastXml: bidResponse.VastXml,
referrer: referrer,
}));
},
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
"scripts": {
"serve": "gulp serve",
"test": "gulp test",
"lint": "gulp lint",
"build:connatix": "gulp build-bundle-prod --disable NATIVE --modules=modules.json",
"build:connatix:gannett": "gulp build-bundle-prod --disable NATIVE --modules=gannet-modules.json"
"lint": "gulp lint"
},
"repository": {
"type": "git",
Expand Down
57 changes: 55 additions & 2 deletions test/spec/modules/connatixBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
spec,
getBidFloor as connatixGetBidFloor
} from '../../../modules/connatixBidAdapter.js';
import { BANNER } from '../../../src/mediaTypes.js';
import { ADPOD, BANNER, VIDEO } from '../../../src/mediaTypes.js';

describe('connatixBidAdapter', function () {
let bid;
Expand All @@ -24,6 +24,26 @@ describe('connatixBidAdapter', function () {
};
};

function addVideoToBidMock(bid) {
const mediaTypes = {
video: {
context: 'instream',
Alex404Damsa marked this conversation as resolved.
Show resolved Hide resolved
w: 1280,
h: 720,
playerSize: [1280, 720],
placement: 1,
plcmt: 1,
api: [1, 2],
mimes: ['video/mp4', 'application/javascript'],
minduration: 30,
maxduration: 60,
startdelay: 0,
}
}

bid.mediaTypes = mediaTypes;
}

describe('isBidRequestValid', function () {
this.beforeEach(function () {
bid = mockBidRequest();
Expand Down Expand Up @@ -52,7 +72,7 @@ describe('connatixBidAdapter', function () {
delete bid.mediaTypes;
expect(spec.isBidRequestValid(bid)).to.be.false;
});
it('Should return false if banner is missing from mediaTypes ', function () {
it('Should return false if both banner and video are missing from mediaTypes', function () {
delete bid.mediaTypes.banner;
expect(spec.isBidRequestValid(bid)).to.be.false;
});
Expand All @@ -68,6 +88,15 @@ describe('connatixBidAdapter', function () {
bid.mediaTypes.banner.sizes = [];
expect(spec.isBidRequestValid(bid)).to.be.false;
});
it('Should return true if video is set correctly', function () {
addVideoToBidMock(bid);
expect(spec.isBidRequestValid(bid)).to.be.true;
});
it('Should return false if context is set to adpod on video media type', function() {
addVideoToBidMock(bid);
bid.mediaTypes.video.context = ADPOD;
expect(spec.isBidRequestValid(bid)).to.be.false;
});
it('Should return true if add an extra field was added to the bidRequest', function () {
bid.params.test = 1;
expect(spec.isBidRequestValid(bid)).to.be.true;
Expand Down Expand Up @@ -192,6 +221,30 @@ describe('connatixBidAdapter', function () {
expect(bidResponses[0].cpm).to.equal(firstBidCpm);
expect(bidResponses[1].cpm).to.equal(secondBidCpm);
});

it('Should contain specific values for banner bids', function () {
const adHtml = 'ad html'
serverResponse.body.Bids = [ { ...Bid, Ad: adHtml } ];

const bidResponses = spec.interpretResponse(serverResponse);
const [ bidResponse ] = bidResponses;

expect(bidResponse.vastXml).to.be.undefined;
expect(bidResponse.ad).to.equal(adHtml);
expect(bidResponse.mediaType).to.equal(BANNER);
});

it('Should contain specific values for video bids', function () {
const adVastXml = 'ad vast xml'
serverResponse.body.Bids = [ { ...Bid, VastXml: adVastXml } ];

const bidResponses = spec.interpretResponse(serverResponse);
const [ bidResponse ] = bidResponses;

expect(bidResponse.ad).to.be.undefined;
expect(bidResponse.vastXml).to.equal(adVastXml);
expect(bidResponse.mediaType).to.equal(VIDEO);
});
});

describe('getUserSyncs', function() {
Expand Down