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

Beachfront adapter support for sizes defined in mediaTypes #2435

Merged
merged 1 commit into from
Apr 27, 2018
Merged
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
Parse bid sizes on the mediaTypes object
  • Loading branch information
John Salis committed Apr 20, 2018
commit 1b3d16a7bbb099f7cedafb6b4a5207664d5e51de
5 changes: 4 additions & 1 deletion modules/beachfrontBidAdapter.js
Original file line number Diff line number Diff line change
@@ -121,7 +121,10 @@ function outstreamRender(bid) {
}

function getSizes(bid) {
return utils.parseSizesInput(bid.sizes).map(size => {
let sizes = (isVideoBid(bid)
? utils.deepAccess(bid, 'mediaTypes.video.playerSize')
: utils.deepAccess(bid, 'mediaTypes.banner.sizes')) || bid.sizes;
return utils.parseSizesInput(sizes).map(size => {
let [ width, height ] = size.split('x');
return {
w: parseInt(width, 10) || undefined,
12 changes: 8 additions & 4 deletions modules/beachfrontBidAdapter.md
Original file line number Diff line number Diff line change
@@ -15,10 +15,10 @@ Module that connects to Beachfront's demand sources
var adUnits = [
{
code: 'test-video',
sizes: [[640, 360]],
mediaTypes: {
video: {
context: 'instream'
context: 'instream',
playerSize: [ 640, 360 ]
}
},
bids: [
@@ -28,14 +28,18 @@ Module that connects to Beachfront's demand sources
bidfloor: 0.01,
appId: '11bc5dd5-7421-4dd8-c926-40fa653bec76',
video: {
mimes: ['video/mp4', 'application/javascript']
mimes: [ 'video/mp4', 'application/javascript' ]
}
}
}
]
}, {
code: 'test-banner',
sizes: [300, 250],
mediaTypes: {
banner: {
sizes: [ 300, 250 ]
}
},
bids: [
{
bidder: 'beachfront',
121 changes: 92 additions & 29 deletions test/spec/modules/beachfrontBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -14,7 +14,6 @@ describe('BeachfrontAdapter', () => {
appId: '3b16770b-17af-4d22-daff-9606bdf2c9c3'
},
adUnitCode: 'div-gpt-ad-1460505748561-0',
sizes: [ 300, 250 ],
bidId: '25186806a41eab',
bidderRequestId: '15bdd8d4a0ebaf',
auctionId: 'f17d62d0-e3e3-48d0-9f73-cb4ea358a309'
@@ -25,7 +24,6 @@ describe('BeachfrontAdapter', () => {
appId: '11bc5dd5-7421-4dd8-c926-40fa653bec76'
},
adUnitCode: 'div-gpt-ad-1460505748561-1',
sizes: [ 300, 600 ],
bidId: '365088ee6d649d',
bidderRequestId: '15bdd8d4a0ebaf',
auctionId: 'f17d62d0-e3e3-48d0-9f73-cb4ea358a309'
@@ -86,11 +84,16 @@ describe('BeachfrontAdapter', () => {
});

it('should attach request data', () => {
const width = 640;
const height = 480;
const bidRequest = bidRequests[0];
bidRequest.mediaTypes = { video: {} };
bidRequest.mediaTypes = {
video: {
playerSize: [ width, height ]
}
};
const requests = spec.buildRequests([ bidRequest ]);
const data = requests[0].data;
const [ width, height ] = bidRequest.sizes;
const topLocation = utils.getTopWindowLocation();
expect(data.isPrebid).to.equal(true);
expect(data.appId).to.equal(bidRequest.params.appId);
@@ -107,8 +110,11 @@ describe('BeachfrontAdapter', () => {
const width = 640;
const height = 480;
const bidRequest = bidRequests[0];
bidRequest.sizes = [[ width, height ]];
bidRequest.mediaTypes = { video: {} };
bidRequest.mediaTypes = {
video: {
playerSize: [[ width, height ]]
}
};
const requests = spec.buildRequests([ bidRequest ]);
const data = requests[0].data;
expect(data.imp[0].video).to.deep.contain({ w: width, h: height });
@@ -118,22 +124,39 @@ describe('BeachfrontAdapter', () => {
const width = 640;
const height = 480;
const bidRequest = bidRequests[0];
bidRequest.sizes = `${width}x${height}`;
bidRequest.mediaTypes = { video: {} };
bidRequest.mediaTypes = {
video: {
playerSize: `${width}x${height}`
}
};
const requests = spec.buildRequests([ bidRequest ]);
const data = requests[0].data;
expect(data.imp[0].video).to.deep.contain({ w: width, h: height });
});

it('must handle an empty bid size', () => {
const bidRequest = bidRequests[0];
bidRequest.sizes = [];
bidRequest.mediaTypes = { video: {} };
bidRequest.mediaTypes = {
video: {
playerSize: []
}
};
const requests = spec.buildRequests([ bidRequest ]);
const data = requests[0].data;
expect(data.imp[0].video).to.deep.contain({ w: undefined, h: undefined });
});

it('must fall back to the size on the bid object', () => {
const width = 640;
const height = 480;
const bidRequest = bidRequests[0];
bidRequest.sizes = [ width, height ];
bidRequest.mediaTypes = { video: {} };
const requests = spec.buildRequests([ bidRequest ]);
const data = requests[0].data;
expect(data.imp[0].video).to.deep.contain({ w: width, h: height });
});

it('must override video targeting params', () => {
const bidRequest = bidRequests[0];
const mimes = ['video/webm'];
@@ -163,11 +186,16 @@ describe('BeachfrontAdapter', () => {
});

it('should attach request data', () => {
const width = 300;
const height = 250;
const bidRequest = bidRequests[0];
bidRequest.mediaTypes = { banner: {} };
bidRequest.mediaTypes = {
banner: {
sizes: [ width, height ]
}
};
const requests = spec.buildRequests([ bidRequest ]);
const data = requests[0].data;
const [ width, height ] = bidRequest.sizes;
const topLocation = utils.getTopWindowLocation();
expect(data.slots).to.deep.equal([
{
@@ -184,11 +212,14 @@ describe('BeachfrontAdapter', () => {
});

it('must parse bid size from a nested array', () => {
const width = 640;
const height = 480;
const width = 300;
const height = 250;
const bidRequest = bidRequests[0];
bidRequest.sizes = [[ width, height ]];
bidRequest.mediaTypes = { banner: {} };
bidRequest.mediaTypes = {
banner: {
sizes: [[ width, height ]]
}
};
const requests = spec.buildRequests([ bidRequest ]);
const data = requests[0].data;
expect(data.slots[0].sizes).to.deep.equal([
@@ -197,11 +228,14 @@ describe('BeachfrontAdapter', () => {
});

it('must parse bid size from a string', () => {
const width = 640;
const height = 480;
const width = 300;
const height = 250;
const bidRequest = bidRequests[0];
bidRequest.sizes = `${width}x${height}`;
bidRequest.mediaTypes = { banner: {} };
bidRequest.mediaTypes = {
banner: {
sizes: `${width}x${height}`
}
};
const requests = spec.buildRequests([ bidRequest ]);
const data = requests[0].data;
expect(data.slots[0].sizes).to.deep.equal([
@@ -211,12 +245,26 @@ describe('BeachfrontAdapter', () => {

it('must handle an empty bid size', () => {
const bidRequest = bidRequests[0];
bidRequest.sizes = [];
bidRequest.mediaTypes = { banner: {} };
bidRequest.mediaTypes = {
banner: {
sizes: []
}
};
const requests = spec.buildRequests([ bidRequest ]);
const data = requests[0].data;
expect(data.slots[0].sizes).to.deep.equal([]);
});

it('must fall back to the size on the bid object', () => {
const width = 300;
const height = 250;
const bidRequest = bidRequests[0];
bidRequest.sizes = [ width, height ];
bidRequest.mediaTypes = { banner: {} };
const requests = spec.buildRequests([ bidRequest ]);
const data = requests[0].data;
expect(data.slots[0].sizes).to.deep.contain({ w: width, h: height });
});
});
});

@@ -250,15 +298,20 @@ describe('BeachfrontAdapter', () => {
});

it('should return a valid video bid response', () => {
const width = 640;
const height = 480;
const bidRequest = bidRequests[0];
bidRequest.mediaTypes = { video: {} };
bidRequest.mediaTypes = {
video: {
playerSize: [ width, height ]
}
};
const serverResponse = {
bidPrice: 5.00,
url: 'http://reachms.bfmio.com/getmu?aid=bid:19c4a196-fb21-4c81-9a1a-ecc5437a39da',
cmpId: '123abc'
};
const bidResponse = spec.interpretResponse({ body: serverResponse }, { bidRequest });
const [ width, height ] = bidRequest.sizes;
expect(bidResponse).to.deep.equal({
requestId: bidRequest.bidId,
bidderCode: spec.code,
@@ -277,7 +330,11 @@ describe('BeachfrontAdapter', () => {

it('should return a renderer for outstream video bids', () => {
const bidRequest = bidRequests[0];
bidRequest.mediaTypes = { video: { context: 'outstream' } };
bidRequest.mediaTypes = {
video: {
context: 'outstream'
}
};
const serverResponse = {
bidPrice: 5.00,
url: 'http://reachms.bfmio.com/getmu?aid=bid:19c4a196-fb21-4c81-9a1a-ecc5437a39da',
@@ -307,10 +364,16 @@ describe('BeachfrontAdapter', () => {
});

it('should return valid banner bid responses', () => {
bidRequests[0].mediaTypes = { banner: {} };
bidRequests[0].sizes = [[ 300, 250 ], [ 728, 90 ]];
bidRequests[1].mediaTypes = { banner: {} };
bidRequests[1].sizes = [[ 300, 600 ], [ 200, 200 ]];
bidRequests[0].mediaTypes = {
banner: {
sizes: [[ 300, 250 ], [ 728, 90 ]]
}
};
bidRequests[1].mediaTypes = {
banner: {
sizes: [[ 300, 600 ], [ 200, 200 ]]
}
};
const serverResponse = [{
slot: bidRequests[0].adUnitCode,
adm: '<div id="44851937"></div>',