From e748bef965a8550b203bdf8f9c3929966f251d3d Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Mon, 17 Jul 2017 18:54:20 +0200 Subject: [PATCH] StickyAdsTV bidder adapter update (#1311) * add stickyadsTV bidder adapter * init unit test file * ad some unit tests * fix unit test on ad format with parameters * add some unit tests * add unit tests on getBid method * add some test cases in unit tests * minor fix on component id tag. * remove adapters-sticky.json test file * use top most accessible window instead of window.top * Pass in the bid request in the createBid call. * use top most accessible window instead of window.top * add unit tests * update unit tests * fix unit test. * fix CI build * add alias freewheel-ssp * update unit tests on bidderCode value * fix component id values and add unit tests * allws to use any outstream format. * fix ASLoader on futur outstream format versions * minor: fix code format. * update unit tests * minor fix code format * minor: add missing new line at eof --- modules/stickyadstvBidAdapter.js | 90 +++++++++---------- .../modules/stickyadstvBidAdapter_spec.js | 31 +++++-- 2 files changed, 67 insertions(+), 54 deletions(-) diff --git a/modules/stickyadstvBidAdapter.js b/modules/stickyadstvBidAdapter.js index 27ebb4ef31a..c8936e11601 100644 --- a/modules/stickyadstvBidAdapter.js +++ b/modules/stickyadstvBidAdapter.js @@ -8,8 +8,7 @@ var adaptermanager = require('src/adaptermanager'); var StickyAdsTVAdapter = function StickyAdsTVAdapter() { var STICKYADS_BIDDERCODE = 'stickyadstv'; var MUSTANG_URL = '//cdn.stickyadstv.com/mustang/mustang.min.js'; - var INTEXTROLL_URL = '//cdn.stickyadstv.com/prime-time/intext-roll.min.js'; - var SCREENROLL_URL = '//cdn.stickyadstv.com/prime-time/screen-roll.min.js'; + var OUTSTREAM_URL = '//cdn.stickyadstv.com/prime-time/[COMP-ID].min.js'; var topMostWindow = getTopMostWindow(); topMostWindow.stickyadstv_cache = {}; @@ -34,11 +33,9 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { var integrationType = bid.params.format ? bid.params.format : 'inbanner'; var urltoLoad = MUSTANG_URL; - if (integrationType === 'intext-roll') { - urltoLoad = INTEXTROLL_URL; - } - if (integrationType === 'screen-roll') { - urltoLoad = SCREENROLL_URL; + if (integrationType !== 'inbanner') { + // integration types are equals to component ids + urltoLoad = OUTSTREAM_URL.replace('[COMP-ID]', integrationType); } var bidRegistered = false; @@ -56,6 +53,12 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { var zoneId = bid.params.zoneId || bid.params.zone; // accept both var size = getBiggerSize(bid.sizes); + // some of our formats doesn't have tools API exposed + var toolsAPI = window.com.stickyadstv.tools; + if (toolsAPI && toolsAPI.ASLoader) { + topMostWindow.stickyadstv_asLoader = new toolsAPI.ASLoader(zoneId, getComponentId(bid.params.format)); + } + var vastLoader = new window.com.stickyadstv.vast.VastLoader(); bid.vast = topMostWindow.stickyadstv_cache[bid.placementCode] = vastLoader.getVast(); @@ -79,17 +82,36 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { zoneId: zoneId, playerSize: size[0] + 'x' + size[1], vastUrlParams: bid.params.vastUrlParams, - componentId: 'prebid-sticky' + (bid.params.format ? '-' + bid.params.format : '') + componentId: getComponentId(bid.params.format) }; - if (bid.params.format === 'screen-roll') { - // in screenroll case we never use the original div size. - config.playerSize = window.com.stickyadstv.screenroll.getPlayerSize(); + var api = window.com.stickyadstv[getAPIName(bid.params.format)]; + if (api && typeof api.getPlayerSize === 'function') { + // in screenroll and similar cases we don't use the original div size. + config.playerSize = api.getPlayerSize(); } vastLoader.load(config, vastCallback); } + function getComponentId(inputFormat) { + var component = 'mustang'; // default component id + + if (inputFormat && inputFormat !== 'inbanner') { + // format identifiers are equals to their component ids. + component = inputFormat; + } + + return component; + } + + function getAPIName(componentId) { + componentId = componentId || ''; + + // remove dash in componentId to get API name + return componentId.replace('-', ''); + } + function getBiggerSize(array) { var result = [1, 1]; for (var i = 0; i < array.length; i++) { @@ -114,6 +136,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { ' autoPlay:true' + '};' + 'var ad = new topWindow.com.stickyadstv.vpaid.Ad(document.getElementById("stickyadstv_prebid_target"),config);' + + 'if(topWindow.stickyadstv_asLoader) topWindow.stickyadstv_asLoader.registerEvents(ad);' + 'ad.initAd(' + size[0] + ',' + size[1] + ',"",0,"","");' + ''; @@ -121,7 +144,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { return divHtml + script; }; - var formatIntextHTML = function(bid) { + var formatOutstreamHTML = function(bid) { var placementCode = bid.placementCode; var config = bid.params; @@ -136,7 +159,8 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { 'var topWindow = (function(){var res=window; try{while(top != res){if(res.parent.location.href.length)res=res.parent;}}catch(e){}return res;})();' + 'var vast = topWindow.stickyadstv_cache["' + placementCode + '"];' + 'var config = {' + - ' preloadedVast:vast'; + ' preloadedVast:vast,' + + ' ASLoader:topWindow.stickyadstv_asLoader'; for (var key in config) { // dont' send format parameter @@ -147,50 +171,20 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { } script += '};' + - 'topWindow.com.stickyadstv.intextroll.start(config);' + + 'topWindow.com.stickyadstv.' + getAPIName(bid.params.format) + '.start(config);' + ''; return script; }; - var formatScreenRollHTML = function(bid) { - var placementCode = bid.placementCode; - - var config = bid.params; - - var script = "'; - - return script; - }; function formatAdHTML(bid, size) { var integrationType = bid.params.format; var html = ''; - if (integrationType === 'intext-roll') { - html = formatIntextHTML(bid); - } else if (integrationType === 'screen-roll') { - html = formatScreenRollHTML(bid); + if (integrationType && integrationType !== 'inbanner') { + html = formatOutstreamHTML(bid); } else { html = formatInBannerHTML(bid, size); } @@ -202,7 +196,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { var priceData = vast.getPricing(); if (!priceData) { - utils.logWarn("StickyAdsTV: Bid pricing Can't be retreived. You may need to enable pricing on you're zone. Please get in touch with your sticky contact."); + console.warn("freewheel-ssp: Bid pricing Can't be retreived. You may need to enable pricing on you're zone. Please get in touch with your Freewheel contact."); } return priceData; @@ -265,6 +259,8 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { getBiggerSize: getBiggerSize, getBid: getBid, getTopMostWindow: getTopMostWindow, + getComponentId: getComponentId, + getAPIName: getAPIName, createNew: StickyAdsTVAdapter.createNew // enable alias feature (to be used for freewheel-ssp alias) }); }; diff --git a/test/spec/modules/stickyadstvBidAdapter_spec.js b/test/spec/modules/stickyadstvBidAdapter_spec.js index f9d98ce3ae2..c0f35b1c406 100644 --- a/test/spec/modules/stickyadstvBidAdapter_spec.js +++ b/test/spec/modules/stickyadstvBidAdapter_spec.js @@ -124,9 +124,9 @@ describe('StickyAdsTV Adapter', function () { delete window.com.stickyadstv; }); - it('should have returned a valid bidObject', function () { + it('should return a valid bidObject', function () { expect(bidResponse).to.have.property('cpm', 4.000); - expect(bidResponse).to.have.property('ad', ""); + expect(bidResponse).to.have.property('ad', ""); expect(bidResponse).to.have.property('bidderCode', 'stickyadstv'); expect(bidResponse).to.have.property('currencyCode', 'USD'); expect(bidResponse).to.have.property('width', 300); @@ -173,24 +173,24 @@ describe('StickyAdsTV Adapter', function () { it('should create an inBanner ad format', function () { let result = adapter.formatAdHTML({placementCode: 'placementCodeValue', params: {}}, [200, 300]); - expect(result).to.equal('
'); + expect(result).to.equal('
'); }); it('should create an intext ad format', function () { let result = adapter.formatAdHTML({placementCode: 'placementCodeValue', params: {format: 'intext-roll', auto: 'v2', smartPlay: 'true'}}, [200, 300]); - expect(result).to.equal(''); + expect(result).to.equal(''); }); it('should create a screenroll ad format', function () { let result = adapter.formatAdHTML({placementCode: 'placementCodeValue', params: {format: 'screen-roll', smartPlay: 'true'}}, [200, 300]); - expect(result).to.equal(''); + expect(result).to.equal(''); }); }); describe('getBiggerSize', function () { - it('should returns the bigger size', function () { + it('should return the bigger size', function () { let result = adapter.getBiggerSize([[1, 4000], [4000, 1], [200, 300], [0, 0]]); expect(result[0]).to.equal(200); @@ -199,10 +199,27 @@ describe('StickyAdsTV Adapter', function () { }); describe('top most window', function () { - it('should returns the top most window', function () { + it('should return the top most window', function () { let result = adapter.getTopMostWindow(); expect(result).to.equal(window.top); }); }); + + describe('get component id', function() { + it('should return valid component ids', function() { + expect(adapter.getComponentId('inbanner')).to.equal('mustang'); + expect(adapter.getComponentId('intext-roll')).to.equal('intext-roll'); + expect(adapter.getComponentId('screen-roll')).to.equal('screen-roll'); + }); + }); + + describe('get API name', function() { + it('should return valid API names', function() { + expect(adapter.getAPIName()).to.equal(''); + expect(adapter.getAPIName('intext-roll')).to.equal('intextroll'); + expect(adapter.getAPIName('screen-roll')).to.equal('screenroll'); + expect(adapter.getAPIName('floorad')).to.equal('floorad'); + }); + }); });