Skip to content

Commit

Permalink
Avoid using global private variables in Sovrn adapter (prebid#1475)
Browse files Browse the repository at this point in the history
* Update Sovrn adapter. Add test coverage. Enable deal IDs.

* HS-271: Avoid using private variables such as _bidsRequested and _bidsReceived in Sovrn adapter and Sovrn tests.

* lint

* Add bidfloor param to test.
  • Loading branch information
rachelrj authored and Nate Cozi committed Aug 11, 2017
1 parent 6956a56 commit add4a01
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
7 changes: 2 additions & 5 deletions modules/sovrnBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ var SovrnAdapter = function SovrnAdapter() {
}

function addBlankBidResponses(impidsWithBidBack) {
var missing = $$PREBID_GLOBAL$$._bidsRequested.find(bidSet => bidSet.bidderCode === 'sovrn');
var missing = utils.getBidderRequestAllAdUnits('sovrn');
if (missing) {
missing = missing.bids.filter(bid => impidsWithBidBack.indexOf(bid.bidId) < 0);
} else {
Expand Down Expand Up @@ -102,15 +102,12 @@ var SovrnAdapter = function SovrnAdapter() {
var id = sovrnBid.impid;
var bid = {};

// try to fetch the bid request we sent Sovrn
var bidObj = $$PREBID_GLOBAL$$._bidsRequested.find(bidSet => bidSet.bidderCode === 'sovrn').bids
.find(bid => bid.bidId === id);
var bidObj = utils.getBidRequest(id);

if (bidObj) {
placementCode = bidObj.placementCode;
bidObj.status = CONSTANTS.STATUS.GOOD;

// place ad response on bidmanager._adResponsesByBidderId
responseCPM = parseFloat(sovrnBid.price);

if (responseCPM !== 0) {
Expand Down
28 changes: 20 additions & 8 deletions test/spec/modules/sovrnBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {expect} from 'chai';
import Adapter from 'modules/sovrnBidAdapter';
import bidmanager from 'src/bidmanager';
import adloader from 'src/adloader';
var utils = require('src/utils');

describe('sovrn adapter tests', function () {
let adapter;
Expand All @@ -12,7 +13,8 @@ describe('sovrn adapter tests', function () {
bidId: 'bidId1',
bidder: 'sovrn',
params: {
tagid: '315045'
tagid: '315045',
bidfloor: 1.25
},
sizes: [[320, 50]],
placementCode: 'div-gpt-ad-12345-1'
Expand Down Expand Up @@ -42,9 +44,11 @@ describe('sovrn adapter tests', function () {

describe('requestBids', function () {
let stubLoadScript;

beforeEach(() => {
stubLoadScript = sinon.stub(adloader, 'loadScript');
});

afterEach(() => {
stubLoadScript.restore();
});
Expand All @@ -57,7 +61,7 @@ describe('sovrn adapter tests', function () {
adapter.callBids(bidderRequest);

let sovrnScript = decodeURIComponent(stubLoadScript.getCall(0).args[0]);
let firstExpectedImpObj = '{"id":"bidId1","banner":{"w":320,"h":50},"tagid":"315045","bidfloor":""}';
let firstExpectedImpObj = '{"id":"bidId1","banner":{"w":320,"h":50},"tagid":"315045","bidfloor":1.25}';
let secondExpectedImpObj = '{"id":"bidId2","banner":{"w":320,"h":50},"tagid":"315046","bidfloor":""}';

expect(sovrnScript).to.contain(firstExpectedImpObj);
Expand All @@ -67,26 +71,37 @@ describe('sovrn adapter tests', function () {

describe('sovrnResponse', function () {
let stubAddBidResponse;
let getRequestStub;
let getRequestsStub;

beforeEach(() => {
stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse');

getRequestStub = sinon.stub(utils, 'getBidRequest');
getRequestStub.withArgs(bidderRequest.bids[0].bidId).returns(bidderRequest.bids[0]);
getRequestStub.withArgs(bidderRequest.bids[1].bidId).returns(bidderRequest.bids[1]);
getRequestStub.withArgs(bidderRequest.bids[2].bidId).returns(bidderRequest.bids[2]);

getRequestsStub = sinon.stub(utils, 'getBidderRequestAllAdUnits');
getRequestsStub.returns(bidderRequest);
});

afterEach(() => {
stubAddBidResponse.restore();
getRequestStub.restore();
getRequestsStub.restore();
});

it('should exist and be a function', function () {
expect($$PREBID_GLOBAL$$.sovrnResponse).to.exist.and.to.be.a('function');
});

it('should add empty bid responses if no bids returned', function () {
// no bids returned in the response.
let response = {
'id': '54321',
'seatbid': []
};

$$PREBID_GLOBAL$$._bidsRequested.push(bidderRequest);

$$PREBID_GLOBAL$$.sovrnResponse(response);

let bidPlacementCode1 = stubAddBidResponse.getCall(0).args[0];
Expand All @@ -112,7 +127,6 @@ describe('sovrn adapter tests', function () {
});

it('should add a bid response for bids returned and empty bid responses for the rest', function () {
// Returning a single bid in the response.
let response = {
'id': '54321111',
'seatbid': [ {
Expand All @@ -130,8 +144,6 @@ describe('sovrn adapter tests', function () {
} ]
};

$$PREBID_GLOBAL$$._bidsRequested.push(bidderRequest);

$$PREBID_GLOBAL$$.sovrnResponse(response);

let bidPlacementCode1 = stubAddBidResponse.getCall(0).args[0];
Expand Down

0 comments on commit add4a01

Please sign in to comment.