From f745fe1147433983aba725e0b176ce57d3d125af Mon Sep 17 00:00:00 2001 From: hdjvieira Date: Fri, 4 Aug 2017 13:37:41 +0100 Subject: [PATCH] Executed changes requested by @jaiminpanchal27 on 2017-08-01 Moved zone_728x90.html to integrationExamples/gpt/pollux_zone_728x90.html; Added bidRequest as second parameter to bidfactory.createBid() on Pollux Bid Adapter; Added more test cases to increase test coverage (at least 85%); Review Ref: - https://github.com/prebid/Prebid.js/pull/1431#pullrequestreview-53608436 --- .../pollux_zone_728x90.html} | 7 +- modules/polluxBidAdapter.js | 4 +- test/spec/modules/polluxBidAdapter_spec.js | 243 +++++++++++++++--- 3 files changed, 212 insertions(+), 42 deletions(-) rename integrationExamples/{pollux/zone_728x90.html => gpt/pollux_zone_728x90.html} (95%) diff --git a/integrationExamples/pollux/zone_728x90.html b/integrationExamples/gpt/pollux_zone_728x90.html similarity index 95% rename from integrationExamples/pollux/zone_728x90.html rename to integrationExamples/gpt/pollux_zone_728x90.html index 023cd033319..ecede9b5db2 100644 --- a/integrationExamples/pollux/zone_728x90.html +++ b/integrationExamples/gpt/pollux_zone_728x90.html @@ -11,16 +11,15 @@ sizes: [[728, 90]], bids: [ { - bidder: 'appnexus', + bidder: 'pollux', params: { - placementId: '4799418' + zone: '276' } }, { bidder: 'pollux', - bidderUrl: '//adn.plxnt.com/prebid', params: { - zone: '276' + zone: '1806' } } ] diff --git a/modules/polluxBidAdapter.js b/modules/polluxBidAdapter.js index bbc70122693..ebf83380298 100644 --- a/modules/polluxBidAdapter.js +++ b/modules/polluxBidAdapter.js @@ -67,7 +67,7 @@ function polluxBidAdapter() { placementCode = bidObj.placementCode; } if (bidObj && response.cpm > 0 && !!response.ad) { - bidObject = bidfactory.createBid(STATUS.GOOD); + bidObject = bidfactory.createBid(STATUS.GOOD, bidObj); bidObject.bidderCode = bidObj.bidder; bidObject.mediaType = response.mediaType; bidObject.cpm = parseFloat(response.cpm); @@ -79,7 +79,7 @@ function polluxBidAdapter() { bidObject.width = response.width; bidObject.height = response.height; } else { - bidObject = bidfactory.createBid(STATUS.NO_BID); + bidObject = bidfactory.createBid(STATUS.NO_BID, bidObj); bidObject.bidderCode = 'pollux'; utils.logMessage('No prebid response from polluxHandler for placement code ' + placementCode); } diff --git a/test/spec/modules/polluxBidAdapter_spec.js b/test/spec/modules/polluxBidAdapter_spec.js index 51a8ede2d6c..1ac7c79e181 100644 --- a/test/spec/modules/polluxBidAdapter_spec.js +++ b/test/spec/modules/polluxBidAdapter_spec.js @@ -1,39 +1,210 @@ -import {expect} from 'chai'; -import Adapter from '../../../modules/polluxBidAdapter'; -import bidManager from '../../../src/bidmanager'; -import adLoader from '../../../src/adloader'; - -describe('Pollux Adapter', () => { - let adapter; - - const REQUEST = { - 'bidderCode': 'pollux', - 'requestId': 'd3e07445-ab06-44c8-a9dd-5ef9af06d2a6', - 'bidderRequestId': '7101db09af0db2', - 'bids': [ - { - 'bidder': 'pollux', - 'bidderUrl': '//adn-dev.polluxnetwork.com/prebid', - 'params': { - 'zone': '123' - }, - 'code': 'div-gpt-ad-1460505661639-0', - 'sizes': [[728, 90]], - 'bidId': '84ab500420319d', - 'bidderRequestId': '7101db09af0db2', - 'requestId': 'd3e07445-ab06-44c8-a9dd-5ef9af06d2a6' +describe('Pollux Bid Adapter tests', function () { + var expect = require('chai').expect; + var urlParse = require('url-parse'); + var querystringify = require('querystringify'); + var adapter = require('modules/polluxBidAdapter'); + var adLoader = require('src/adloader'); + var bidmanager = require('src/bidmanager'); + + var stubLoadScript; + + beforeEach(function () { + stubLoadScript = sinon.stub(adLoader, 'loadScript'); + }); + + afterEach(function () { + stubLoadScript.restore(); + }); + + describe('creation of bid url', function () { + if (typeof ($$PREBID_GLOBAL$$._bidsReceived) === 'undefined') { + $$PREBID_GLOBAL$$._bidsReceived = []; + } + if (typeof ($$PREBID_GLOBAL$$._bidsRequested) === 'undefined') { + $$PREBID_GLOBAL$$._bidsRequested = []; + } + + it('bid request for single placement', function () { + var params = { + bids: [{ + placementCode: 'div-gpt-ad-1460505661639-0', + bidId: '21fe992ca48d55', + bidder: 'pollux', + sizes: [[300, 250]], + params: { zone: '1806' } + }] + }; + + adapter().callBids(params); + + var bidUrl = stubLoadScript.getCall(0).args[0]; + + sinon.assert.calledOnce(stubLoadScript); + + var parsedBidUrl = urlParse(bidUrl); + var parsedBidUrlQueryString = querystringify.parse(parsedBidUrl.query); + + expect(parsedBidUrlQueryString).to.have.property('zone').and.to.equal('1806'); + expect(parsedBidUrlQueryString).to.have.property('domain').and.to.have.length.above(1); + }); + }); + + describe('handling bid response', function () { + it('should return complete bid response adUrl', function() { + var stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); + + var params = { + bids: [{ + placementCode: 'div-gpt-ad-1460505661639-0', + sizes: [[300, 250]], + bidId: '21fe992ca48d55', + bidder: 'pollux', + params: { zone: '1806' } + }] + }; + + var response = { + cpm: 0.5, + width: 300, + height: 250, + callback_id: '21fe992ca48d55', + ad: 'some.ad.url', + ad_type: 'url', + zone: 1806 + }; + + adapter().callBids(params); + var adUnits = []; + var unit = {}; + unit.bids = params.bids; + unit.code = 'div-gpt-ad-1460505661639-0'; + unit.sizes = [[300, 250]]; + adUnits.push(unit); + + if (typeof ($$PREBID_GLOBAL$$._bidsRequested) === 'undefined') { + $$PREBID_GLOBAL$$._bidsRequested = [params]; + } else { + $$PREBID_GLOBAL$$._bidsRequested.push(params); } - ], - 'start': 1469479810130 - }; - - sinon.stub(bidManager, 'addBidResponse'); - const adLoaderStub = sinon.stub(adLoader, 'loadScript'); - - describe('callBids', () => { - adapter = new Adapter(); - adapter.callBids(REQUEST); - expect(adLoaderStub.getCall(0).args[0]).to.contain('zone=123'); - expect(adLoaderStub.getCall(0).args[0]).to.contain('domain='); + + $$PREBID_GLOBAL$$.adUnits = adUnits; + + $$PREBID_GLOBAL$$.polluxHandler(response); + + var bidPlacementCode1 = stubAddBidResponse.getCall(0).args[0]; + var bidObject1 = stubAddBidResponse.getCall(0).args[1]; + + expect(bidPlacementCode1).to.equal('div-gpt-ad-1460505661639-0'); + expect(bidObject1.bidderCode).to.equal('pollux'); + expect(bidObject1.cpm).to.equal(0.5); + expect(bidObject1.width).to.equal(300); + expect(bidObject1.height).to.equal(250); + expect(bidObject1.adUrl).to.have.length.above(1); + + stubAddBidResponse.restore(); + }); + + it('should return complete bid response ad (html)', function() { + var stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); + + var params = { + bids: [{ + placementCode: 'div-gpt-ad-1460505661639-0', + sizes: [[300, 250]], + bidId: '21fe992ca48d55', + bidder: 'pollux', + params: { zone: '1806' } + }] + }; + + var response = { + cpm: 0.5, + width: 300, + height: 250, + callback_id: '21fe992ca48d55', + ad: '', + ad_type: 'html', + zone: 1806 + }; + + adapter().callBids(params); + var adUnits = []; + var unit = {}; + unit.bids = params.bids; + unit.code = 'div-gpt-ad-1460505661639-0'; + unit.sizes = [[300, 250]]; + adUnits.push(unit); + + if (typeof ($$PREBID_GLOBAL$$._bidsRequested) === 'undefined') { + $$PREBID_GLOBAL$$._bidsRequested = [params]; + } else { + $$PREBID_GLOBAL$$._bidsRequested.push(params); + } + + $$PREBID_GLOBAL$$.adUnits = adUnits; + + $$PREBID_GLOBAL$$.polluxHandler(response); + + var bidPlacementCode1 = stubAddBidResponse.getCall(0).args[0]; + var bidObject1 = stubAddBidResponse.getCall(0).args[1]; + + expect(bidPlacementCode1).to.equal('div-gpt-ad-1460505661639-0'); + expect(bidObject1.bidderCode).to.equal('pollux'); + expect(bidObject1.cpm).to.equal(0.5); + expect(bidObject1.width).to.equal(300); + expect(bidObject1.height).to.equal(250); + expect(bidObject1.ad).to.have.length.above(1); + + stubAddBidResponse.restore(); + }); + + it('should return no bid response', function() { + var stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); + + var params = { + bids: [{ + placementCode: 'div-gpt-ad-1460505661639-0', + sizes: [[300, 250]], + bidId: '21fe992ca48d55', + bidder: 'pollux', + params: { zone: '276' } + }] + }; + + var response = { + cpm: null, + width: null, + height: null, + callback_id: null, + ad: null, + zone: null + }; + + adapter().callBids(params); + + var adUnits = []; + var unit = {}; + unit.bids = params.bids; + unit.code = 'div-gpt-ad-1460505661639-0'; + unit.sizes = [[300, 250]]; + adUnits.push(unit); + + if (typeof ($$PREBID_GLOBAL$$._bidsRequested) === 'undefined') { + $$PREBID_GLOBAL$$._bidsRequested = [params]; + } else { + $$PREBID_GLOBAL$$._bidsRequested.push(params); + } + + $$PREBID_GLOBAL$$.adUnits = adUnits; + + $$PREBID_GLOBAL$$.polluxHandler(response); + var bidPlacementCode1 = stubAddBidResponse.getCall(0).args[0]; + var bidObject1 = stubAddBidResponse.getCall(0).args[1]; + + expect(bidPlacementCode1).to.equal(''); + expect(bidObject1.bidderCode).to.equal('pollux'); + + stubAddBidResponse.restore(); + }); }); });