diff --git a/src/adapters/sharethrough.js b/src/adapters/sharethrough.js index e2f582dbaae..fd5c3072816 100644 --- a/src/adapters/sharethrough.js +++ b/src/adapters/sharethrough.js @@ -4,7 +4,7 @@ var bidfactory = require('../bidfactory.js'); var ajax = require('../ajax.js').ajax; const STR_BIDDER_CODE = "sharethrough"; -const STR_VERSION = "1.1.0"; +const STR_VERSION = "1.2.0"; var SharethroughAdapter = function SharethroughAdapter() { @@ -22,10 +22,16 @@ var SharethroughAdapter = function SharethroughAdapter() { const bidRequest = bids[i]; str.placementCodeSet[bidRequest.placementCode] = bidRequest; const scriptUrl = _buildSharethroughCall(bidRequest); - str.ajax(scriptUrl, $$PREBID_GLOBAL$$.strcallback, undefined, {withCredentials: true}); + str.ajax(scriptUrl, _createCallback(bidRequest), undefined, {withCredentials: true}); } } + function _createCallback(bidRequest) { + return (bidResponse) => { + _strcallback(bidRequest, bidResponse); + }; + } + function _buildSharethroughCall(bid) { const pkey = utils.getBidIdParameter('pkey', bid.params); @@ -39,17 +45,10 @@ var SharethroughAdapter = function SharethroughAdapter() { return url; } - $$PREBID_GLOBAL$$.strcallback = function(bidResponse) { + function _strcallback(bidObj, bidResponse) { try { bidResponse = JSON.parse(bidResponse); - } catch (e) { - utils.logError(e); - return; - } - - const bidId = bidResponse.bidId; - const bidObj = utils.getBidRequest(bidId); - try { + const bidId = bidResponse.bidId; const bid = bidfactory.createBid(1, bidObj); bid.bidderCode = STR_BIDDER_CODE; bid.cpm = bidResponse.creatives[0].cpm; @@ -84,7 +83,7 @@ var SharethroughAdapter = function SharethroughAdapter() { } catch (e) { _handleInvalidBid(bidObj); } - }; + } function _handleInvalidBid(bidObj) { const bid = bidfactory.createBid(2, bidObj); diff --git a/test/spec/adapters/sharethrough_spec.js b/test/spec/adapters/sharethrough_spec.js index 03eb7aaba49..24884b87ffb 100644 --- a/test/spec/adapters/sharethrough_spec.js +++ b/test/spec/adapters/sharethrough_spec.js @@ -63,17 +63,8 @@ describe('sharethrough adapter', () => { sinon.assert.calledTwice(adapter.str.ajax); - expect(firstBidUrl).to.contain(adapter.str.STR_BTLR_HOST + '/header-bid/v1?bidId=bidId1&placement_key=aaaa1111&hbVersion=%24prebid.version%24&strVersion=1.1.0&hbSource=prebid&'); - expect(secondBidUrl).to.contain(adapter.str.STR_BTLR_HOST + '/header-bid/v1?bidId=bidId2&placement_key=bbbb2222&hbVersion=%24prebid.version%24&strVersion=1.1.0&hbSource=prebid&'); - }); - - }); - - describe('strcallback', () => { - - it('should exist and be a function', () => { - let shit = sandbox.stub(pbjs, 'strcallback'); - expect(pbjs.strcallback).to.exist.and.to.be.a('function'); + expect(firstBidUrl).to.contain(adapter.str.STR_BTLR_HOST + '/header-bid/v1?bidId=bidId1&placement_key=aaaa1111&hbVersion=%24prebid.version%24&strVersion=1.2.0&hbSource=prebid&'); + expect(secondBidUrl).to.contain(adapter.str.STR_BTLR_HOST + '/header-bid/v1?bidId=bidId2&placement_key=bbbb2222&hbVersion=%24prebid.version%24&strVersion=1.2.0&hbSource=prebid&'); }); }); @@ -82,16 +73,18 @@ describe('sharethrough adapter', () => { let firstBid; let secondBid; + let server; beforeEach(() => { sandbox.stub(bidManager, 'addBidResponse'); + server = sinon.fakeServer.create(); pbjs._bidsRequested.push(bidderRequest); adapter.str.placementCodeSet['foo'] = {}; adapter.str.placementCodeSet['bar'] = {}; // respond - let bidderReponse1 = { + let bidderResponse1 = { "adserverRequestId": "40b6afd5-6134-4fbb-850a-bb8972a46994", "bidId": "bidId1", "creatives": [ @@ -104,7 +97,7 @@ describe('sharethrough adapter', () => { "stxUserId": "" }; - let bidderReponse2 = { + let bidderResponse2 = { "adserverRequestId": "40b6afd5-6134-4fbb-850a-bb8972a46994", "bidId": "bidId2", "creatives": [ @@ -117,13 +110,20 @@ describe('sharethrough adapter', () => { "stxUserId": "" }; - pbjs.strcallback(JSON.stringify(bidderReponse1)); - pbjs.strcallback(JSON.stringify(bidderReponse2)); + server.respondWith(/aaaa1111/,JSON.stringify(bidderResponse1)); + server.respondWith(/bbbb2222/,JSON.stringify(bidderResponse2)); + adapter.callBids(bidderRequest); + + server.respond(); firstBid = bidManager.addBidResponse.firstCall.args[1]; secondBid = bidManager.addBidResponse.secondCall.args[1]; }); + afterEach(() => { + server.restore(); + }); + it('should add a bid object for each bid', () => { sinon.assert.calledTwice(bidManager.addBidResponse); });