From b1ef968dcfe5f1ded219b8990d3a9ca4d13546b0 Mon Sep 17 00:00:00 2001 From: atkachov Date: Tue, 16 May 2017 18:23:03 +0300 Subject: [PATCH 1/2] Atomx adapter: add "video" mediaType support --- adapters.json | 5 ++ src/adapters/admixer.js | 22 ++++- test/spec/adapters/admixer_spec.js | 127 ++++++++++++++++++++++++++--- 3 files changed, 141 insertions(+), 13 deletions(-) diff --git a/adapters.json b/adapters.json index 44e70d432b2..8e31b290afb 100644 --- a/adapters.json +++ b/adapters.json @@ -142,5 +142,10 @@ "rhythmone": { "supportedMediaTypes": ["video"] } + }, + { + "admixer": { + "supportedMediaTypes": ["video"] + } } ] diff --git a/src/adapters/admixer.js b/src/adapters/admixer.js index 2aed4994083..1858e9291b0 100644 --- a/src/adapters/admixer.js +++ b/src/adapters/admixer.js @@ -10,6 +10,7 @@ var utils = require('../utils.js'); */ var AdmixerAdapter = function AdmixerAdapter() { var invUrl = '//inv-nets.admixer.net/prebid.aspx'; + var invVastUrl = "//inv-nets.admixer.net/videoprebid.aspx"; function _callBids(data) { var bids = data.bids || []; @@ -21,7 +22,16 @@ var AdmixerAdapter = function AdmixerAdapter() { 'callback_uid': bid.placementCode }; if (params.zone) { - _requestBid(invUrl, params); + if (bid.mediaType === "video") { + var videoParams = {}; + if (typeof bid.video === "object") { + Object.assign(videoParams, bid.video); + } + Object.assign(videoParams, params); + _requestBid(invVastUrl, params); + } else { + _requestBid(invUrl, params); + } } else { var bidObject = bidfactory.createBid(2); @@ -49,7 +59,13 @@ var AdmixerAdapter = function AdmixerAdapter() { bidObject = bidfactory.createBid(1); bidObject.bidderCode = 'admixer'; bidObject.cpm = bid.cpm; - bidObject.ad = bid.ad; + if (bid.vastUrl) { + bidObject.mediaType = "video"; + bidObject.vastUrl = bid.vastUrl; + bidObject.descriptionUrl = bid.vastUrl; + } else { + bidObject.ad = bid.ad; + } bidObject.width = bid.width; bidObject.height = bid.height; } else { @@ -65,4 +81,4 @@ var AdmixerAdapter = function AdmixerAdapter() { }; }; -module.exports = AdmixerAdapter; \ No newline at end of file +module.exports = AdmixerAdapter; diff --git a/test/spec/adapters/admixer_spec.js b/test/spec/adapters/admixer_spec.js index a49a2b4b230..e7ff007cf55 100644 --- a/test/spec/adapters/admixer_spec.js +++ b/test/spec/adapters/admixer_spec.js @@ -39,6 +39,54 @@ describe('Admixer adapter', function () { } ] }; + var validVideoData_1 = { + bids: [ + { + mediaType: "video", + bidder: 'admixer', + bidId: 'bid_id', + params: {zone: 'zone_id'}, + placementCode: 'ad-unit-1', + sizes: [[300, 250], [300, 600]] + } + ] + }; + var validVideoData_2 = { + bids: [ + { + mediaType: "video", + bidder: 'admixer', + bidId: 'bid_id', + params: {zone: 'zone_id'}, + placementCode: 'ad-unit-1', + sizes: [300, 250] + } + ] + }; + var validVideoData_3 = { + bids: [ + { + mediaType: "video", + bidder: 'admixer', + bidId: 'bid_id', + params: {zone: 'zone_id', video: {skippable: true}}, + placementCode: 'ad-unit-1', + sizes: [300, 250] + } + ] + }; + var invalidVideoData = { + bids: [ + { + mediaType: "video", + bidder: 'admixer', + bidId: 'bid_id', + params: {}, + placementCode: 'ad-unit-1', + sizes: [[300, 250], [300, 600]] + } + ] + }; var responseWithAd = JSON.stringify({ 'result': { 'cpm': 2.2, @@ -57,13 +105,38 @@ describe('Admixer adapter', function () { }, 'callback_uid': 'ad-unit-1' }); + var responseWithVideoAd = JSON.stringify({ + 'result': { + 'cpm': 2.2, + 'vastUrl': 'http://inv-nets.admixer.net/vastxml.aspx?req=9d651544-daf4-48ed-ae0c-38a60a4e1920&vk=e914f026449e49aeb6eea07b9642a2ce', + 'width': 300, + 'height': 250 + }, + 'callback_uid': 'ad-unit-1' + }); + var responseWithoutVideoAd = JSON.stringify({ + 'result': { + 'cpm': 0, + 'vastUrl': '', + 'width': 0, + 'height': 0 + }, + 'callback_uid': 'ad-unit-1' + }); var responseEmpty = ''; var invUrl = '//inv-nets.admixer.net/prebid.aspx'; + var invVastUrl = "//inv-nets.admixer.net/videoprebid.aspx"; var validJsonParams = { zone: 'zone_id', callback_uid: 'ad-unit-1', sizes: '300x250-300x600' }; + var validJsonVideoParams = { + zone: 'zone_id', + callback_uid: 'ad-unit-1', + sizes: '300x250-300x600', + skippable: true + }; describe('bid request with valid data', function () { var stubAjax; beforeEach(function () { @@ -73,19 +146,32 @@ describe('Admixer adapter', function () { afterEach(function () { stubAjax.restore(); }); - it('bid request should be called. sizes style -> [[],[]]', function () { + it('display: bid request should be called. sizes style -> [[],[]]', function () { Adapter.callBids(validData_1); sinon.assert.calledOnce(stubAjax); }); - it('bid request should be called. sizes style -> []', function () { + it('video: bid request should be called. sizes style -> [[],[]]', function () { + Adapter.callBids(validVideoData_1); + sinon.assert.calledOnce(stubAjax); + }); + it('display: bid request should be called. sizes style -> []', function () { Adapter.callBids(validData_2); sinon.assert.calledOnce(stubAjax); }); - it('ajax params should be matched', function () { + it('video: bid request should be called. sizes style -> []', function () { + Adapter.callBids(validVideoData_2); + sinon.assert.calledOnce(stubAjax); + }); + it('display: ajax params should be matched', function () { Adapter.callBids(validData_1); sinon.assert.calledWith(stubAjax, sinon.match(invUrl, function () { }, validJsonParams, {method: "GET"})); }); + it('video: ajax params should be matched', function () { + Adapter.callBids(validVideoData_3); + sinon.assert.calledWith(stubAjax, sinon.match(invVastUrl, function () { + }, validJsonVideoParams, {method: "GET"})); + }); }); describe('bid request with invalid data', function () { var addBidResponse, stubAjax; @@ -98,15 +184,24 @@ describe('Admixer adapter', function () { addBidResponse.restore(); stubAjax.restore(); }); - it('ajax shouldn\'t be called', function () { + it('display: ajax shouldn\'t be called', function () { Adapter.callBids(invalidData); sinon.assert.notCalled(stubAjax); }); - it('bidmanager.addBidResponse status code must to be equal "' + CONSTANTS.STATUS.NO_BID + '"', function () { + it('video: ajax shouldn\'t be called', function () { + Adapter.callBids(invalidVideoData); + sinon.assert.notCalled(stubAjax); + }); + it('display: bidmanager.addBidResponse status code must to be equal "' + CONSTANTS.STATUS.NO_BID + '"', function () { Adapter.callBids(invalidData); expect(addBidResponse.firstCall.args[1].getStatusCode()).to.equal(CONSTANTS.STATUS.NO_BID); expect(addBidResponse.firstCall.args[1].bidderCode).to.equal('admixer'); }); + it('video: bidmanager.addBidResponse status code must to be equal "' + CONSTANTS.STATUS.NO_BID + '"', function () { + Adapter.callBids(invalidVideoData); + expect(addBidResponse.firstCall.args[1].getStatusCode()).to.equal(CONSTANTS.STATUS.NO_BID); + expect(addBidResponse.firstCall.args[1].bidderCode).to.equal('admixer'); + }); }); describe('bid response', function () { var addBidResponse; @@ -116,23 +211,35 @@ describe('Admixer adapter', function () { afterEach(function () { addBidResponse.restore(); }); - it('response with ad. bidmanager.addBidResponse status code must to be equal "' + CONSTANTS.STATUS.GOOD + '"', function () { + it('display: response with ad. bidmanager.addBidResponse status code must to be equal "' + CONSTANTS.STATUS.GOOD + '"', function () { Adapter.responseCallback(responseWithAd); var arg = addBidResponse.firstCall.args[1]; expect(arg.getStatusCode()).to.equal(CONSTANTS.STATUS.GOOD); expect(arg.bidderCode).to.equal('admixer'); }); - it('response without ad. bidmanager.addBidResponse status code must to be equal "' + CONSTANTS.STATUS.NO_BID, function () { + it('video: response with ad. bidmanager.addBidResponse status code must to be equal "' + CONSTANTS.STATUS.GOOD + '"', function () { + Adapter.responseCallback(responseWithVideoAd); + var arg = addBidResponse.firstCall.args[1]; + expect(arg.getStatusCode()).to.equal(CONSTANTS.STATUS.GOOD); + expect(arg.bidderCode).to.equal('admixer'); + }); + it('display: response without ad. bidmanager.addBidResponse status code must to be equal "' + CONSTANTS.STATUS.NO_BID, function () { Adapter.responseCallback(responseWithoutAd); var arg = addBidResponse.firstCall.args[1]; expect(arg.getStatusCode()).to.equal(CONSTANTS.STATUS.NO_BID); expect(arg.bidderCode).to.equal('admixer'); }); - it('response empty. bidmanager.addBidResponse status code must to be equal "' + CONSTANTS.STATUS.NO_BID, function () { + it('video: response without ad. bidmanager.addBidResponse status code must to be equal "' + CONSTANTS.STATUS.NO_BID, function () { + Adapter.responseCallback(responseWithoutVideoAd); + var arg = addBidResponse.firstCall.args[1]; + expect(arg.getStatusCode()).to.equal(CONSTANTS.STATUS.NO_BID); + expect(arg.bidderCode).to.equal('admixer'); + }); + it('display/video: response empty. bidmanager.addBidResponse status code must to be equal "' + CONSTANTS.STATUS.NO_BID, function () { Adapter.responseCallback(responseEmpty); var arg = addBidResponse.firstCall.args[1]; expect(arg.getStatusCode()).to.equal(CONSTANTS.STATUS.NO_BID); expect(arg.bidderCode).to.equal('admixer'); - }) + }); }); -}); \ No newline at end of file +}); From 8b7820fd10079350bbb31e65b3e7d819399d4f38 Mon Sep 17 00:00:00 2001 From: atkachov Date: Thu, 18 May 2017 11:19:28 +0300 Subject: [PATCH 2/2] admixer adapter: fix lint errors --- src/adapters/admixer.js | 8 ++++---- test/spec/adapters/admixer_spec.js | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/adapters/admixer.js b/src/adapters/admixer.js index 1c7585885d7..24cf81bf9e9 100644 --- a/src/adapters/admixer.js +++ b/src/adapters/admixer.js @@ -10,7 +10,7 @@ var utils = require('../utils.js'); */ var AdmixerAdapter = function AdmixerAdapter() { var invUrl = '//inv-nets.admixer.net/prebid.aspx'; - var invVastUrl = "//inv-nets.admixer.net/videoprebid.aspx"; + var invVastUrl = '//inv-nets.admixer.net/videoprebid.aspx'; function _callBids(data) { var bids = data.bids || []; @@ -22,9 +22,9 @@ var AdmixerAdapter = function AdmixerAdapter() { 'callback_uid': bid.placementCode }; if (params.zone) { - if (bid.mediaType === "video") { + if (bid.mediaType === 'video') { var videoParams = {}; - if (typeof bid.video === "object") { + if (typeof bid.video === 'object') { Object.assign(videoParams, bid.video); } Object.assign(videoParams, params); @@ -59,7 +59,7 @@ var AdmixerAdapter = function AdmixerAdapter() { bidObject.bidderCode = 'admixer'; bidObject.cpm = bid.cpm; if (bid.vastUrl) { - bidObject.mediaType = "video"; + bidObject.mediaType = 'video'; bidObject.vastUrl = bid.vastUrl; bidObject.descriptionUrl = bid.vastUrl; } else { diff --git a/test/spec/adapters/admixer_spec.js b/test/spec/adapters/admixer_spec.js index 440ced0920c..45f18ce7abc 100644 --- a/test/spec/adapters/admixer_spec.js +++ b/test/spec/adapters/admixer_spec.js @@ -42,7 +42,7 @@ describe('Admixer adapter', function () { var validVideoData_1 = { bids: [ { - mediaType: "video", + mediaType: 'video', bidder: 'admixer', bidId: 'bid_id', params: {zone: 'zone_id'}, @@ -54,7 +54,7 @@ describe('Admixer adapter', function () { var validVideoData_2 = { bids: [ { - mediaType: "video", + mediaType: 'video', bidder: 'admixer', bidId: 'bid_id', params: {zone: 'zone_id'}, @@ -66,7 +66,7 @@ describe('Admixer adapter', function () { var validVideoData_3 = { bids: [ { - mediaType: "video", + mediaType: 'video', bidder: 'admixer', bidId: 'bid_id', params: {zone: 'zone_id', video: {skippable: true}}, @@ -78,7 +78,7 @@ describe('Admixer adapter', function () { var invalidVideoData = { bids: [ { - mediaType: "video", + mediaType: 'video', bidder: 'admixer', bidId: 'bid_id', params: {}, @@ -125,7 +125,7 @@ describe('Admixer adapter', function () { }); var responseEmpty = ''; var invUrl = '//inv-nets.admixer.net/prebid.aspx'; - var invVastUrl = "//inv-nets.admixer.net/videoprebid.aspx"; + var invVastUrl = '//inv-nets.admixer.net/videoprebid.aspx'; var validJsonParams = { zone: 'zone_id', callback_uid: 'ad-unit-1', @@ -170,7 +170,7 @@ describe('Admixer adapter', function () { it('video: ajax params should be matched', function () { Adapter.callBids(validVideoData_3); sinon.assert.calledWith(stubAjax, sinon.match(invVastUrl, function () { - }, validJsonVideoParams, {method: "GET"})); + }, validJsonVideoParams, {method: 'GET'})); }); }); describe('bid request with invalid data', function () {