From 632c8c1c34bee8d26f568f8e99981e3cf0d87858 Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Thu, 5 Jan 2017 10:21:49 +0100 Subject: [PATCH 01/25] add stickyadsTV bidder adapter --- src/adapters/stickyadstv.js | 263 ++++++++++++++++++++++++++++++++++++ 1 file changed, 263 insertions(+) create mode 100644 src/adapters/stickyadstv.js diff --git a/src/adapters/stickyadstv.js b/src/adapters/stickyadstv.js new file mode 100644 index 00000000000..748701cb856 --- /dev/null +++ b/src/adapters/stickyadstv.js @@ -0,0 +1,263 @@ +var bidfactory = require('../bidfactory.js'); +var bidmanager = require('../bidmanager.js'); +var adloader = require('../adloader.js'); + +var StickyAdsTVAdapter = function StickyAdsTVAdapter() { + + var MUSTANG_URL = "http://cdn.stickyadstv.com/mustang/mustang.min.js"; + var INTEXTROLL_URL = "http://cdn.stickyadstv.com/prime-time/intext-roll.min.js"; + var SCREENROLL_URL = "http://cdn.stickyadstv.com/prime-time/screen-roll.min.js"; + + window.stickyadstv_cache = {}; + + function _callBids(params) { + + var bids = params.bids || []; + for (var i = 0; i < bids.length; i++) { + var bid = bids[i]; + // Send out bid request for each bid given its tag IDs and query strings + sendBidRequest(bid); + + } + } + + function sendBidRequest(bid){ + + var placementCode = bid.placementCode; + + 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; + } + + var bidRegistered = false; + adloader.loadScript(urltoLoad, function(){ + + getBid(bid, function(bidObject){ + if(!bidRegistered){ + bidRegistered = true; + onBidReceived(placementCode, bidObject); + } + + }); + }, true); + } + + function getBid(bid, callback){ + var zoneId = bid.params.zoneId || bid.params.zone; //accept both + var size = getBiggerSize(bid.sizes); + + var vastLoader = new window.com.stickyadstv.vast.VastLoader(); + bid.vast = window.stickyadstv_cache[bid.placementCode] = vastLoader.getVast(); + + var vastCallback = { + onSuccess : bind(function(){ + //'this' is the bid here + var bid = this; + + var adHtml = formatAdHTML(bid,size); + var price = extractPrice(bid.vast); + + callback(formatBidObject(true, price, adHtml, size[0], size[1])); + + },bid), + onError : bind(function(){ + callback(formatBidObject(false)); + },bid) + }; + + var config = { + zoneId:zoneId, + playerSize:size[0]+"x"+size[1], + vastUrlParams: bid.params.vastUrlParams, + componentId: "prebid-sticky-"+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(); + } + + vastLoader.load(config, vastCallback); + } + + function getBiggerSize(array){ + var result = [1,1]; + for(var i = 0; i< array.length; i++){ + if(array[i][0]*array[i][1] > result[0]*result[1]){ + result = array[i]; + } + } + return result; + } + + var formatInBannerHTML = function(bid,size){ + var placementCode = bid.placementCode; + + var divHtml = "
"; + + var script = ""; + + return divHtml+script; + }; + + var formatIntextHTML = function(bid){ + var placementCode = bid.placementCode; + + var config = bid.params; + + //default placement if no placement is set + if(!config.hasOwnProperty("domId") && !config.hasOwnProperty("auto") && !config.hasOwnProperty("p") && !config.hasOwnProperty("article")){ + config.domId = placementCode; + } + + var script = ""; + + 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); + } + else { + html = formatInBannerHTML(bid,size); + } + + return html; + } + + + function extractPrice(vast){ + var priceData = vast.getPricing(); + + if(!priceData) + { + console.warn("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."); + } + + return priceData; + } + + function formatBidObject(valid, priceData, html, width, height){ + var bidObject; + if(valid && priceData) { + // valid bid response + bidObject = bidfactory.createBid(1); + bidObject.bidderCode = 'stickyadstv'; + bidObject.cpm = priceData.price; + bidObject.currencyCode = priceData.currency; + bidObject.ad = html; + bidObject.width = width; + bidObject.height = height; + + } + else { + // invalid bid response + bidObject = bidfactory.createBid(2); + bidObject.bidderCode = 'stickyadstv'; + } + return bidObject; + } + + function onBidReceived(placementCode, bidObject){ + + console.log("Add Bid response:"+ bidObject); + // send the bidResponse object to bid manager with the adUnitCode. + bidmanager.addBidResponse(placementCode, bidObject); + + } + + /* Create a function bound to a given object (assigning `this`, and arguments, + * optionally). Binding with arguments is also known as `curry`. + * Delegates to **ECMAScript 5**'s native `Function.bind` if available. + * We check for `func.bind` first, to fail fast when `func` is undefined. + * + * @param {function} func + * @param {optional} context + * @param {...any} var_args + * @return {function} + */ + var bind = function(func, context) { + + return function() { + return func.apply(context,arguments); + }; + }; + + // Export the callBids function, so that prebid.js can execute + // this function when the page asks to send out bid requests. + return { + callBids: _callBids + }; +}; + +module.exports = StickyAdsTVAdapter; \ No newline at end of file From a91ac2d34afdca9039eb1210be2f8ad94157860f Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Thu, 5 Jan 2017 14:26:27 +0100 Subject: [PATCH 02/25] init unit test file --- adapters-sticky.json | 3 + src/adapters/stickyadstv.js | 18 ++- test/spec/adapters/stickyadstv_spec.js | 158 +++++++++++++++++++++++++ 3 files changed, 173 insertions(+), 6 deletions(-) create mode 100644 adapters-sticky.json create mode 100644 test/spec/adapters/stickyadstv_spec.js diff --git a/adapters-sticky.json b/adapters-sticky.json new file mode 100644 index 00000000000..5f410194f87 --- /dev/null +++ b/adapters-sticky.json @@ -0,0 +1,3 @@ +[ + "stickyadstv" +] diff --git a/src/adapters/stickyadstv.js b/src/adapters/stickyadstv.js index 748701cb856..46ed372e14f 100644 --- a/src/adapters/stickyadstv.js +++ b/src/adapters/stickyadstv.js @@ -4,9 +4,9 @@ var adloader = require('../adloader.js'); var StickyAdsTVAdapter = function StickyAdsTVAdapter() { - var MUSTANG_URL = "http://cdn.stickyadstv.com/mustang/mustang.min.js"; - var INTEXTROLL_URL = "http://cdn.stickyadstv.com/prime-time/intext-roll.min.js"; - var SCREENROLL_URL = "http://cdn.stickyadstv.com/prime-time/screen-roll.min.js"; + 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"; window.stickyadstv_cache = {}; @@ -16,7 +16,13 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { for (var i = 0; i < bids.length; i++) { var bid = bids[i]; // Send out bid request for each bid given its tag IDs and query strings - sendBidRequest(bid); + + if(bid.placementCode && bid.params.zoneId) { + sendBidRequest(bid); + } + else { + console.warn("StickyAdsTV: Missing mandatory field(s)."); + } } } @@ -39,6 +45,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { adloader.loadScript(urltoLoad, function(){ getBid(bid, function(bidObject){ + if(!bidRegistered){ bidRegistered = true; onBidReceived(placementCode, bidObject); @@ -199,8 +206,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { function extractPrice(vast){ var priceData = vast.getPricing(); - if(!priceData) - { + if(!priceData) { console.warn("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."); } diff --git a/test/spec/adapters/stickyadstv_spec.js b/test/spec/adapters/stickyadstv_spec.js new file mode 100644 index 00000000000..1bf862238fa --- /dev/null +++ b/test/spec/adapters/stickyadstv_spec.js @@ -0,0 +1,158 @@ +import {expect} from 'chai'; +import {assert} from 'chai'; +import Adapter from '../../../src/adapters/stickyadstv'; +import bidManager from '../../../src/bidmanager'; +import adLoader from '../../../src/adloader'; + +describe('StickyAdsTV Adapter', function () { + var adapter = void 0; + var sandbox = void 0; + var bidsRequestBuff = void 0; + var bidderRequest = { + bidderCode: 'stickyadstv', + bids: [{ + bidId: 'bidId1', + bidder: 'stickyadstv', + placementCode: 'foo', + sizes: [[300, 250]], + params: { + zoneId: '2003' + } + }, { + bidId: 'bidId2', + bidder: 'stickyadstv', + placementCode: 'bar', + sizes: [[728, 90]], + params: { + zoneId: '5562003' + } + }, { + bidId: 'bidId3', + bidder: 'stickyadstv', + placementCode: '', + sizes: [[300, 600]], + params: { + zoneId: '123456' + } + }, { + bidId: 'bidId4', + bidder: 'stickyadstv', + placementCode: 'coo', + sizes: [[300, 600]], + params: { + wrong: "missing zoneId" + } + }] + }; + + beforeEach(function () { + adapter = new Adapter(); + sandbox = sinon.sandbox.create(); + bidsRequestBuff = pbjs._bidsRequested; + pbjs._bidsRequested = []; + }); + + afterEach(function () { + sandbox.restore(); + pbjs._bidsRequested = bidsRequestBuff; + }); + + describe('callBids', function () { + beforeEach(function () { + sandbox.stub(adLoader, 'loadScript'); + adapter.callBids(bidderRequest); + }); + + it('should be called twice', function () { + sinon.assert.calledTwice(adLoader.loadScript); + }); + + it('should have load the mustang script', function () { + var url = void 0; + url = adLoader.loadScript.firstCall.args[0]; + expect(url).to.equal("//cdn.stickyadstv.com/mustang/mustang.min.js"); + }); + }); + + describe('getbids', function () { + beforeEach(function () { + adapter.getbids(); + }); + + it('should be called twice', function () { + sinon.assert.calledTwice(adLoader.loadScript); + }); + }); + + describe('Bid response', function () { + var vzBidRequest = void 0; + var bidderReponse = { + "vzhPlacementId": "VZ-HB-123", + "bid": "0fac1b8a-6ba0-4641-bd57-2899b1bedeae_0", + "adWidth": "300", + "adHeight": "250", + "cpm": "1.00000000000000", + "ad": "
", + "slotBidId": "bidId1", + "nurl": "", + "statusText": "vertoz:success" + }; + + beforeEach(function () { + pbjs._bidsRequested.push(bidderRequest); + }); + + describe('success', function () { + var firstBidReg = void 0; + var adSpaceId = void 0; + + beforeEach(function () { + sandbox.stub(_bidmanager2['default'], 'addBidResponse'); + pbjs.vzResponse(bidderReponse); + firstBidReg = bidManager.addBidResponse.firstCall.args[1]; + adSpaceId = bidManager.addBidResponse.firstCall.args[0]; + }); + + it('cpm to have property 1.000000', function () { + (0, _chai.expect)(firstBidReg).to.have.property('cpm', 1.00); + }); + it('adSpaceId should exist and be equal to placementCode', function () { + (0, _chai.expect)(adSpaceId).to.equal("foo"); + }); + it('should have property ad', function () { + (0, _chai.expect)(firstBidReg).to.have.property('ad'); + }); + it('should include the size to the bid object', function () { + (0, _chai.expect)(firstBidReg).to.have.property('width', '300'); + (0, _chai.expect)(firstBidReg).to.have.property('height', '250'); + }); + }); + + describe('failure', function () { + var secondBidReg = void 0; + var adSpaceId = void 0; + var bidderResponse = { + "vzhPlacementId": "VZ-HB-456", + "slotBidId": "bidId2", + "statusText": "vertoz:NO_BIDS" + }; + + beforeEach(function () { + sandbox.stub(bidManager, 'addBidResponse'); + pbjs.vzResponse(bidderResponse); + secondBidReg = bidManager.addBidResponse.firstCall.args[1]; + adSpaceId = bidManager.addBidResponse.firstCall.args[0]; + }); + + it('should not have cpm property', function () { + (0, _chai.expect)(secondBidReg.cpm).to.be.undefined; + }); + it('adSpaceId should exist and be equal to placementCode', function () { + (0, _chai.expect)(adSpaceId).to.equal("bar"); + }); + it('should not have ad property', function () { + (0, _chai.expect)(secondBidReg.ad).to.be.undefined; + }); + }); + }); +}); \ No newline at end of file From 9e2d70ea29379115ad970079ccc1141138fcb905 Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Thu, 5 Jan 2017 17:44:03 +0100 Subject: [PATCH 03/25] ad some unit tests --- src/adapters/stickyadstv.js | 4 +- test/spec/adapters/stickyadstv_spec.js | 267 +++++++++++-------------- 2 files changed, 121 insertions(+), 150 deletions(-) diff --git a/src/adapters/stickyadstv.js b/src/adapters/stickyadstv.js index 46ed372e14f..98554a7f31f 100644 --- a/src/adapters/stickyadstv.js +++ b/src/adapters/stickyadstv.js @@ -262,7 +262,9 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { // Export the callBids function, so that prebid.js can execute // this function when the page asks to send out bid requests. return { - callBids: _callBids + callBids: _callBids, + formatBidObject: formatBidObject, + formatAdHTML: formatAdHTML }; }; diff --git a/test/spec/adapters/stickyadstv_spec.js b/test/spec/adapters/stickyadstv_spec.js index 1bf862238fa..9d619abcf09 100644 --- a/test/spec/adapters/stickyadstv_spec.js +++ b/test/spec/adapters/stickyadstv_spec.js @@ -5,154 +5,123 @@ import bidManager from '../../../src/bidmanager'; import adLoader from '../../../src/adloader'; describe('StickyAdsTV Adapter', function () { - var adapter = void 0; - var sandbox = void 0; - var bidsRequestBuff = void 0; - var bidderRequest = { - bidderCode: 'stickyadstv', - bids: [{ - bidId: 'bidId1', - bidder: 'stickyadstv', - placementCode: 'foo', - sizes: [[300, 250]], - params: { - zoneId: '2003' - } - }, { - bidId: 'bidId2', - bidder: 'stickyadstv', - placementCode: 'bar', - sizes: [[728, 90]], - params: { - zoneId: '5562003' - } - }, { - bidId: 'bidId3', - bidder: 'stickyadstv', - placementCode: '', - sizes: [[300, 600]], - params: { - zoneId: '123456' - } - }, { - bidId: 'bidId4', - bidder: 'stickyadstv', - placementCode: 'coo', - sizes: [[300, 600]], - params: { - wrong: "missing zoneId" - } - }] - }; + var adapter = void 0; + var sandbox = void 0; + var bidsRequestBuff = void 0; + var bidderRequest = { + bidderCode: 'stickyadstv', + bids: [{ + bidId: 'bidId1', + bidder: 'stickyadstv', + placementCode: 'foo', + sizes: [[300, 250]], + params: { + zoneId: '2003' + } + }, { + bidId: 'bidId2', + bidder: 'stickyadstv', + placementCode: 'bar', + sizes: [[728, 90]], + params: { + zoneId: '5562003' + } + }, { + bidId: 'bidId3', + bidder: 'stickyadstv', + placementCode: '', + sizes: [[300, 600]], + params: { + zoneId: '123456' + } + }, { + bidId: 'bidId4', + bidder: 'stickyadstv', + placementCode: 'coo', + sizes: [[300, 600]], + params: { + wrong: "missing zoneId" + } + }] + }; + + beforeEach(function () { + adapter = new Adapter(); + sandbox = sinon.sandbox.create(); + bidsRequestBuff = pbjs._bidsRequested; + pbjs._bidsRequested = []; + }); + + afterEach(function () { + sandbox.restore(); + pbjs._bidsRequested = bidsRequestBuff; + }); + + describe('callBids', function () { + beforeEach(function () { + sandbox.stub(adLoader, 'loadScript'); + adapter.callBids(bidderRequest); + }); + + it('should be called twice', function () { + sinon.assert.calledTwice(adLoader.loadScript); + }); + + it('should have load the mustang script', function () { + var url = void 0; + url = adLoader.loadScript.firstCall.args[0]; + expect(url).to.equal("//cdn.stickyadstv.com/mustang/mustang.min.js"); + }); + }); + + describe('formatBidObject', function () { + + it('should create a valid bid object', function () { + let result = adapter.formatBidObject(true, {currency:"EUR",price:"1.2345"}, "
sample
", 200, 300); + + expect(result).to.have.property('cpm', '1.2345'); + expect(result).to.have.property('ad', "
sample
"); + expect(result).to.have.property('bidderCode', "stickyadstv"); + expect(result).to.have.property('currencyCode', "EUR"); + expect(result).to.have.property('width', 200); + expect(result).to.have.property('height', 300); + expect(result.getStatusCode()).to.equal(1); + }); + + it('should create a invalid bid object because price is not defined', function () { + let result = adapter.formatBidObject(true, null, "
sample
", 200, 300); + + expect(result).to.have.property('bidderCode', "stickyadstv"); + expect(result.getStatusCode()).to.equal(2); + }); + + it('should create a invalid bid object', function () { + let result = adapter.formatBidObject(false, {currency:"EUR",price:"1.2345"}, "
sample
", 200, 300); + + expect(result).to.have.property('bidderCode', "stickyadstv"); + expect(result.getStatusCode()).to.equal(2); + }); + }); + + describe('formatAdHTML', function () { + + it('should create an inBanner ad format', function () { + let result = adapter.formatAdHTML({placementCode:"placementCodeValue", params:{}}, [200,300]); + + 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(""); + }); + + it('should create a screenroll ad format', function () { + let result = adapter.formatAdHTML({placementCode:"placementCodeValue", params:{format:"screen-roll"}}, [200,300]); + + expect(result).to.equal(""); + }); + }); - beforeEach(function () { - adapter = new Adapter(); - sandbox = sinon.sandbox.create(); - bidsRequestBuff = pbjs._bidsRequested; - pbjs._bidsRequested = []; - }); - - afterEach(function () { - sandbox.restore(); - pbjs._bidsRequested = bidsRequestBuff; - }); - - describe('callBids', function () { - beforeEach(function () { - sandbox.stub(adLoader, 'loadScript'); - adapter.callBids(bidderRequest); - }); - - it('should be called twice', function () { - sinon.assert.calledTwice(adLoader.loadScript); - }); - - it('should have load the mustang script', function () { - var url = void 0; - url = adLoader.loadScript.firstCall.args[0]; - expect(url).to.equal("//cdn.stickyadstv.com/mustang/mustang.min.js"); - }); - }); - - describe('getbids', function () { - beforeEach(function () { - adapter.getbids(); - }); - - it('should be called twice', function () { - sinon.assert.calledTwice(adLoader.loadScript); - }); - }); - - describe('Bid response', function () { - var vzBidRequest = void 0; - var bidderReponse = { - "vzhPlacementId": "VZ-HB-123", - "bid": "0fac1b8a-6ba0-4641-bd57-2899b1bedeae_0", - "adWidth": "300", - "adHeight": "250", - "cpm": "1.00000000000000", - "ad": "
", - "slotBidId": "bidId1", - "nurl": "", - "statusText": "vertoz:success" - }; - - beforeEach(function () { - pbjs._bidsRequested.push(bidderRequest); - }); - - describe('success', function () { - var firstBidReg = void 0; - var adSpaceId = void 0; - - beforeEach(function () { - sandbox.stub(_bidmanager2['default'], 'addBidResponse'); - pbjs.vzResponse(bidderReponse); - firstBidReg = bidManager.addBidResponse.firstCall.args[1]; - adSpaceId = bidManager.addBidResponse.firstCall.args[0]; - }); - - it('cpm to have property 1.000000', function () { - (0, _chai.expect)(firstBidReg).to.have.property('cpm', 1.00); - }); - it('adSpaceId should exist and be equal to placementCode', function () { - (0, _chai.expect)(adSpaceId).to.equal("foo"); - }); - it('should have property ad', function () { - (0, _chai.expect)(firstBidReg).to.have.property('ad'); - }); - it('should include the size to the bid object', function () { - (0, _chai.expect)(firstBidReg).to.have.property('width', '300'); - (0, _chai.expect)(firstBidReg).to.have.property('height', '250'); - }); - }); - - describe('failure', function () { - var secondBidReg = void 0; - var adSpaceId = void 0; - var bidderResponse = { - "vzhPlacementId": "VZ-HB-456", - "slotBidId": "bidId2", - "statusText": "vertoz:NO_BIDS" - }; - - beforeEach(function () { - sandbox.stub(bidManager, 'addBidResponse'); - pbjs.vzResponse(bidderResponse); - secondBidReg = bidManager.addBidResponse.firstCall.args[1]; - adSpaceId = bidManager.addBidResponse.firstCall.args[0]; - }); - - it('should not have cpm property', function () { - (0, _chai.expect)(secondBidReg.cpm).to.be.undefined; - }); - it('adSpaceId should exist and be equal to placementCode', function () { - (0, _chai.expect)(adSpaceId).to.equal("bar"); - }); - it('should not have ad property', function () { - (0, _chai.expect)(secondBidReg.ad).to.be.undefined; - }); - }); - }); }); \ No newline at end of file From 9c92c3e852c47a0412d470e8e90fbcb89a6626b6 Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Thu, 5 Jan 2017 18:22:43 +0100 Subject: [PATCH 04/25] fix unit test on ad format with parameters --- test/spec/adapters/stickyadstv_spec.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/spec/adapters/stickyadstv_spec.js b/test/spec/adapters/stickyadstv_spec.js index 9d619abcf09..19557bd2755 100644 --- a/test/spec/adapters/stickyadstv_spec.js +++ b/test/spec/adapters/stickyadstv_spec.js @@ -114,13 +114,13 @@ describe('StickyAdsTV Adapter', function () { 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"}}, [200,300]); + let result = adapter.formatAdHTML({placementCode:"placementCodeValue", params:{format:"screen-roll", smartPlay:"true"}}, [200,300]); - expect(result).to.equal(""); + expect(result).to.equal(""); }); }); From 7ed68e95c81d8590442f66e0277a72196ba8fa50 Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Fri, 6 Jan 2017 15:31:54 +0100 Subject: [PATCH 05/25] add some unit tests --- src/adapters/stickyadstv.js | 13 +++---------- test/spec/adapters/stickyadstv_spec.js | 12 +++++++++++- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/adapters/stickyadstv.js b/src/adapters/stickyadstv.js index 98554a7f31f..fb5a0841ae8 100644 --- a/src/adapters/stickyadstv.js +++ b/src/adapters/stickyadstv.js @@ -48,7 +48,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { if(!bidRegistered){ bidRegistered = true; - onBidReceived(placementCode, bidObject); + bidmanager.addBidResponse(placementCode, bidObject); } }); @@ -234,14 +234,6 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { return bidObject; } - function onBidReceived(placementCode, bidObject){ - - console.log("Add Bid response:"+ bidObject); - // send the bidResponse object to bid manager with the adUnitCode. - bidmanager.addBidResponse(placementCode, bidObject); - - } - /* Create a function bound to a given object (assigning `this`, and arguments, * optionally). Binding with arguments is also known as `curry`. * Delegates to **ECMAScript 5**'s native `Function.bind` if available. @@ -264,7 +256,8 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { return { callBids: _callBids, formatBidObject: formatBidObject, - formatAdHTML: formatAdHTML + formatAdHTML: formatAdHTML, + getBiggerSize:getBiggerSize }; }; diff --git a/test/spec/adapters/stickyadstv_spec.js b/test/spec/adapters/stickyadstv_spec.js index 19557bd2755..6972e4d8bc0 100644 --- a/test/spec/adapters/stickyadstv_spec.js +++ b/test/spec/adapters/stickyadstv_spec.js @@ -120,7 +120,17 @@ describe('StickyAdsTV Adapter', function () { 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 () { + let result = adapter.getBiggerSize([[1,4000],[4000,1],[200,300],[0,0]]); + + expect(result[0]).to.equal(200); + expect(result[1]).to.equal(300); }); }); From 88a45ac96f8c3fe445cf0ac26d06d2ab90eaaeca Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Fri, 6 Jan 2017 16:01:41 +0100 Subject: [PATCH 06/25] add unit tests on getBid method --- src/adapters/stickyadstv.js | 3 +- test/spec/adapters/stickyadstv_spec.js | 56 ++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/src/adapters/stickyadstv.js b/src/adapters/stickyadstv.js index fb5a0841ae8..30b818215da 100644 --- a/src/adapters/stickyadstv.js +++ b/src/adapters/stickyadstv.js @@ -257,7 +257,8 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { callBids: _callBids, formatBidObject: formatBidObject, formatAdHTML: formatAdHTML, - getBiggerSize:getBiggerSize + getBiggerSize:getBiggerSize, + getBid:getBid }; }; diff --git a/test/spec/adapters/stickyadstv_spec.js b/test/spec/adapters/stickyadstv_spec.js index 6972e4d8bc0..5f262224312 100644 --- a/test/spec/adapters/stickyadstv_spec.js +++ b/test/spec/adapters/stickyadstv_spec.js @@ -74,6 +74,62 @@ describe('StickyAdsTV Adapter', function () { }); }); + describe('getBid', function () { + let bidRespone; + let getPricingCalled; + + beforeEach(function () { + //Mock VastLoader for test purpose + window.com = { + stickyadstv : { + vast : { + VastLoader : function(){ + this.getVast = function(){ + return { + getPricing : function(){ + getPricingCalled = true; + return {currency:"USD", price: 4.000} + } + }; + }; + + this.load = function(config, listener){ + listener.onSuccess(); + }; + } + } + } + }; + + adapter.getBid(bidderRequest.bids[0], function(bidObject){ + bidRespone = bidObject; + }); + }); + + afterEach(function() { + delete window.com.stickyadstv.vast.VastLoader; + delete window.com.stickyadstv.vast; + delete window.com.stickyadstv; + }); + + it('should have returned a valid bidObject', function () { + + expect(bidRespone).to.have.property('cpm', 4.000); + expect(bidRespone).to.have.property('ad', "
"); + expect(bidRespone).to.have.property('bidderCode', "stickyadstv"); + expect(bidRespone).to.have.property('currencyCode', "USD"); + expect(bidRespone).to.have.property('width', 300); + expect(bidRespone).to.have.property('height', 250); + expect(bidRespone.getStatusCode()).to.equal(1); + }); + + it('should have called getPricing', function () { + + expect(getPricingCalled).to.equal(true); + + }); + }); + describe('formatBidObject', function () { it('should create a valid bid object', function () { From 7d6bf3c3484391c841d67eb8b7c6269720a92eec Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Fri, 6 Jan 2017 16:21:40 +0100 Subject: [PATCH 07/25] add some test cases in unit tests --- test/spec/adapters/stickyadstv_spec.js | 42 +++++++++++++++++++------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/test/spec/adapters/stickyadstv_spec.js b/test/spec/adapters/stickyadstv_spec.js index 5f262224312..6869f1264dd 100644 --- a/test/spec/adapters/stickyadstv_spec.js +++ b/test/spec/adapters/stickyadstv_spec.js @@ -16,7 +16,8 @@ describe('StickyAdsTV Adapter', function () { placementCode: 'foo', sizes: [[300, 250]], params: { - zoneId: '2003' + zoneId: '2003', + format:"screen-roll" } }, { bidId: 'bidId2', @@ -67,15 +68,20 @@ describe('StickyAdsTV Adapter', function () { sinon.assert.calledTwice(adLoader.loadScript); }); - it('should have load the mustang script', function () { + it('should have load screenroll and mustang script', function () { var url = void 0; + url = adLoader.loadScript.firstCall.args[0]; + expect(url).to.equal("//cdn.stickyadstv.com/prime-time/screen-roll.min.js"); + + url = adLoader.loadScript.secondCall.args[0]; expect(url).to.equal("//cdn.stickyadstv.com/mustang/mustang.min.js"); }); }); describe('getBid', function () { - let bidRespone; + let bidResponse; + let loadConfig; let getPricingCalled; beforeEach(function () { @@ -94,33 +100,47 @@ describe('StickyAdsTV Adapter', function () { }; this.load = function(config, listener){ + loadConfig = config; listener.onSuccess(); }; } + }, + screenroll : { + getPlayerSize: function(){ + return "123x456"; + } } } }; adapter.getBid(bidderRequest.bids[0], function(bidObject){ - bidRespone = bidObject; + bidResponse = bidObject; }); }); afterEach(function() { delete window.com.stickyadstv.vast.VastLoader; delete window.com.stickyadstv.vast; + delete window.com.stickyadstv.screenroll; delete window.com.stickyadstv; }); it('should have returned a valid bidObject', function () { - expect(bidRespone).to.have.property('cpm', 4.000); - expect(bidRespone).to.have.property('ad', "
"); - expect(bidRespone).to.have.property('bidderCode', "stickyadstv"); - expect(bidRespone).to.have.property('currencyCode', "USD"); - expect(bidRespone).to.have.property('width', 300); - expect(bidRespone).to.have.property('height', 250); - expect(bidRespone.getStatusCode()).to.equal(1); + expect(bidResponse).to.have.property('cpm', 4.000); + 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); + expect(bidResponse).to.have.property('height', 250); + expect(bidResponse.getStatusCode()).to.equal(1); + }); + + it('should have called load with proper config', function () { + + expect(loadConfig).to.have.property('playerSize', "123x456"); + expect(loadConfig).to.have.property('zoneId', "2003"); + }); it('should have called getPricing', function () { From affdd67a855f8d9cb3e5a45b80f4f6c6f24ff392 Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Mon, 9 Jan 2017 15:24:58 +0100 Subject: [PATCH 08/25] minor fix on component id tag. --- adapters.json | 1 + src/adapters/stickyadstv.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/adapters.json b/adapters.json index a49141c8345..f28bfab3af2 100644 --- a/adapters.json +++ b/adapters.json @@ -29,6 +29,7 @@ "sonobi", "sovrn", "springserve", + "stickyadstv", "triplelift", "yieldbot", "nginad", diff --git a/src/adapters/stickyadstv.js b/src/adapters/stickyadstv.js index 30b818215da..7fe851285db 100644 --- a/src/adapters/stickyadstv.js +++ b/src/adapters/stickyadstv.js @@ -82,7 +82,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { zoneId:zoneId, playerSize:size[0]+"x"+size[1], vastUrlParams: bid.params.vastUrlParams, - componentId: "prebid-sticky-"+bid.params.format + componentId: "prebid-sticky"+(bid.params.format ? "-"+bid.params.format : "") }; if(bid.params.format === "screen-roll"){ From 654a473048b43719a6a0fa7dc87d3ef8a86d439a Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Thu, 12 Jan 2017 10:16:54 +0100 Subject: [PATCH 09/25] remove adapters-sticky.json test file --- adapters-sticky.json | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 adapters-sticky.json diff --git a/adapters-sticky.json b/adapters-sticky.json deleted file mode 100644 index 5f410194f87..00000000000 --- a/adapters-sticky.json +++ /dev/null @@ -1,3 +0,0 @@ -[ - "stickyadstv" -] From 8c0f1438605ddfcaa1d2b8bdd49294566cc573fc Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Thu, 26 Jan 2017 16:17:18 +0100 Subject: [PATCH 10/25] use top most accessible window instead of window.top --- src/adapters/stickyadstv.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/adapters/stickyadstv.js b/src/adapters/stickyadstv.js index 7fe851285db..b682b16b3f4 100644 --- a/src/adapters/stickyadstv.js +++ b/src/adapters/stickyadstv.js @@ -109,13 +109,14 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { var divHtml = "
"; var script = ""; @@ -135,7 +136,8 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { var script = ""; @@ -163,7 +165,8 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { var script = ""; From fd877dc69095241a554c4e6f53c5351750925867 Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Thu, 26 Jan 2017 16:35:38 +0100 Subject: [PATCH 11/25] Pass in the bid request in the createBid call. --- src/adapters/stickyadstv.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/adapters/stickyadstv.js b/src/adapters/stickyadstv.js index b682b16b3f4..647f3a14662 100644 --- a/src/adapters/stickyadstv.js +++ b/src/adapters/stickyadstv.js @@ -64,17 +64,17 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { var vastCallback = { onSuccess : bind(function(){ - //'this' is the bid here - var bid = this; + //'this' is the bid request here + var bidRequest = this; - var adHtml = formatAdHTML(bid,size); - var price = extractPrice(bid.vast); + var adHtml = formatAdHTML(bidRequest,size); + var price = extractPrice(bidRequest.vast); - callback(formatBidObject(true, price, adHtml, size[0], size[1])); + callback(formatBidObject(bidRequest, true, price, adHtml, size[0], size[1])); },bid), onError : bind(function(){ - callback(formatBidObject(false)); + callback(formatBidObject(bidRequest, false)); },bid) }; @@ -216,11 +216,11 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { return priceData; } - function formatBidObject(valid, priceData, html, width, height){ + function formatBidObject(bidRequest, valid, priceData, html, width, height){ var bidObject; if(valid && priceData) { // valid bid response - bidObject = bidfactory.createBid(1); + bidObject = bidfactory.createBid(1, bidRequest); bidObject.bidderCode = 'stickyadstv'; bidObject.cpm = priceData.price; bidObject.currencyCode = priceData.currency; @@ -231,7 +231,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { } else { // invalid bid response - bidObject = bidfactory.createBid(2); + bidObject = bidfactory.createBid(2, bidRequest); bidObject.bidderCode = 'stickyadstv'; } return bidObject; From 09f7348fe3e7ff4d4d444c40ce05b9001c36d75a Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Fri, 3 Feb 2017 16:49:51 +0100 Subject: [PATCH 12/25] use top most accessible window instead of window.top --- src/adapters/stickyadstv.js | 47 +++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/src/adapters/stickyadstv.js b/src/adapters/stickyadstv.js index 647f3a14662..90fbf569e55 100644 --- a/src/adapters/stickyadstv.js +++ b/src/adapters/stickyadstv.js @@ -8,7 +8,8 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { var INTEXTROLL_URL = "//cdn.stickyadstv.com/prime-time/intext-roll.min.js"; var SCREENROLL_URL = "//cdn.stickyadstv.com/prime-time/screen-roll.min.js"; - window.stickyadstv_cache = {}; + var topMostWindow = getTopMostWindow(); + topMostWindow.stickyadstv_cache = {}; function _callBids(params) { @@ -64,6 +65,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { var vastCallback = { onSuccess : bind(function(){ + //'this' is the bid request here var bidRequest = this; @@ -74,6 +76,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { },bid), onError : bind(function(){ + var bidRequest = this; callback(formatBidObject(bidRequest, false)); },bid) }; @@ -109,14 +112,14 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { var divHtml = "
"; var script = ""; @@ -135,9 +138,9 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { } var script = ""; @@ -165,8 +168,9 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { var script = ""; @@ -237,6 +241,24 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { return bidObject; } + + /** + * returns the top most accessible window + */ + function getTopMostWindow(){ + var res=window; + + try { + while(top != res){ + if(res.parent.location.href.length) + res=res.parent; + } + } + catch(e){} + + return res; + } + /* Create a function bound to a given object (assigning `this`, and arguments, * optionally). Binding with arguments is also known as `curry`. * Delegates to **ECMAScript 5**'s native `Function.bind` if available. @@ -254,6 +276,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { }; }; + // Export the callBids function, so that prebid.js can execute // this function when the page asks to send out bid requests. return { From 90264e8c34cef8344a1cc68893f6244729a17f23 Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Fri, 3 Feb 2017 16:58:07 +0100 Subject: [PATCH 13/25] add unit tests --- src/adapters/stickyadstv.js | 3 ++- test/spec/adapters/stickyadstv_spec.js | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/adapters/stickyadstv.js b/src/adapters/stickyadstv.js index 90fbf569e55..3408af5e23b 100644 --- a/src/adapters/stickyadstv.js +++ b/src/adapters/stickyadstv.js @@ -284,7 +284,8 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { formatBidObject: formatBidObject, formatAdHTML: formatAdHTML, getBiggerSize:getBiggerSize, - getBid:getBid + getBid:getBid, + getTopMostWindow:getTopMostWindow }; }; diff --git a/test/spec/adapters/stickyadstv_spec.js b/test/spec/adapters/stickyadstv_spec.js index 6869f1264dd..3fa253eca32 100644 --- a/test/spec/adapters/stickyadstv_spec.js +++ b/test/spec/adapters/stickyadstv_spec.js @@ -210,4 +210,13 @@ describe('StickyAdsTV Adapter', function () { }); }); + describe('top most window', function () { + + it('should returns the top most window', function () { + let result = adapter.getTopMostWindow(); + + expect(result).to.equal(window.top); + }); + }); + }); \ No newline at end of file From 29453af7cf5e0e19001c4080a216be5baeec937f Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Fri, 3 Feb 2017 17:23:23 +0100 Subject: [PATCH 14/25] update unit tests --- test/spec/adapters/stickyadstv_spec.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/spec/adapters/stickyadstv_spec.js b/test/spec/adapters/stickyadstv_spec.js index 3fa253eca32..eb665ec658c 100644 --- a/test/spec/adapters/stickyadstv_spec.js +++ b/test/spec/adapters/stickyadstv_spec.js @@ -128,7 +128,7 @@ describe('StickyAdsTV Adapter', function () { it('should have returned 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); @@ -153,7 +153,7 @@ describe('StickyAdsTV Adapter', function () { describe('formatBidObject', function () { it('should create a valid bid object', function () { - let result = adapter.formatBidObject(true, {currency:"EUR",price:"1.2345"}, "
sample
", 200, 300); + let result = adapter.formatBidObject("", true, {currency:"EUR",price:"1.2345"}, "
sample
", 200, 300); expect(result).to.have.property('cpm', '1.2345'); expect(result).to.have.property('ad', "
sample
"); @@ -165,14 +165,14 @@ describe('StickyAdsTV Adapter', function () { }); it('should create a invalid bid object because price is not defined', function () { - let result = adapter.formatBidObject(true, null, "
sample
", 200, 300); + let result = adapter.formatBidObject("", true, null, "
sample
", 200, 300); expect(result).to.have.property('bidderCode', "stickyadstv"); expect(result.getStatusCode()).to.equal(2); }); it('should create a invalid bid object', function () { - let result = adapter.formatBidObject(false, {currency:"EUR",price:"1.2345"}, "
sample
", 200, 300); + let result = adapter.formatBidObject("", false, {currency:"EUR",price:"1.2345"}, "
sample
", 200, 300); expect(result).to.have.property('bidderCode', "stickyadstv"); expect(result.getStatusCode()).to.equal(2); @@ -184,19 +184,19 @@ 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(''); }); }); From b664ee1e883416502ca398e3d5b1363373ee4046 Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Fri, 3 Feb 2017 17:33:23 +0100 Subject: [PATCH 15/25] fix unit test. --- src/adapters/stickyadstv.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/adapters/stickyadstv.js b/src/adapters/stickyadstv.js index 3408af5e23b..baf910e386e 100644 --- a/src/adapters/stickyadstv.js +++ b/src/adapters/stickyadstv.js @@ -61,7 +61,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { var size = getBiggerSize(bid.sizes); var vastLoader = new window.com.stickyadstv.vast.VastLoader(); - bid.vast = window.stickyadstv_cache[bid.placementCode] = vastLoader.getVast(); + bid.vast = topMostWindow.stickyadstv_cache[bid.placementCode] = vastLoader.getVast(); var vastCallback = { onSuccess : bind(function(){ From 57c31a1208459b3b0de61cb01b0f5a92b43ed9d3 Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Mon, 6 Feb 2017 09:49:19 +0100 Subject: [PATCH 16/25] fix CI build --- src/adapters/stickyadstv.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/adapters/stickyadstv.js b/src/adapters/stickyadstv.js index baf910e386e..803cd626d56 100644 --- a/src/adapters/stickyadstv.js +++ b/src/adapters/stickyadstv.js @@ -249,7 +249,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { var res=window; try { - while(top != res){ + while(top !== res){ if(res.parent.location.href.length) res=res.parent; } From 475eee312693498b6b8ec7e2c35eaa0c0420af98 Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Thu, 2 Mar 2017 14:25:12 +0100 Subject: [PATCH 17/25] add alias freewheel-ssp --- adapters.json | 5 +++++ src/adapters/stickyadstv.js | 19 ++++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/adapters.json b/adapters.json index dc7796ea482..6b711d02aae 100644 --- a/adapters.json +++ b/adapters.json @@ -107,6 +107,11 @@ "getintent": { "supportedMediaTypes" : ["video"] } + }, + { + "stickyadstv": { + "alias": "freewheel-ssp" + } } ] diff --git a/src/adapters/stickyadstv.js b/src/adapters/stickyadstv.js index 803cd626d56..221898df1f0 100644 --- a/src/adapters/stickyadstv.js +++ b/src/adapters/stickyadstv.js @@ -1,9 +1,11 @@ +var Adapter = require('./adapter.js'); var bidfactory = require('../bidfactory.js'); var bidmanager = require('../bidmanager.js'); var adloader = require('../adloader.js'); 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"; @@ -225,7 +227,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { if(valid && priceData) { // valid bid response bidObject = bidfactory.createBid(1, bidRequest); - bidObject.bidderCode = 'stickyadstv'; + bidObject.bidderCode = bidRequest.bidder; bidObject.cpm = priceData.price; bidObject.currencyCode = priceData.currency; bidObject.ad = html; @@ -236,7 +238,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { else { // invalid bid response bidObject = bidfactory.createBid(2, bidRequest); - bidObject.bidderCode = 'stickyadstv'; + bidObject.bidderCode = bidRequest.bidder; } return bidObject; } @@ -277,16 +279,19 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { }; - // Export the callBids function, so that prebid.js can execute - // this function when the page asks to send out bid requests. - return { + return Object.assign(Adapter.createNew(STICKYADS_BIDDERCODE), { callBids: _callBids, formatBidObject: formatBidObject, formatAdHTML: formatAdHTML, getBiggerSize:getBiggerSize, getBid:getBid, - getTopMostWindow:getTopMostWindow - }; + getTopMostWindow:getTopMostWindow, + createNew: StickyAdsTVAdapter.createNew //enable alias feature (to be used for freewheel-ssp alias) + }); +}; + +StickyAdsTVAdapter.createNew = function() { + return new StickyAdsTVAdapter(); }; module.exports = StickyAdsTVAdapter; \ No newline at end of file From 410ee003e22d5f9cfba346d538348239ab5164d5 Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Fri, 10 Mar 2017 16:33:24 +0100 Subject: [PATCH 18/25] update unit tests on bidderCode value --- test/spec/adapters/stickyadstv_spec.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/spec/adapters/stickyadstv_spec.js b/test/spec/adapters/stickyadstv_spec.js index eb665ec658c..b485416f614 100644 --- a/test/spec/adapters/stickyadstv_spec.js +++ b/test/spec/adapters/stickyadstv_spec.js @@ -157,7 +157,6 @@ describe('StickyAdsTV Adapter', function () { expect(result).to.have.property('cpm', '1.2345'); expect(result).to.have.property('ad', "
sample
"); - expect(result).to.have.property('bidderCode', "stickyadstv"); expect(result).to.have.property('currencyCode', "EUR"); expect(result).to.have.property('width', 200); expect(result).to.have.property('height', 300); @@ -167,14 +166,12 @@ describe('StickyAdsTV Adapter', function () { it('should create a invalid bid object because price is not defined', function () { let result = adapter.formatBidObject("", true, null, "
sample
", 200, 300); - expect(result).to.have.property('bidderCode', "stickyadstv"); expect(result.getStatusCode()).to.equal(2); }); it('should create a invalid bid object', function () { let result = adapter.formatBidObject("", false, {currency:"EUR",price:"1.2345"}, "
sample
", 200, 300); - expect(result).to.have.property('bidderCode', "stickyadstv"); expect(result.getStatusCode()).to.equal(2); }); }); From b09dfdd9077bbe07db119b3138d0f484614bd2ed Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Fri, 16 Jun 2017 11:21:54 +0200 Subject: [PATCH 19/25] fix component id values and add unit tests --- src/adapters/stickyadstv.js | 14 +++++++++++++- test/spec/adapters/stickyadstv_spec.js | 8 ++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/adapters/stickyadstv.js b/src/adapters/stickyadstv.js index d0095541a8f..55162532f17 100644 --- a/src/adapters/stickyadstv.js +++ b/src/adapters/stickyadstv.js @@ -77,7 +77,7 @@ 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') { @@ -88,6 +88,17 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { vastLoader.load(config, vastCallback); } + function getComponentId(inputFormat) { + var component = "mustang"; //default component id + + if(inputFormat == FORMAT_INTEXT || inputFormat == FORMAT_SCREEN){ + //format identifiers are equals to their component ids. + component = inputFormat; + } + + return component; + } + function getBiggerSize(array) { var result = [1, 1]; for (var i = 0; i < array.length; i++) { @@ -263,6 +274,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { getBiggerSize: getBiggerSize, getBid: getBid, getTopMostWindow: getTopMostWindow, + getComponentId: getComponentId, createNew: StickyAdsTVAdapter.createNew // enable alias feature (to be used for freewheel-ssp alias) }); }; diff --git a/test/spec/adapters/stickyadstv_spec.js b/test/spec/adapters/stickyadstv_spec.js index 96a589ea07d..74438c2b0aa 100644 --- a/test/spec/adapters/stickyadstv_spec.js +++ b/test/spec/adapters/stickyadstv_spec.js @@ -206,4 +206,12 @@ describe('StickyAdsTV Adapter', function () { expect(result).to.equal(window.top); }); }); + + describe('get component id', function(){ + it('should returns 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"); + }); + }); }); From d52df6f193a0c965257ab73ca296a48ae1ae87cb Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Tue, 20 Jun 2017 10:45:42 +0200 Subject: [PATCH 20/25] allws to use any outstream format. --- src/adapters/stickyadstv.js | 81 ++++++++++---------------- test/spec/adapters/stickyadstv_spec.js | 10 ++++ 2 files changed, 42 insertions(+), 49 deletions(-) diff --git a/src/adapters/stickyadstv.js b/src/adapters/stickyadstv.js index 55162532f17..a48c184af16 100644 --- a/src/adapters/stickyadstv.js +++ b/src/adapters/stickyadstv.js @@ -6,8 +6,7 @@ var adloader = require('../adloader.js'); 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 = {}; @@ -32,11 +31,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; @@ -54,6 +51,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(); @@ -77,28 +80,36 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { zoneId: zoneId, playerSize: size[0] + 'x' + size[1], vastUrlParams: bid.params.vastUrlParams, - componentId: getComponentId(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 + var component = 'mustang'; // default component id - if(inputFormat == FORMAT_INTEXT || inputFormat == FORMAT_SCREEN){ - //format identifiers are equals to their component ids. + 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++) { @@ -123,6 +134,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,"","");' + ''; @@ -130,7 +142,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { return divHtml + script; }; - var formatIntextHTML = function(bid) { + var formatOutstreamHTML = function(bid) { var placementCode = bid.placementCode; var config = bid.params; @@ -156,50 +168,20 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { } script += '};' + - 'topWindow.com.stickyadstv.intextroll.start(config);' + + 'topWindow.com.stickyadstv.'+getAPIName(bid.params.format)+'.start(config, topWindow.stickyadstv_asLoader);' + ''; 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); } @@ -211,7 +193,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { var priceData = vast.getPricing(); if (!priceData) { - console.warn("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; @@ -275,6 +257,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { 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/adapters/stickyadstv_spec.js b/test/spec/adapters/stickyadstv_spec.js index 74438c2b0aa..46d5fa4a8bb 100644 --- a/test/spec/adapters/stickyadstv_spec.js +++ b/test/spec/adapters/stickyadstv_spec.js @@ -214,4 +214,14 @@ describe('StickyAdsTV Adapter', function () { expect(adapter.getComponentId("screen-roll")).to.equal("screen-roll"); }); }); + + describe('get API name', function(){ + it('should returns valid component ids', 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"); + }); + }); + }); From 9ad2b7f65d3df6494c47a1025aac0600b533923e Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Tue, 20 Jun 2017 11:15:08 +0200 Subject: [PATCH 21/25] fix ASLoader on futur outstream format versions --- src/adapters/stickyadstv.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/adapters/stickyadstv.js b/src/adapters/stickyadstv.js index a48c184af16..457a9bf4412 100644 --- a/src/adapters/stickyadstv.js +++ b/src/adapters/stickyadstv.js @@ -157,7 +157,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 @@ -168,7 +169,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { } script += '};' + - 'topWindow.com.stickyadstv.'+getAPIName(bid.params.format)+'.start(config, topWindow.stickyadstv_asLoader);' + + 'topWindow.com.stickyadstv.'+getAPIName(bid.params.format)+'.start(config);' + ''; From 427b45c37a91c1c6a2224ce437d054d2fa4f519a Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Tue, 20 Jun 2017 11:24:18 +0200 Subject: [PATCH 22/25] minor: fix code format. --- src/adapters/stickyadstv.js | 16 ++++++++-------- test/spec/adapters/stickyadstv_spec.js | 26 +++++++++++++------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/adapters/stickyadstv.js b/src/adapters/stickyadstv.js index 457a9bf4412..c747db57555 100644 --- a/src/adapters/stickyadstv.js +++ b/src/adapters/stickyadstv.js @@ -95,7 +95,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { function getComponentId(inputFormat) { var component = 'mustang'; // default component id - if(inputFormat && inputFormat !== 'inbanner'){ + if (inputFormat && inputFormat !== 'inbanner') { // format identifiers are equals to their component ids. component = inputFormat; } @@ -104,10 +104,10 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { } function getAPIName(componentId) { - componentId = componentId || ""; + componentId = componentId || ''; - //remove dash in componentId to get API name - return componentId.replace('-',''); + // remove dash in componentId to get API name + return componentId.replace('-', ''); } function getBiggerSize(array) { @@ -134,7 +134,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);'+ + 'if(topWindow.stickyadstv_asLoader) topWindow.stickyadstv_asLoader.registerEvents(ad);' + 'ad.initAd(' + size[0] + ',' + size[1] + ',"",0,"","");' + ''; @@ -157,7 +157,7 @@ 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) { @@ -169,7 +169,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { } script += '};' + - 'topWindow.com.stickyadstv.'+getAPIName(bid.params.format)+'.start(config);' + + 'topWindow.com.stickyadstv.' + getAPIName(bid.params.format) + '.start(config);' + ''; @@ -258,7 +258,7 @@ var StickyAdsTVAdapter = function StickyAdsTVAdapter() { getBid: getBid, getTopMostWindow: getTopMostWindow, getComponentId: getComponentId, - getAPIName:getAPIName, + getAPIName: getAPIName, createNew: StickyAdsTVAdapter.createNew // enable alias feature (to be used for freewheel-ssp alias) }); }; diff --git a/test/spec/adapters/stickyadstv_spec.js b/test/spec/adapters/stickyadstv_spec.js index 46d5fa4a8bb..4d7b9d82a3d 100644 --- a/test/spec/adapters/stickyadstv_spec.js +++ b/test/spec/adapters/stickyadstv_spec.js @@ -207,21 +207,21 @@ describe('StickyAdsTV Adapter', function () { }); }); - describe('get component id', function(){ - it('should returns 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 component id', function() { + it('should returns 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 returns valid component ids', 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"); + describe('get API name', function() { + it('should returns valid component ids', 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'); }); }); - -}); + +}); \ No newline at end of file From c65c62d59c04fb66c982d5e806e6e74f8e653141 Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Tue, 20 Jun 2017 14:36:56 +0200 Subject: [PATCH 23/25] update unit tests --- test/spec/adapters/stickyadstv_spec.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/spec/adapters/stickyadstv_spec.js b/test/spec/adapters/stickyadstv_spec.js index 4d7b9d82a3d..83e43a9fbe1 100644 --- a/test/spec/adapters/stickyadstv_spec.js +++ b/test/spec/adapters/stickyadstv_spec.js @@ -125,9 +125,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); @@ -174,24 +174,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); @@ -200,7 +200,7 @@ 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); @@ -208,7 +208,7 @@ describe('StickyAdsTV Adapter', function () { }); describe('get component id', function() { - it('should returns valid component ids', 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'); @@ -216,7 +216,7 @@ describe('StickyAdsTV Adapter', function () { }); describe('get API name', function() { - it('should returns valid component ids', 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'); From 23639ff187434c01c010c0716d9eaa9f6591f679 Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Tue, 20 Jun 2017 14:52:07 +0200 Subject: [PATCH 24/25] minor fix code format --- test/spec/adapters/stickyadstv_spec.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/spec/adapters/stickyadstv_spec.js b/test/spec/adapters/stickyadstv_spec.js index 83e43a9fbe1..e3dc5c0a8ac 100644 --- a/test/spec/adapters/stickyadstv_spec.js +++ b/test/spec/adapters/stickyadstv_spec.js @@ -223,5 +223,4 @@ describe('StickyAdsTV Adapter', function () { expect(adapter.getAPIName('floorad')).to.equal('floorad'); }); }); - }); \ No newline at end of file From 7b2ff6709aeb0d5d0f9edec56d5944a8eb4c987e Mon Sep 17 00:00:00 2001 From: guillaume-sticky Date: Tue, 20 Jun 2017 18:29:32 +0200 Subject: [PATCH 25/25] minor: add missing new line at eof --- test/spec/adapters/stickyadstv_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/spec/adapters/stickyadstv_spec.js b/test/spec/adapters/stickyadstv_spec.js index e3dc5c0a8ac..0a4866862d7 100644 --- a/test/spec/adapters/stickyadstv_spec.js +++ b/test/spec/adapters/stickyadstv_spec.js @@ -223,4 +223,4 @@ describe('StickyAdsTV Adapter', function () { expect(adapter.getAPIName('floorad')).to.equal('floorad'); }); }); -}); \ No newline at end of file +});