Skip to content
This repository has been archived by the owner on Feb 13, 2021. It is now read-only.

Commit

Permalink
Executed changes requested by @jaiminpanchal27 on 2017-08-01
Browse files Browse the repository at this point in the history
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:
 - prebid#1431 (review)
  • Loading branch information
hdjvieira committed Aug 4, 2017
1 parent 52e1dc8 commit f745fe1
Show file tree
Hide file tree
Showing 3 changed files with 212 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
]
Expand Down
4 changes: 2 additions & 2 deletions modules/polluxBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down
243 changes: 207 additions & 36 deletions test/spec/modules/polluxBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -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: '<script src="some.ad.url"></script>',
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();
});
});
});

0 comments on commit f745fe1

Please sign in to comment.