Skip to content

Commit

Permalink
Fix: check mandatory video params (prebid#5470)
Browse files Browse the repository at this point in the history
* Fix: check mandatory video params

* Simplifying mediaType video existence check
  • Loading branch information
cabama authored and BrightMountainMedia committed Sep 14, 2020
1 parent fa354dc commit 2d32072
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 24 deletions.
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

0 comments on commit 2d32072

Please sign in to comment.