Skip to content

Commit

Permalink
Index Exchange adapter explicit pass on bid with unsupported sizes. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
arvending authored and Matt Kendall committed Jul 31, 2017
1 parent 940295f commit 424df94
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 10 deletions.
29 changes: 21 additions & 8 deletions modules/indexExchangeBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ window.index_render = function(doc, targetID) {
if (ad != null) {
doc.write(ad);
} else {
var url = window.location.protocol === 'https:' ? 'https://as-sec.casalemedia.com' : 'http://as.casalemedia.com';
var url = utils.getTopWindowLocation().protocol === 'http:' ? 'http://as.casalemedia.com' : 'https://as-sec.casalemedia.com';
url += '/headerstats?type=RT&s=' + cygnus_index_args.siteID + '&u=' + encodeURIComponent(location.href) + '&r=' + _IndexRequestData.lastRequestID;
var px_call = new Image();
px_call.src = url + '&blank=' + targetID;
Expand Down Expand Up @@ -346,10 +346,10 @@ var cygnus_index_start = function () {
var scriptSrc;
if (getIndexDebugMode() == CONSTANTS.INDEX_DEBUG_MODE.mode.sandbox.queryValue.toUpperCase()) {
this.siteID = CONSTANTS.INDEX_DEBUG_MODE.mode.sandbox.siteID;
scriptSrc = window.location.protocol === 'https:' ? 'https://sandbox.ht.indexexchange.com' : 'http://sandbox.ht.indexexchange.com';
scriptSrc = utils.getTopWindowLocation().protocol === 'http:' ? 'http://sandbox.ht.indexexchange.com' : 'https://sandbox.ht.indexexchange.com';
utils.logMessage('IX DEBUG: Sandbox mode activated');
} else {
scriptSrc = window.location.protocol === 'https:' ? 'https://as-sec.casalemedia.com' : 'http://as.casalemedia.com';
scriptSrc = utils.getTopWindowLocation().protocol === 'http:' ? 'http://as.casalemedia.com' : 'https://as-sec.casalemedia.com';
}
var prebidVersion = encodeURIComponent('$prebid.version$');
scriptSrc += '/cygnus?v=7&fn=cygnus_index_parse_res&s=' + this.siteID + '&r=' + jsonURI + '&pid=pb' + prebidVersion;
Expand Down Expand Up @@ -407,6 +407,13 @@ var IndexExchangeAdapter = function IndexExchangeAdapter() {
];
var firstAdUnitCode = '';

function passOnBid(adUnitCode) {
var bid = bidfactory.createBid(2);
bid.bidderCode = ADAPTER_CODE;
bidmanager.addBidResponse(adUnitCode, bid);
return bid;
}

function _callBids(request) {
var bidArr = request.bids;

Expand All @@ -419,6 +426,9 @@ var IndexExchangeAdapter = function IndexExchangeAdapter() {
_IndexRequestData.targetAggregate = {'open': {}, 'private': {}};

if (!utils.hasValidBidRequest(bidArr[0].params, requiredParams, ADAPTER_NAME)) {
for (var i = 0; i < bidArr.length; i++) {
passOnBid(bidArr[i].placementCode);
}
return;
}

Expand Down Expand Up @@ -450,13 +460,17 @@ var IndexExchangeAdapter = function IndexExchangeAdapter() {

if (!validSize) {
utils.logMessage(ADAPTER_NAME + ' slot excluded from request due to no valid sizes');
passOnBid(bid.placementCode);
continue;
}

var usingSizeSpecificSiteID = false;
// Check for size defined in bidder params
if (bid.params.size && bid.params.size instanceof Array) {
if (!(bid.sizes[j][0] == bid.params.size[0] && bid.sizes[j][1] == bid.params.size[1])) { continue; }
if (!(bid.sizes[j][0] == bid.params.size[0] && bid.sizes[j][1] == bid.params.size[1])) {
passOnBid(bid.placementCode);
continue;
}
usingSizeSpecificSiteID = true;
}

Expand All @@ -467,6 +481,7 @@ var IndexExchangeAdapter = function IndexExchangeAdapter() {
var siteID = Number(bid.params.siteID);
if (typeof siteID !== 'number' || siteID % 1 != 0 || siteID <= 0) {
utils.logMessage(ADAPTER_NAME + ' slot excluded from request due to invalid siteID');
passOnBid(bid.placementCode);
continue;
}
if (siteID && typeof cygnus_index_args.siteID === 'undefined') {
Expand All @@ -478,6 +493,7 @@ var IndexExchangeAdapter = function IndexExchangeAdapter() {
var slotID = bid.params[requiredParams[0]];
if (typeof slotID !== 'string' && typeof slotID !== 'number') {
utils.logError(ADAPTER_NAME + ' bid contains invalid slot ID from ' + bid.placementCode + '. Discarding slot');
passOnBid(bid.placementCode);
continue
}

Expand Down Expand Up @@ -598,10 +614,7 @@ var IndexExchangeAdapter = function IndexExchangeAdapter() {
}
// No bids for expected bid, pass bid
} else {
var bid = bidfactory.createBid(2);
bid.bidderCode = ADAPTER_CODE;
currentBid = bid;
bidmanager.addBidResponse(adUnitCode, currentBid);
currentBid = passOnBid(adUnitCode);
}
}
} catch (e) {
Expand Down
17 changes: 17 additions & 0 deletions test/spec/modules/indexExchangeBidAdapter_request_spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Adapter from '../../../modules/indexExchangeBidAdapter';
import bidManager from '../../../src/bidmanager';
import adLoader from '../../../src/adloader';

var assert = require('chai').assert;
Expand All @@ -21,6 +22,7 @@ describe('indexExchange adapter - Request', function () {
adapter = new Adapter();
sandbox = sinon.sandbox.create();
sandbox.stub(adLoader, 'loadScript');
sandbox.stub(bidManager, 'addBidResponse');
});

afterEach(function() {
Expand Down Expand Up @@ -96,6 +98,21 @@ describe('indexExchange adapter - Request', function () {
adapter.callBids({ bids: configuredBids });

assert.isUndefined(adLoader.loadScript.firstCall.args[0], 'no request made to AS');

var adapterResponse = {};
for (var i = 0; i < bidManager.addBidResponse.callCount; i++) {
var adUnitCode = bidManager.addBidResponse.getCall(i).args[0];
var bid = bidManager.addBidResponse.getCall(i).args[1];

if (typeof adapterResponse[adUnitCode] === 'undefined') {
adapterResponse[adUnitCode] = [];
};
adapterResponse[adUnitCode].push(bid);
};
assert.deepEqual(Object.keys(adapterResponse), [IndexUtils.DefaultPlacementCodePrefix], 'bid response from placement code that is configured');
assert.equal(adapterResponse[IndexUtils.DefaultPlacementCodePrefix].length, 1, 'one response back returned for placement ' + IndexUtils.DefaultPlacementCodePrefix);
assert.equal(adapterResponse[IndexUtils.DefaultPlacementCodePrefix][0].bidderCode, ADAPTER_CODE, "bidder code match with adapter's name");
assert.equal(adapterResponse[IndexUtils.DefaultPlacementCodePrefix][0].statusMessage, 'Bid returned empty or error response', 'pass on bid message');
});

it('test_prebid_indexAdapter_request_2_1: single slot with all supported multiple sizes -> multiple request objects for the slot', function () {
Expand Down
Loading

0 comments on commit 424df94

Please sign in to comment.