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

Fix: check mandatory video params #5470

Merged
merged 2 commits into from
Sep 10, 2020
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
12 changes: 6 additions & 6 deletions modules/seedtagBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ function mapMediaType(seedtagMediaType) {
else return seedtagMediaType;
}

function getMediaTypeFromBid(bid) {
return bid.mediaTypes && Object.keys(bid.mediaTypes)[0]
function hasVideoMediaType(bid) {
return !!bid.mediaTypes && !!bid.mediaTypes.video
}

function hasMandatoryParams(params) {
Expand All @@ -34,7 +34,7 @@ function hasMandatoryParams(params) {
);
}

function hasVideoMandatoryParams(mediaTypes) {
function hasMandatoryVideoParams(mediaTypes) {
const isVideoInStream =
!!mediaTypes.video && mediaTypes.video.context === 'instream';
const isPlayerSize =
Expand Down Expand Up @@ -65,7 +65,7 @@ function buildBidRequests(validBidRequests) {
bidRequest.adPosition = params.adPosition;
}

if (params.video) {
if (hasVideoMediaType(validBidRequest)) {
bidRequest.videoParams = params.video || {};
bidRequest.videoParams.w =
validBidRequest.mediaTypes.video.playerSize[0][0];
Expand Down Expand Up @@ -124,8 +124,8 @@ export const spec = {
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid(bid) {
return getMediaTypeFromBid(bid) === VIDEO
? hasMandatoryParams(bid.params) && hasVideoMandatoryParams(bid.mediaTypes)
return hasVideoMediaType(bid)
? hasMandatoryParams(bid.params) && hasMandatoryVideoParams(bid.mediaTypes)
: hasMandatoryParams(bid.params);
},

Expand Down
59 changes: 41 additions & 18 deletions test/spec/modules/seedtagBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { expect } from 'chai'
import { spec, getTimeoutUrl } from 'modules/seedtagBidAdapter.js'

const PUBLISHER_ID = '0000-0000-01'
const ADUNIT_ID = '000000'

function getSlotConfigs(mediaTypes, params) {
return {
params: params,
Expand All @@ -16,10 +19,16 @@ function getSlotConfigs(mediaTypes, params) {
}
}

function createVideoSlotConfig(mediaType) {
return getSlotConfigs(mediaType, {
publisherId: PUBLISHER_ID,
adUnitId: ADUNIT_ID,
placement: 'video'
})
}

describe('Seedtag Adapter', function() {
describe('isBidRequestValid method', function() {
const PUBLISHER_ID = '0000-0000-01'
const ADUNIT_ID = '000000'
describe('returns true', function() {
describe('when banner slot config has all mandatory params', () => {
describe('and placement has the correct value', function() {
Expand Down Expand Up @@ -66,41 +75,41 @@ describe('Seedtag Adapter', function() {
})
describe('returns false', function() {
describe('when params are not correct', function() {
function createSlotconfig(params) {
function createSlotConfig(params) {
return getSlotConfigs({ banner: {} }, params)
}
it('does not have the PublisherToken.', function() {
const isBidRequestValid = spec.isBidRequestValid(
createSlotconfig({
adUnitId: '000000',
createSlotConfig({
adUnitId: ADUNIT_ID,
placement: 'banner'
})
)
expect(isBidRequestValid).to.equal(false)
})
it('does not have the AdUnitId.', function() {
const isBidRequestValid = spec.isBidRequestValid(
createSlotconfig({
publisherId: '0000-0000-01',
createSlotConfig({
publisherId: PUBLISHER_ID,
placement: 'banner'
})
)
expect(isBidRequestValid).to.equal(false)
})
it('does not have the placement.', function() {
const isBidRequestValid = spec.isBidRequestValid(
createSlotconfig({
publisherId: '0000-0000-01',
adUnitId: '000000'
createSlotConfig({
publisherId: PUBLISHER_ID,
adUnitId: ADUNIT_ID
})
)
expect(isBidRequestValid).to.equal(false)
})
it('does not have a the correct placement.', function() {
const isBidRequestValid = spec.isBidRequestValid(
createSlotconfig({
publisherId: '0000-0000-01',
adUnitId: '000000',
createSlotConfig({
publisherId: PUBLISHER_ID,
adUnitId: ADUNIT_ID,
placement: 'another_thing'
})
)
Expand All @@ -117,19 +126,19 @@ describe('Seedtag Adapter', function() {
}
it('is a void object', function() {
const isBidRequestValid = spec.isBidRequestValid(
createVideoSlotconfig({ video: {} })
createVideoSlotConfig({ video: {} })
)
expect(isBidRequestValid).to.equal(false)
})
it('does not have playerSize.', function() {
const isBidRequestValid = spec.isBidRequestValid(
createVideoSlotconfig({ video: { context: 'instream' } })
createVideoSlotConfig({ video: { context: 'instream' } })
)
expect(isBidRequestValid).to.equal(false)
})
it('is not instream ', function() {
const isBidRequestValid = spec.isBidRequestValid(
createVideoSlotconfig({
createVideoSlotConfig({
video: {
context: 'outstream',
playerSize: [[600, 200]]
Expand All @@ -138,6 +147,20 @@ describe('Seedtag Adapter', function() {
)
expect(isBidRequestValid).to.equal(false)
})
describe('order does not matter', function() {
it('when video is not the first slot', function() {
const isBidRequestValid = spec.isBidRequestValid(
createVideoSlotConfig({ banner: {}, video: {} })
)
expect(isBidRequestValid).to.equal(false)
})
it('when video is the first slot', function() {
const isBidRequestValid = spec.isBidRequestValid(
createVideoSlotConfig({ video: {}, banner: {} })
)
expect(isBidRequestValid).to.equal(false)
})
})
})
})
})
Expand All @@ -148,8 +171,8 @@ describe('Seedtag Adapter', function() {
timeout: 1000
}
const mandatoryParams = {
publisherId: '0000-0000-01',
adUnitId: '000000',
publisherId: PUBLISHER_ID,
adUnitId: ADUNIT_ID,
placement: 'banner'
}
const inStreamParams = Object.assign({}, mandatoryParams, {
Expand Down