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

FreewheelSSP - enable mediaTypes banner and video with test cases #4739

Merged
merged 3 commits into from
Jan 28, 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
37 changes: 23 additions & 14 deletions modules/freewheel-sspBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,17 @@ export const spec = {
requestParams.loc = location;
}

var playerSize = getBiggerSizeWithLimit(currentBidRequest.mediaTypes.banner.sizes, currentBidRequest.mediaTypes.banner.minSizeLimit, currentBidRequest.mediaTypes.banner.maxSizeLimit);
var playerSize = [];
if (currentBidRequest.mediaTypes.video && currentBidRequest.mediaTypes.video.playerSize) {
// If mediaTypes is video, get size from mediaTypes.video.playerSize per http://prebid.org/blog/pbjs-3
playerSize = currentBidRequest.mediaTypes.video.playerSize;
} else if (currentBidRequest.mediaTypes.banner.sizes) {
// If mediaTypes is banner, get size from mediaTypes.banner.sizes per http://prebid.org/blog/pbjs-3
playerSize = getBiggerSizeWithLimit(currentBidRequest.mediaTypes.banner.sizes, currentBidRequest.mediaTypes.banner.minSizeLimit, currentBidRequest.mediaTypes.banner.maxSizeLimit);
} else {
// Backward compatible code, in case size still pass by sizes in bid request
playerSize = getBiggerSize(currentBidRequest.sizes);
}

if (playerSize[0] > 0 || playerSize[1] > 0) {
requestParams.playerSize = playerSize[0] + 'x' + playerSize[1];
Expand All @@ -306,7 +316,17 @@ export const spec = {
*/
interpretResponse: function(serverResponse, request) {
var bidrequest = request.bidRequest;
var playerSize = getBiggerSizeWithLimit(bidrequest.mediaTypes.banner.sizes, bidrequest.mediaTypes.banner.minSizeLimit, bidrequest.mediaTypes.banner.maxSizeLimit);
var playerSize = [];
if (bidrequest.mediaTypes.video && bidrequest.mediaTypes.video.playerSize) {
// If mediaTypes is video, get size from mediaTypes.video.playerSize per http://prebid.org/blog/pbjs-3
playerSize = bidrequest.mediaTypes.video.playerSize;
} else if (bidrequest.mediaTypes.banner.sizes) {
// If mediaTypes is banner, get size from mediaTypes.banner.sizes per http://prebid.org/blog/pbjs-3
playerSize = getBiggerSizeWithLimit(bidrequest.mediaTypes.banner.sizes, bidrequest.mediaTypes.banner.minSizeLimit, bidrequest.mediaTypes.banner.maxSizeLimit);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify where the mediaTypes.banner.minSizeLimit and mediaTypes.banner.maxSizeLimit fields get populated? Are those extra fields meant to be added within the adUnit setup or something else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. These two fields could be added within the adUnit set up together with the banner.sizes array. The idea is if any of the two limits (or both) is set, then only valid size within the [minSize -> maxSize] range could be used. If none of the limits are set, the default value of minSize [0, 0] and maxSize [Number.MAX_VALUE, Number.MAX_VALUE] will be set so that all the sizes in the array are treated as potentially valid.

} else {
// Backward compatible code, in case size still pass by sizes in bid request
playerSize = getBiggerSize(bidrequest.sizes);
}

if (typeof serverResponse == 'object' && typeof serverResponse.body == 'string') {
serverResponse = serverResponse.body;
Expand Down Expand Up @@ -343,18 +363,7 @@ export const spec = {
netRevenue: true,
ttl: 360
};

var mediaTypes = bidrequest.mediaTypes || {};
if (mediaTypes.video) {
// bidResponse.vastXml = serverResponse;
bidResponse.mediaType = 'video';

var blob = new Blob([serverResponse], {type: 'application/xml'});
bidResponse.vastUrl = window.URL.createObjectURL(blob);
} else {
bidResponse.ad = formatAdHTML(bidrequest, playerSize);
}

bidResponse.ad = formatAdHTML(bidrequest, playerSize);
bidResponses.push(bidResponse);
}

Expand Down
240 changes: 237 additions & 3 deletions test/spec/modules/freewheel-sspBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('freewheelSSP BidAdapter Test', () => {
});
});

describe('isBidRequestValid', () => {
describe('isBidRequestValidForBanner', () => {
let bid = {
'bidder': 'freewheel-ssp',
'params': {
Expand Down Expand Up @@ -47,7 +47,39 @@ describe('freewheelSSP BidAdapter Test', () => {
});
});

describe('buildRequests', () => {
describe('isBidRequestValidForVideo', () => {
let bid = {
'bidder': 'freewheel-ssp',
'params': {
'zoneId': '277225'
},
'adUnitCode': 'adunit-code',
'mediaTypes': {
'video': {
'playerSize': [300, 250],
}
},
'sizes': [[300, 250]],
'bidId': '30b31c1838de1e',
'bidderRequestId': '22edbae2733bf6',
'auctionId': '1d1a030790a475',
};

it('should return true when required params found', () => {
expect(spec.isBidRequestValid(bid)).to.equal(true);
});

it('should return false when required params are not passed', () => {
let bid = Object.assign({}, bid);
delete bid.params;
bid.params = {
wrong: 'missing zone id'
};
expect(spec.isBidRequestValid(bid)).to.equal(false);
});
});

describe('buildRequestsForBanner', () => {
let bidRequests = [
{
'bidder': 'freewheel-ssp',
Expand Down Expand Up @@ -120,7 +152,78 @@ describe('freewheelSSP BidAdapter Test', () => {
});
})

describe('interpretResponse', () => {
describe('buildRequestsForVideo', () => {
let bidRequests = [
{
'bidder': 'freewheel-ssp',
'params': {
'zoneId': '277225'
},
'adUnitCode': 'adunit-code',
'mediaTypes': {
'video': {
'playerSize': [300, 600],
}
},
'sizes': [[300, 250], [300, 600]],
'bidId': '30b31c1838de1e',
'bidderRequestId': '22edbae2733bf6',
'auctionId': '1d1a030790a475',
}
];

it('should add parameters to the tag', () => {
const request = spec.buildRequests(bidRequests);
const payload = request.data;
expect(payload.reqType).to.equal('AdsSetup');
expect(payload.protocolVersion).to.equal('2.0');
expect(payload.zoneId).to.equal('277225');
expect(payload.componentId).to.equal('mustang');
expect(payload.playerSize).to.equal('300x600');
});

it('sends bid request to ENDPOINT via GET', () => {
const request = spec.buildRequests(bidRequests);
expect(request.url).to.contain(ENDPOINT);
expect(request.method).to.equal('GET');
});

it('should add usp consent to the request', () => {
let uspConsentString = '1FW-SSP-uspConsent-';
let bidderRequest = {};
bidderRequest.uspConsent = uspConsentString;
const request = spec.buildRequests(bidRequests, bidderRequest);
const payload = request.data;
expect(payload.reqType).to.equal('AdsSetup');
expect(payload.protocolVersion).to.equal('2.0');
expect(payload.zoneId).to.equal('277225');
expect(payload.componentId).to.equal('mustang');
expect(payload.playerSize).to.equal('300x600');
expect(payload._fw_us_privacy).to.exist.and.to.be.a('string');
expect(payload._fw_us_privacy).to.equal(uspConsentString);
});

it('should add gdpr consent to the request', () => {
let gdprConsentString = '1FW-SSP-gdprConsent-';
let bidderRequest = {
'gdprConsent': {
'consentString': gdprConsentString
}
};

const request = spec.buildRequests(bidRequests, bidderRequest);
const payload = request.data;
expect(payload.reqType).to.equal('AdsSetup');
expect(payload.protocolVersion).to.equal('2.0');
expect(payload.zoneId).to.equal('277225');
expect(payload.componentId).to.equal('mustang');
expect(payload.playerSize).to.equal('300x600');
expect(payload._fw_gdpr_consent).to.exist.and.to.be.a('string');
expect(payload._fw_gdpr_consent).to.equal(gdprConsentString);
});
})

describe('interpretResponseForBanner', () => {
let bidRequests = [
{
'bidder': 'freewheel-ssp',
Expand Down Expand Up @@ -249,6 +352,137 @@ describe('freewheelSSP BidAdapter Test', () => {
expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0]));
});

it('handles nobid responses', () => {
var reqest = spec.buildRequests(formattedBidRequests);
let response = '<?xml version=\'1.0\' encoding=\'UTF-8\'?><VAST version=\'2.0\'></VAST>';

let result = spec.interpretResponse(response, reqest);
expect(result.length).to.equal(0);
});
});
describe('interpretResponseForVideo', () => {
let bidRequests = [
{
'bidder': 'freewheel-ssp',
'params': {
'zoneId': '277225'
},
'adUnitCode': 'adunit-code',
'mediaTypes': {
'video': {
'playerSize': [300, 600],
}
},
'sizes': [[300, 400]],
'bidId': '30b31c1838de1e',
'bidderRequestId': '22edbae2733bf6',
'auctionId': '1d1a030790a475',
}
];

let formattedBidRequests = [
{
'bidder': 'freewheel-ssp',
'params': {
'zoneId': '277225',
'format': 'floorad'
},
'adUnitCode': 'adunit-code',
'mediaTypes': {
'video': {
'playerSize': [300, 600],
}
},
'sizes': [[300, 400]],
'bidId': '30b3other1c1838de1e',
'bidderRequestId': '22edbae273other3bf6',
'auctionId': '1d1a03079test0a475',
},
{
'bidder': 'stickyadstv',
'params': {
'zoneId': '277225',
'format': 'test'
},
'adUnitCode': 'adunit-code',
'mediaTypes': {
'video': {
'playerSize': [300, 600],
}
},
'sizes': [[300, 400]],
'bidId': '2',
'bidderRequestId': '3',
'auctionId': '4',
}
];

let response = '<?xml version=\'1.0\' encoding=\'UTF-8\'?><VAST version=\'2.0\'>' +
'<Ad id=\'AdswizzAd28517153\'>' +
' <InLine>' +
' <AdSystem>Adswizz</AdSystem>' +
' <Creatives>' +
' <Creative id=\'28517153\' sequence=\'1\'>' +
' <Linear>' +
' <Duration>00:00:09</Duration>' +
' <MediaFiles>' +
' <MediaFile delivery=\'progressive\' bitrate=\'129\' width=\'320\' height=\'240\' type=\'video/mp4\' scalable=\'true\' maintainAspectRatio=\'true\'><![CDATA[http://cdn.stickyadstv.com/www/images/28517153-web-MP4-59e47d565b2d9.mp4]]></MediaFile>' +
' </MediaFiles>' +
' </Linear>' +
' </Creative>' +
' </Creatives>' +
' <Extensions>' +
' <Extension type=\'StickyPricing\'><Price currency="EUR">0.2000</Price></Extension>' +
' </Extensions>' +
' </InLine>' +
' </Ad>' +
'</VAST>';

let ad = '<div id="freewheelssp_prebid_target"></div><script type=\'text/javascript\'>(function() { var st = document.createElement(\'script\'); st.type = \'text/javascript\'; st.async = true; st.src = \'http://cdn.stickyadstv.com/mustang/mustang.min.js\'; st.onload = function(){ var vastLoader = new window.com.stickyadstv.vast.VastLoader(); var vast = vastLoader.getVast(); var topWindow = (function(){var res=window; try{while(top != res){if(res.parent.location.href.length)res=res.parent;}}catch(e){}return res;})(); vast.setXmlString(topWindow.freeheelssp_cache["adunit-code"]); vastLoader.parseAds(vast, { onSuccess: function() {var config = { preloadedVast:vast, autoPlay:true }; var ad = new window.com.stickyadstv.vpaid.Ad(document.getElementById("freewheelssp_prebid_target"),config); (new window.com.stickyadstv.tools.ASLoader(277225, \'mustang\')).registerEvents(ad); ad.initAd(300,600,"",0,"",""); } }); }; document.head.appendChild(st);})();</script>';
let formattedAd = '<div id="freewheelssp_prebid_target"></div><script type=\'text/javascript\'>(function() { var st = document.createElement(\'script\'); st.type = \'text/javascript\'; st.async = true; st.src = \'http://cdn.stickyadstv.com/prime-time/floorad.min.js\'; st.onload = function(){ var vastLoader = new window.com.stickyadstv.vast.VastLoader(); var vast = vastLoader.getVast(); var topWindow = (function(){var res=window; try{while(top != res){if(res.parent.location.href.length)res=res.parent;}}catch(e){}return res;})(); vast.setXmlString(topWindow.freeheelssp_cache["adunit-code"]); vastLoader.parseAds(vast, { onSuccess: function() {var config = { preloadedVast:vast, ASLoader:new window.com.stickyadstv.tools.ASLoader(277225, \'floorad\'),domId:"adunit-code"};window.com.stickyadstv.floorad.start(config); } }); }; document.head.appendChild(st);})();</script>';

it('should get correct bid response', () => {
var request = spec.buildRequests(bidRequests);

let expectedResponse = [
{
requestId: '30b31c1838de1e',
cpm: '0.2000',
width: 300,
height: 600,
creativeId: '28517153',
currency: 'EUR',
netRevenue: true,
ttl: 360,
ad: ad
}
];

let result = spec.interpretResponse(response, request);
expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0]));
});

it('should get correct bid response with formated ad', () => {
var request = spec.buildRequests(formattedBidRequests);

let expectedResponse = [
{
requestId: '30b31c1838de1e',
cpm: '0.2000',
width: 300,
height: 600,
creativeId: '28517153',
currency: 'EUR',
netRevenue: true,
ttl: 360,
ad: formattedAd
}
];

let result = spec.interpretResponse(response, request);
expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0]));
});

it('handles nobid responses', () => {
var reqest = spec.buildRequests(formattedBidRequests);
let response = '<?xml version=\'1.0\' encoding=\'UTF-8\'?><VAST version=\'2.0\'></VAST>';
Expand Down