From 82686c9993f4ef21a429f554768f061a09c5a562 Mon Sep 17 00:00:00 2001 From: Dmitriy Shimko Date: Thu, 13 Jul 2017 09:51:31 +0300 Subject: [PATCH 01/18] Adding Orbitsoft module --- modules/orbitsoftBidAdapter.js | 228 +++++++++++ test/spec/modules/orbitsoftBidAdapter_spec.js | 358 ++++++++++++++++++ 2 files changed, 586 insertions(+) create mode 100644 modules/orbitsoftBidAdapter.js create mode 100644 test/spec/modules/orbitsoftBidAdapter_spec.js diff --git a/modules/orbitsoftBidAdapter.js b/modules/orbitsoftBidAdapter.js new file mode 100644 index 00000000000..e4fe863d645 --- /dev/null +++ b/modules/orbitsoftBidAdapter.js @@ -0,0 +1,228 @@ +import { getBidRequest } from 'src/utils'; +import adaptermanager from 'src/adaptermanager'; + +let CONSTANTS = require('src/constants'); +let utils = require('src/utils'); +let adloader = require('src/adloader'); +let bidmanager = require('src/bidmanager'); +let bidfactory = require('src/bidfactory'); +let Adapter = require('src/adapter'); + +let styleParamsToFieldsMap = { + 'title.family': 'f1', // headerFont + 'title.size': 'fs1', // headerFontSize + 'title.weight': 'w1', // headerWeight + 'title.style': 's1', // headerStyle + 'title.color': 'c3', // headerColor + 'description.family': 'f2', // descriptionFont + 'description.size': 'fs2', // descriptionFontSize + 'description.weight': 'w2', // descriptionWeight + 'description.style': 's2', // descriptionStyle + 'description.color': 'c4', // descriptionColor + 'url.family': 'f3', // urlFont + 'url.size': 'fs3', // urlFontSize + 'url.weight': 'w3', // urlWeight + 'url.style': 's3', // urlStyle + 'url.color': 'c5', // urlColor + 'colors.background': 'c2', // borderColor + 'colors.border': 'c1', // borderColor + 'colors.link': 'c6', // lnkColor +}; + +let OrbitsoftAdapter; +OrbitsoftAdapter = function OrbitsoftAdapter() { + let baseAdapter = Adapter.createNew('orbitsoft'); + + baseAdapter.callBids = function (params) { + let bids = params.bids || []; + + if (bids.length === 0) { + return; + } + + for (let i = 0; i < bids.length; i++) { + let bidRequest = bids[i]; + let callbackId = bidRequest.bidId; + adloader.loadScript(buildJPTCall(bidRequest, callbackId)); + } + }; + + function buildJPTCall(bid, callbackId) { + // Determine tag params + let placementId = utils.getBidIdParameter('placementId', bid.params); + + let referrer = utils.getBidIdParameter('ref', bid.params); + let location = utils.getBidIdParameter('loc', bid.params); + let jptCall = utils.getBidIdParameter('requestUrl', bid.params); + if (jptCall.length === 0) { + // No param requestUrl + // @if NODE_ENV='debug' + utils.logMessage('No param requestUrl'); + // @endif + return null; + } + else { + jptCall += '?'; + } + + jptCall = utils.tryAppendQueryString(jptCall, 'callback', '$$PREBID_GLOBAL$$.handleOASCB'); + jptCall = utils.tryAppendQueryString(jptCall, 'callback_uid', callbackId); + jptCall = utils.tryAppendQueryString(jptCall, 'scid', placementId); + + // Sizes takes a bit more logic + let sizeQueryString; + let parsedSizes = utils.parseSizesInput(bid.sizes); + + // Combine string into proper query string + let parsedSizesLength = parsedSizes.length; + if (parsedSizesLength > 0) { + // First value should be "size" + sizeQueryString = 'size=' + parsedSizes[0]; + jptCall += sizeQueryString + '&'; + } + + // Append custom attributes: + let paramsCopy = Object.assign({}, bid.params); + + // Delete attributes already used + delete paramsCopy.placementId; + delete paramsCopy.referrer; + delete paramsCopy.style; + delete paramsCopy.customParams; + + // Get the reminder + jptCall += utils.parseQueryStringParameters(paramsCopy); + + // Append location & referrer + if (location === '') { + location = utils.getTopWindowUrl(); + } + if (referrer === '') { + referrer = window.top.document.referrer; + } + jptCall = utils.tryAppendQueryString(jptCall, 'loc', location); + jptCall = utils.tryAppendQueryString(jptCall, 'ref', referrer); + + // Remove the trailing "&" + jptCall = removeTrailingAmp(jptCall); + + // @if NODE_ENV='debug' + utils.logMessage('jpt request built: ' + jptCall); + // @endif + + // Append a timer here to track latency + bid.startTime = new Date().getTime(); + + return jptCall; + } + + // Remove the trailing "&" + function removeTrailingAmp(url) { + if (url.lastIndexOf('&') === url.length - 1) { + url = url.substring(0, url.length - 1); + } + return url; + } + + // Expose the callback to the global object + $$PREBID_GLOBAL$$.handleOASCB = function (jptResponseObj) { + let bidCode; + + if (jptResponseObj && jptResponseObj.callback_uid) { + let responseCPM; + let id = jptResponseObj.callback_uid; + let placementCode = ''; + let bidObj = getBidRequest(id); + if (bidObj) { + bidCode = bidObj.bidder; + + placementCode = bidObj.placementCode; + + // Set the status + bidObj.status = CONSTANTS.STATUS.GOOD; + } + + // @if NODE_ENV='debug' + utils.logMessage('JSONP callback function called for ad ID: ' + id); + // @endif + + let bid = []; + if (jptResponseObj.cpm && jptResponseObj.cpm !== 0) { + // Store bid response + responseCPM = jptResponseObj.cpm; + // Bid status is good (indicating 1) + bid = bidfactory.createBid(CONSTANTS.STATUS.GOOD, bidObj); + bid.bidderCode = bidCode; + bid.cpm = responseCPM; + bid.adUrl = jptResponseObj.content_url; + bid.width = jptResponseObj.width; + bid.height = jptResponseObj.height; + + // Styles params + let styles = utils.getBidIdParameter('style', bidObj.params); + let stylesParams = {}; + for (let currentValue in styles) { + if (styles.hasOwnProperty(currentValue)) { + let currentStyle = styles[currentValue]; + for (let field in currentStyle) { + if (currentStyle.hasOwnProperty(field)) { + let styleField = styleParamsToFieldsMap[currentValue + '.' + field]; + if (styleField !== undefined) { + stylesParams[styleField] = currentStyle[field]; + } + } + } + } + } + bid.adUrl += '&' + utils.parseQueryStringParameters(stylesParams); + + // Custom params + let customParams = utils.getBidIdParameter('customParams', bidObj.params); + let customParamsArray = {}; + for (let customField in customParams) { + if (customParams.hasOwnProperty(customField)) { + customParamsArray['c.' + customField] = customParams[customField]; + } + } + let customParamsLink = utils.parseQueryStringParameters(customParamsArray); + if (customParamsLink) { + // Don't append a "&" here, we have already done it in parseQueryStringParameters + bid.adUrl += customParamsLink; + } + + // Remove the trailing "&" + bid.adUrl = removeTrailingAmp(bid.adUrl); + + bidmanager.addBidResponse(placementCode, bid); + } else { + // No response data + // @if NODE_ENV='debug' + utils.logMessage('No prebid response from Orbitsoft for placement code ' + placementCode); + // @endif + // indicate that there is no bid for this placement + bid = bidfactory.createBid(CONSTANTS.STATUS.NO_BID, bidObj); + bid.bidderCode = bidCode; + bidmanager.addBidResponse(placementCode, bid); + } + } else { + // No response data + // @if NODE_ENV='debug' + utils.logMessage('No prebid response for placement'); + // @endif + } + }; + + return { + callBids: baseAdapter.callBids, + setBidderCode: baseAdapter.setBidderCode, + buildJPTCall: buildJPTCall + }; +}; + +adaptermanager.registerBidAdapter(new OrbitsoftAdapter, 'orbitsoft'); +adaptermanager.aliasBidAdapter('orbitsoft', 'orbitadserving'); +adaptermanager.aliasBidAdapter('orbitsoft', 'orbitscripts'); +adaptermanager.aliasBidAdapter('orbitsoft', 'orbitsoftcom'); +adaptermanager.aliasBidAdapter('orbitsoft', 'orbitsoftru'); + +module.exports = OrbitsoftAdapter; diff --git a/test/spec/modules/orbitsoftBidAdapter_spec.js b/test/spec/modules/orbitsoftBidAdapter_spec.js new file mode 100644 index 00000000000..efe25492e54 --- /dev/null +++ b/test/spec/modules/orbitsoftBidAdapter_spec.js @@ -0,0 +1,358 @@ +describe('Orbitsoft Adapter tests', function () { + const expect = require('chai').expect; + const assert = require('chai').assert; + const adapter = require('modules/orbitsoftBidAdapter'); + const bidmanager = require('src/bidmanager'); + const adloader = require('src/adloader'); + const CONSTANTS = require('src/constants.json'); + + const contentCallEndPoint = 'http://orbitsoft.com/ads/show/content?'; + const jptCallEndPoint = 'http://orbitsoft.com/ads/show/hb?'; + + before(() => sinon.stub(document.body, 'appendChild')); + after(() => document.body.appendChild.restore()); + + describe('test orbitsoft callback response', function () { + it('should exist and be a function', function () { + expect(pbjs.handleOASCB).to.exist.and.to.be.a('function'); + }); + + it('should add empty bid responses if no bids returned', function () { + let stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); + + let bidderRequest = { + bidderCode: 'orbitsoft', + bids: [ + { + bidId: 'bidIdOrbitsoft1', + bidder: 'orbitsoft', + params: { + placementId: '16', + requestUrl: jptCallEndPoint + }, + sizes: [[300, 250]], + placementCode: 'test-div-12345' + } + ] + }; + + // Empty bid response + let response = { + callback_uid: 'bidIdOrbitsoft1', + cpm: 0 + }; + + pbjs._bidsRequested.push(bidderRequest); + // Adapter needs to be called, in order for the stub to register. + adapter(); + + pbjs.handleOASCB(response); + + let bidPlacementCode1 = stubAddBidResponse.getCall(0).args[0]; + let bidResponse1 = stubAddBidResponse.getCall(0).args[1]; + expect(bidPlacementCode1).to.equal('test-div-12345'); + expect(bidResponse1.getStatusCode()).to.equal(CONSTANTS.STATUS.NO_BID); + expect(bidResponse1.bidderCode).to.equal('orbitsoft'); + stubAddBidResponse.restore(); + }); + + it('should add empty bid responses if no bidId returned', function () { + let stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); + + let bidderRequest = { + bidderCode: 'orbitsoft', + bids: [ + { + bidId: 'bidIdOrbitsoft1', + bidder: 'orbitsoft', + params: { + placementId: '16', + requestUrl: jptCallEndPoint + }, + sizes: [[300, 250]], + placementCode: 'test-div-12345' + } + ] + }; + + // Empty bid response + let response = { + cpm: 0 + }; + + pbjs._bidsRequested.push(bidderRequest); + // Adapter needs to be called, in order for the stub to register. + adapter(); + + pbjs.handleOASCB(response); + + expect(stubAddBidResponse.getCall(0)).to.equal(null); + stubAddBidResponse.restore(); + }); + }); + + it('should add bid responses if bids are returned', function () { + let stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); + + let bidderRequest = { + bidderCode: 'orbitsoft', + bids: [ + { + bidId: 'bidIdOrbitsoft1', + bidder: 'orbitsoft', + params: { + placementId: '16', + requestUrl: jptCallEndPoint + }, + sizes: [[300, 250]], + placementCode: 'test-div-12345' + } + ] + }; + + // Bid response + let response = { + callback_uid: 'bidIdOrbitsoft1', + content_url: contentCallEndPoint + 'id=1_201707031440_56069e8e70318303e5869fad86722cb0', + cpm: 0.03, + width: 300, + height: 250 + }; + + pbjs._bidsRequested.push(bidderRequest); + // Adapter needs to be called, in order for the stub to register. + adapter(); + + pbjs.handleOASCB(response); + + let bidPlacementCode1 = stubAddBidResponse.getCall(0).args[0]; + let bidResponse1 = stubAddBidResponse.getCall(0).args[1]; + let bid1width = 300; + let bid1height = 250; + let cpm = 0.03; + let content_url = contentCallEndPoint + 'id=1_201707031440_56069e8e70318303e5869fad86722cb0'; + expect(bidPlacementCode1).to.equal('test-div-12345'); + expect(bidResponse1.getStatusCode()).to.equal(CONSTANTS.STATUS.GOOD); + expect(bidResponse1.bidderCode).to.equal('orbitsoft'); + expect(bidResponse1.width).to.equal(bid1width); + expect(bidResponse1.height).to.equal(bid1height); + expect(bidResponse1.cpm).to.equal(cpm); + expect(bidResponse1.adUrl).to.equal(content_url); + stubAddBidResponse.restore(); + }); + + it('should call loadscript with the correct params', function () { + let spyLoadScript = sinon.spy(adloader, 'loadScript'); + let params = { + bids: [ + { + sizes: [[300, 250], [300, 600]], + params: { + placementId: '16', + requestUrl: jptCallEndPoint + } + } + ] + }; + adapter().callBids(params); + + sinon.assert.calledOnce(spyLoadScript); + + let bidUrl = spyLoadScript.getCall(0).args[0]; + expect(bidUrl).to.include(jptCallEndPoint); + expect(bidUrl).to.include('scid=16'); + expect(bidUrl).to.include('size=300x250'); + expect(bidUrl).to.include('loc'); + spyLoadScript.restore(); + }); + + describe('test orbitsoft callback with params', function () { + it('should not call loadscript when inputting with empty params', function () { + let spyLoadScript = sinon.spy(adloader, 'loadScript'); + adapter().callBids({}); + assert(!spyLoadScript.called); + spyLoadScript.restore(); + }); + + it('should not call loadscript when inputting without requestUrl param ', function () { + let spyLoadScript = sinon.spy(adloader, 'loadScript'); + let params = { + bids: [ + { + params: { + placementId: '16' + } + } + ] + }; + adapter().callBids(params); + assert(!spyLoadScript.called); + spyLoadScript.restore(); + }); + + it('should not call loadscript when inputting with empty params by string ', function () { + let spyLoadScript = sinon.spy(adloader, 'loadScript'); + adapter().callBids(''); + assert(!spyLoadScript.called); + spyLoadScript.restore(); + }); + + it('should call loadscript without size in params', function () { + let spyLoadScript = sinon.spy(adloader, 'loadScript'); + let params = { + bids: [ + { + params: { + placementId: '16', + requestUrl: jptCallEndPoint + } + } + ] + }; + adapter().callBids(params); + + sinon.assert.calledOnce(spyLoadScript); + + let bidUrl = spyLoadScript.getCall(0).args[0]; + expect(bidUrl).to.include(jptCallEndPoint); + expect(bidUrl).to.include('scid=16'); + expect(bidUrl).to.not.include('size='); + expect(bidUrl).to.include('loc'); + spyLoadScript.restore(); + }); + + it('should add style params to adUrl if bids are returned', function () { + let stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); + + let bidderRequest = { + bidderCode: 'orbitsoft', + bids: [ + { + bidId: 'bidIdOrbitsoft2', + bidder: 'orbitsoft', + params: { + placementId: '16', + requestUrl: jptCallEndPoint, + style: { + title: { + family: 'Tahoma', + size: 'medium', + weight: 'normal', + style: 'normal', + color: '0053F9' + }, + description: { + family: 'Tahoma', + size: 'medium', + weight: 'normal', + style: 'normal', + color: '0053F9' + }, + url: { + family: 'Tahoma', + size: 'medium', + weight: 'normal', + style: 'normal', + color: '0053F9' + }, + colors: { + background: 'ffffff', + border: 'E0E0E0', + link: '5B99FE' + } + } + }, + sizes: [[300, 250]], + placementCode: 'test-div-12345' + } + ] + }; + + // Bid response with content_url + let response = { + callback_uid: 'bidIdOrbitsoft2', + content_url: contentCallEndPoint + 'id=1_201707031440_56069e8e70318303e5869fad86722cb0', + cpm: 0.03, + width: 300, + height: 250 + }; + + pbjs._bidsRequested.push(bidderRequest); + // Adapter needs to be called, in order for the stub to register. + adapter(); + + pbjs.handleOASCB(response); + + let bidResponse1 = stubAddBidResponse.getCall(0).args[1]; + let adUrl = bidResponse1.adUrl; + let content_url = contentCallEndPoint + 'id=1_201707031440_56069e8e70318303e5869fad86722cb0'; + expect(adUrl).to.include(content_url); + expect(adUrl).to.include('f1=Tahoma'); + expect(adUrl).to.include('fs1=medium'); + expect(adUrl).to.include('w1=normal'); + expect(adUrl).to.include('s1=normal'); + expect(adUrl).to.include('c3=0053F9'); + expect(adUrl).to.include('f2=Tahoma'); + expect(adUrl).to.include('fs2=medium'); + expect(adUrl).to.include('w2=normal'); + expect(adUrl).to.include('s2=normal'); + expect(adUrl).to.include('c4=0053F9'); + expect(adUrl).to.include('f3=Tahoma'); + expect(adUrl).to.include('fs3=medium'); + expect(adUrl).to.include('w3=normal'); + expect(adUrl).to.include('s3=normal'); + expect(adUrl).to.include('c5=0053F9'); + expect(adUrl).to.include('c2=ffffff'); + expect(adUrl).to.include('c1=E0E0E0'); + expect(adUrl).to.include('c6=5B99FE'); + + stubAddBidResponse.restore(); + }); + + it('should add custom params to adUrl if bids are returned', function () { + let stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); + + let bidderRequest = { + bidderCode: 'orbitsoft', + bids: [ + { + bidId: 'bidIdOrbitsoft3', + bidder: 'orbitsoft', + params: { + placementId: '16', + requestUrl: jptCallEndPoint, + customParams: { + macro_name: 'macro_value' + } + }, + sizes: [[300, 250]], + placementCode: 'test-div-12345' + } + ] + }; + + // Bid response with custom params + let response = { + callback_uid: 'bidIdOrbitsoft3', + content_url: contentCallEndPoint + 'id=1_201707031440_56069e8e70318303e5869fad86722cb0', + cpm: 0.03, + width: 300, + height: 250 + }; + + pbjs._bidsRequested.push(bidderRequest); + // Adapter needs to be called, in order for the stub to register. + adapter(); + + pbjs.handleOASCB(response); + + let bidResponse1 = stubAddBidResponse.getCall(0).args[1]; + let adUrl = bidResponse1.adUrl; + let content_url = contentCallEndPoint + 'id=1_201707031440_56069e8e70318303e5869fad86722cb0'; + expect(adUrl).to.include(content_url); + expect(adUrl).to.include('c.macro_name=macro_value'); + + stubAddBidResponse.restore(); + }); + }); +}); From d068d59fa26534fb73af6f00272ce9b3d9e73486 Mon Sep 17 00:00:00 2001 From: Dmitriy Shimko Date: Thu, 13 Jul 2017 14:07:10 +0300 Subject: [PATCH 02/18] Adding Orbitsoft module (corrected) --- modules/orbitsoftBidAdapter.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/orbitsoftBidAdapter.js b/modules/orbitsoftBidAdapter.js index e4fe863d645..59700eb7d3f 100644 --- a/modules/orbitsoftBidAdapter.js +++ b/modules/orbitsoftBidAdapter.js @@ -43,7 +43,8 @@ OrbitsoftAdapter = function OrbitsoftAdapter() { for (let i = 0; i < bids.length; i++) { let bidRequest = bids[i]; let callbackId = bidRequest.bidId; - adloader.loadScript(buildJPTCall(bidRequest, callbackId)); + let jptCall = buildJPTCall(bidRequest, callbackId); + if (jptCall) {adloader.loadScript(jptCall);} } }; From 42f1d664ccfe1da0eb0cd27e36727b204fed18c7 Mon Sep 17 00:00:00 2001 From: Dmitriy Shimko Date: Fri, 28 Jul 2017 16:14:47 +0300 Subject: [PATCH 03/18] Adding Orbitsoft module (correction of remarks) --- modules/orbitsoftBidAdapter.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/modules/orbitsoftBidAdapter.js b/modules/orbitsoftBidAdapter.js index 59700eb7d3f..8475dc3b15d 100644 --- a/modules/orbitsoftBidAdapter.js +++ b/modules/orbitsoftBidAdapter.js @@ -36,15 +36,18 @@ OrbitsoftAdapter = function OrbitsoftAdapter() { baseAdapter.callBids = function (params) { let bids = params.bids || []; - if (bids.length === 0) { - return; - } - for (let i = 0; i < bids.length; i++) { let bidRequest = bids[i]; let callbackId = bidRequest.bidId; let jptCall = buildJPTCall(bidRequest, callbackId); - if (jptCall) {adloader.loadScript(jptCall);} + + if (jptCall) { adloader.loadScript(jptCall); } + else { + // indicate that there is no bid for this placement + let bid = bidfactory.createBid(CONSTANTS.STATUS.NO_BID, bidRequest); + bid.bidderCode = params.bidderCode; + bidmanager.addBidResponse(bidRequest.placementCode, bid); + } } }; From aba01a3f4a93547ed64b2fa28ba54d769869b536 Mon Sep 17 00:00:00 2001 From: Dmitriy Shimko Date: Fri, 28 Jul 2017 16:32:10 +0300 Subject: [PATCH 04/18] Adding Orbitsoft module (correction of remarks) --- modules/orbitsoftBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/orbitsoftBidAdapter.js b/modules/orbitsoftBidAdapter.js index 8475dc3b15d..17e25505e18 100644 --- a/modules/orbitsoftBidAdapter.js +++ b/modules/orbitsoftBidAdapter.js @@ -223,7 +223,7 @@ OrbitsoftAdapter = function OrbitsoftAdapter() { }; }; -adaptermanager.registerBidAdapter(new OrbitsoftAdapter, 'orbitsoft'); +adaptermanager.registerBidAdapter(new OrbitsoftAdapter(), 'orbitsoft'); adaptermanager.aliasBidAdapter('orbitsoft', 'orbitadserving'); adaptermanager.aliasBidAdapter('orbitsoft', 'orbitscripts'); adaptermanager.aliasBidAdapter('orbitsoft', 'orbitsoftcom'); From be50c559e201f6541a0f1885c0fd17787ce1f2aa Mon Sep 17 00:00:00 2001 From: Dmitriy Shimko Date: Thu, 14 Sep 2017 12:55:51 +0300 Subject: [PATCH 05/18] Adding Orbitsoft module (correction to alias-able) --- modules/orbitsoftBidAdapter.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/modules/orbitsoftBidAdapter.js b/modules/orbitsoftBidAdapter.js index 17e25505e18..94e82ba02f7 100644 --- a/modules/orbitsoftBidAdapter.js +++ b/modules/orbitsoftBidAdapter.js @@ -31,9 +31,8 @@ let styleParamsToFieldsMap = { let OrbitsoftAdapter; OrbitsoftAdapter = function OrbitsoftAdapter() { - let baseAdapter = Adapter.createNew('orbitsoft'); - baseAdapter.callBids = function (params) { + function _callBids(params) { let bids = params.bids || []; for (let i = 0; i < bids.length; i++) { @@ -49,7 +48,7 @@ OrbitsoftAdapter = function OrbitsoftAdapter() { bidmanager.addBidResponse(bidRequest.placementCode, bid); } } - }; + } function buildJPTCall(bid, callbackId) { // Determine tag params @@ -216,13 +215,18 @@ OrbitsoftAdapter = function OrbitsoftAdapter() { } }; - return { - callBids: baseAdapter.callBids, - setBidderCode: baseAdapter.setBidderCode, - buildJPTCall: buildJPTCall - }; + return Object.assign(Adapter.createNew('orbitsoft'), { + callBids: _callBids, + buildJPTCall: buildJPTCall, + createNew: OrbitsoftAdapter.createNew + }); }; +OrbitsoftAdapter.createNew = function() { + return new OrbitsoftAdapter(); +}; + + adaptermanager.registerBidAdapter(new OrbitsoftAdapter(), 'orbitsoft'); adaptermanager.aliasBidAdapter('orbitsoft', 'orbitadserving'); adaptermanager.aliasBidAdapter('orbitsoft', 'orbitscripts'); From 0af08c92dcc9e9918633e0c03cbca2f8a856f837 Mon Sep 17 00:00:00 2001 From: Dmitriy Shimko Date: Thu, 14 Sep 2017 14:59:39 +0300 Subject: [PATCH 06/18] Adding Orbitsoft module (correction to alias-able) --- modules/orbitsoftBidAdapter.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/modules/orbitsoftBidAdapter.js b/modules/orbitsoftBidAdapter.js index 94e82ba02f7..f8ff9e236be 100644 --- a/modules/orbitsoftBidAdapter.js +++ b/modules/orbitsoftBidAdapter.js @@ -31,8 +31,9 @@ let styleParamsToFieldsMap = { let OrbitsoftAdapter; OrbitsoftAdapter = function OrbitsoftAdapter() { + let baseAdapter = Adapter.createNew('orbitsoft'); - function _callBids(params) { + baseAdapter.callBids = function (params) { let bids = params.bids || []; for (let i = 0; i < bids.length; i++) { @@ -48,7 +49,7 @@ OrbitsoftAdapter = function OrbitsoftAdapter() { bidmanager.addBidResponse(bidRequest.placementCode, bid); } } - } + }; function buildJPTCall(bid, callbackId) { // Determine tag params @@ -216,17 +217,12 @@ OrbitsoftAdapter = function OrbitsoftAdapter() { }; return Object.assign(Adapter.createNew('orbitsoft'), { - callBids: _callBids, - buildJPTCall: buildJPTCall, - createNew: OrbitsoftAdapter.createNew + callBids: baseAdapter.callBids, + setBidderCode: baseAdapter.setBidderCode, + buildJPTCall: buildJPTCall }); }; -OrbitsoftAdapter.createNew = function() { - return new OrbitsoftAdapter(); -}; - - adaptermanager.registerBidAdapter(new OrbitsoftAdapter(), 'orbitsoft'); adaptermanager.aliasBidAdapter('orbitsoft', 'orbitadserving'); adaptermanager.aliasBidAdapter('orbitsoft', 'orbitscripts'); From ccf57ef33aa6be716adff0aa29973aeaa09f00b8 Mon Sep 17 00:00:00 2001 From: Dmitriy Shimko Date: Thu, 14 Sep 2017 15:59:38 +0300 Subject: [PATCH 07/18] Adding Orbitsoft module (correction to alias-able) --- modules/orbitsoftBidAdapter.js | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/modules/orbitsoftBidAdapter.js b/modules/orbitsoftBidAdapter.js index f8ff9e236be..8251325a9b9 100644 --- a/modules/orbitsoftBidAdapter.js +++ b/modules/orbitsoftBidAdapter.js @@ -1,12 +1,12 @@ import { getBidRequest } from 'src/utils'; -import adaptermanager from 'src/adaptermanager'; let CONSTANTS = require('src/constants'); -let utils = require('src/utils'); -let adloader = require('src/adloader'); +let Adapter = require('src/adapter'); let bidmanager = require('src/bidmanager'); let bidfactory = require('src/bidfactory'); -let Adapter = require('src/adapter'); +let adloader = require('src/adloader'); +let utils = require('src/utils'); +let adaptermanager = require('src/adaptermanager'); let styleParamsToFieldsMap = { 'title.family': 'f1', // headerFont @@ -28,12 +28,10 @@ let styleParamsToFieldsMap = { 'colors.border': 'c1', // borderColor 'colors.link': 'c6', // lnkColor }; +let ORBITSOFT_BIDDERCODE = 'orbitsoft'; +let OrbitsoftAdapter = function OrbitsoftAdapter() { -let OrbitsoftAdapter; -OrbitsoftAdapter = function OrbitsoftAdapter() { - let baseAdapter = Adapter.createNew('orbitsoft'); - - baseAdapter.callBids = function (params) { + function _callBids (params) { let bids = params.bids || []; for (let i = 0; i < bids.length; i++) { @@ -49,7 +47,7 @@ OrbitsoftAdapter = function OrbitsoftAdapter() { bidmanager.addBidResponse(bidRequest.placementCode, bid); } } - }; + } function buildJPTCall(bid, callbackId) { // Determine tag params @@ -216,14 +214,18 @@ OrbitsoftAdapter = function OrbitsoftAdapter() { } }; - return Object.assign(Adapter.createNew('orbitsoft'), { - callBids: baseAdapter.callBids, - setBidderCode: baseAdapter.setBidderCode, - buildJPTCall: buildJPTCall + return Object.assign(Adapter.createNew(ORBITSOFT_BIDDERCODE), { + callBids: _callBids, + buildJPTCall: buildJPTCall, + createNew: OrbitsoftAdapter.createNew }); }; -adaptermanager.registerBidAdapter(new OrbitsoftAdapter(), 'orbitsoft'); +OrbitsoftAdapter.createNew = function() { + return new OrbitsoftAdapter(); +}; + +adaptermanager.registerBidAdapter(new OrbitsoftAdapter(), ORBITSOFT_BIDDERCODE); adaptermanager.aliasBidAdapter('orbitsoft', 'orbitadserving'); adaptermanager.aliasBidAdapter('orbitsoft', 'orbitscripts'); adaptermanager.aliasBidAdapter('orbitsoft', 'orbitsoftcom'); From 28d89b06de82fc17b2b856c6babc6b85605c2c8c Mon Sep 17 00:00:00 2001 From: Dmitriy Shimko Date: Thu, 14 Sep 2017 17:06:58 +0300 Subject: [PATCH 08/18] Adding Orbitsoft module (correction to alias-able) --- modules/orbitsoftBidAdapter.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/orbitsoftBidAdapter.js b/modules/orbitsoftBidAdapter.js index 8251325a9b9..849afd99b3d 100644 --- a/modules/orbitsoftBidAdapter.js +++ b/modules/orbitsoftBidAdapter.js @@ -1,13 +1,14 @@ import { getBidRequest } from 'src/utils'; +import Adapter from 'src/adapter'; let CONSTANTS = require('src/constants'); -let Adapter = require('src/adapter'); let bidmanager = require('src/bidmanager'); let bidfactory = require('src/bidfactory'); let adloader = require('src/adloader'); let utils = require('src/utils'); let adaptermanager = require('src/adaptermanager'); +let ORBITSOFT_BIDDERCODE = 'orbitsoft'; let styleParamsToFieldsMap = { 'title.family': 'f1', // headerFont 'title.size': 'fs1', // headerFontSize @@ -28,9 +29,8 @@ let styleParamsToFieldsMap = { 'colors.border': 'c1', // borderColor 'colors.link': 'c6', // lnkColor }; -let ORBITSOFT_BIDDERCODE = 'orbitsoft'; -let OrbitsoftAdapter = function OrbitsoftAdapter() { +let OrbitsoftAdapter = function OrbitsoftAdapter() { function _callBids (params) { let bids = params.bids || []; @@ -39,8 +39,9 @@ let OrbitsoftAdapter = function OrbitsoftAdapter() { let callbackId = bidRequest.bidId; let jptCall = buildJPTCall(bidRequest, callbackId); - if (jptCall) { adloader.loadScript(jptCall); } - else { + if (jptCall) { + adloader.loadScript(jptCall); + } else { // indicate that there is no bid for this placement let bid = bidfactory.createBid(CONSTANTS.STATUS.NO_BID, bidRequest); bid.bidderCode = params.bidderCode; @@ -62,8 +63,7 @@ let OrbitsoftAdapter = function OrbitsoftAdapter() { utils.logMessage('No param requestUrl'); // @endif return null; - } - else { + } else { jptCall += '?'; } @@ -214,7 +214,7 @@ let OrbitsoftAdapter = function OrbitsoftAdapter() { } }; - return Object.assign(Adapter.createNew(ORBITSOFT_BIDDERCODE), { + return Object.assign(new Adapter(ORBITSOFT_BIDDERCODE), { callBids: _callBids, buildJPTCall: buildJPTCall, createNew: OrbitsoftAdapter.createNew From 1c873a0ea8bf4f3c95dda2089d83b40db479395a Mon Sep 17 00:00:00 2001 From: Dmitriy Shimko Date: Fri, 15 Sep 2017 11:17:31 +0300 Subject: [PATCH 09/18] Adding Orbitsoft module (correction to new constructor) --- modules/orbitsoftBidAdapter.js | 18 +++++----- test/spec/modules/orbitsoftBidAdapter_spec.js | 36 +++++++++---------- 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/modules/orbitsoftBidAdapter.js b/modules/orbitsoftBidAdapter.js index 849afd99b3d..3e633d59d44 100644 --- a/modules/orbitsoftBidAdapter.js +++ b/modules/orbitsoftBidAdapter.js @@ -1,5 +1,4 @@ import { getBidRequest } from 'src/utils'; -import Adapter from 'src/adapter'; let CONSTANTS = require('src/constants'); let bidmanager = require('src/bidmanager'); @@ -7,6 +6,7 @@ let bidfactory = require('src/bidfactory'); let adloader = require('src/adloader'); let utils = require('src/utils'); let adaptermanager = require('src/adaptermanager'); +let Adapter = require('src/adapter').default; let ORBITSOFT_BIDDERCODE = 'orbitsoft'; let styleParamsToFieldsMap = { @@ -31,7 +31,9 @@ let styleParamsToFieldsMap = { }; let OrbitsoftAdapter = function OrbitsoftAdapter() { - function _callBids (params) { + let baseAdapter = new Adapter(ORBITSOFT_BIDDERCODE); + + baseAdapter.callBids = function(params) { let bids = params.bids || []; for (let i = 0; i < bids.length; i++) { @@ -214,17 +216,13 @@ let OrbitsoftAdapter = function OrbitsoftAdapter() { } }; - return Object.assign(new Adapter(ORBITSOFT_BIDDERCODE), { - callBids: _callBids, - buildJPTCall: buildJPTCall, - createNew: OrbitsoftAdapter.createNew + return Object.assign(this, { + callBids: baseAdapter.callBids, + setBidderCode: baseAdapter.setBidderCode, + buildJPTCall: buildJPTCall }); }; -OrbitsoftAdapter.createNew = function() { - return new OrbitsoftAdapter(); -}; - adaptermanager.registerBidAdapter(new OrbitsoftAdapter(), ORBITSOFT_BIDDERCODE); adaptermanager.aliasBidAdapter('orbitsoft', 'orbitadserving'); adaptermanager.aliasBidAdapter('orbitsoft', 'orbitscripts'); diff --git a/test/spec/modules/orbitsoftBidAdapter_spec.js b/test/spec/modules/orbitsoftBidAdapter_spec.js index efe25492e54..dc37be73483 100644 --- a/test/spec/modules/orbitsoftBidAdapter_spec.js +++ b/test/spec/modules/orbitsoftBidAdapter_spec.js @@ -1,7 +1,7 @@ describe('Orbitsoft Adapter tests', function () { const expect = require('chai').expect; const assert = require('chai').assert; - const adapter = require('modules/orbitsoftBidAdapter'); + const OrbitsoftAdapter = require('modules/orbitsoftBidAdapter'); const bidmanager = require('src/bidmanager'); const adloader = require('src/adloader'); const CONSTANTS = require('src/constants.json'); @@ -19,6 +19,7 @@ describe('Orbitsoft Adapter tests', function () { it('should add empty bid responses if no bids returned', function () { let stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); + let adapter = new OrbitsoftAdapter(); let bidderRequest = { bidderCode: 'orbitsoft', @@ -43,9 +44,6 @@ describe('Orbitsoft Adapter tests', function () { }; pbjs._bidsRequested.push(bidderRequest); - // Adapter needs to be called, in order for the stub to register. - adapter(); - pbjs.handleOASCB(response); let bidPlacementCode1 = stubAddBidResponse.getCall(0).args[0]; @@ -58,6 +56,7 @@ describe('Orbitsoft Adapter tests', function () { it('should add empty bid responses if no bidId returned', function () { let stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); + let adapter = new OrbitsoftAdapter(); let bidderRequest = { bidderCode: 'orbitsoft', @@ -81,9 +80,6 @@ describe('Orbitsoft Adapter tests', function () { }; pbjs._bidsRequested.push(bidderRequest); - // Adapter needs to be called, in order for the stub to register. - adapter(); - pbjs.handleOASCB(response); expect(stubAddBidResponse.getCall(0)).to.equal(null); @@ -93,6 +89,7 @@ describe('Orbitsoft Adapter tests', function () { it('should add bid responses if bids are returned', function () { let stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); + let adapter = new OrbitsoftAdapter(); let bidderRequest = { bidderCode: 'orbitsoft', @@ -120,9 +117,6 @@ describe('Orbitsoft Adapter tests', function () { }; pbjs._bidsRequested.push(bidderRequest); - // Adapter needs to be called, in order for the stub to register. - adapter(); - pbjs.handleOASCB(response); let bidPlacementCode1 = stubAddBidResponse.getCall(0).args[0]; @@ -142,6 +136,7 @@ describe('Orbitsoft Adapter tests', function () { }); it('should call loadscript with the correct params', function () { + let adapter = new OrbitsoftAdapter(); let spyLoadScript = sinon.spy(adloader, 'loadScript'); let params = { bids: [ @@ -154,7 +149,7 @@ describe('Orbitsoft Adapter tests', function () { } ] }; - adapter().callBids(params); + adapter.callBids(params); sinon.assert.calledOnce(spyLoadScript); @@ -168,13 +163,15 @@ describe('Orbitsoft Adapter tests', function () { describe('test orbitsoft callback with params', function () { it('should not call loadscript when inputting with empty params', function () { + let adapter = new OrbitsoftAdapter(); let spyLoadScript = sinon.spy(adloader, 'loadScript'); - adapter().callBids({}); + adapter.callBids({}); assert(!spyLoadScript.called); spyLoadScript.restore(); }); it('should not call loadscript when inputting without requestUrl param ', function () { + let adapter = new OrbitsoftAdapter(); let spyLoadScript = sinon.spy(adloader, 'loadScript'); let params = { bids: [ @@ -185,19 +182,21 @@ describe('Orbitsoft Adapter tests', function () { } ] }; - adapter().callBids(params); + adapter.callBids(params); assert(!spyLoadScript.called); spyLoadScript.restore(); }); it('should not call loadscript when inputting with empty params by string ', function () { + let adapter = new OrbitsoftAdapter(); let spyLoadScript = sinon.spy(adloader, 'loadScript'); - adapter().callBids(''); + adapter.callBids(''); assert(!spyLoadScript.called); spyLoadScript.restore(); }); it('should call loadscript without size in params', function () { + let adapter = new OrbitsoftAdapter(); let spyLoadScript = sinon.spy(adloader, 'loadScript'); let params = { bids: [ @@ -209,7 +208,7 @@ describe('Orbitsoft Adapter tests', function () { } ] }; - adapter().callBids(params); + adapter.callBids(params); sinon.assert.calledOnce(spyLoadScript); @@ -223,6 +222,7 @@ describe('Orbitsoft Adapter tests', function () { it('should add style params to adUrl if bids are returned', function () { let stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); + let adapter = new OrbitsoftAdapter(); let bidderRequest = { bidderCode: 'orbitsoft', @@ -278,8 +278,6 @@ describe('Orbitsoft Adapter tests', function () { }; pbjs._bidsRequested.push(bidderRequest); - // Adapter needs to be called, in order for the stub to register. - adapter(); pbjs.handleOASCB(response); @@ -311,6 +309,7 @@ describe('Orbitsoft Adapter tests', function () { it('should add custom params to adUrl if bids are returned', function () { let stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); + let adapter = new OrbitsoftAdapter(); let bidderRequest = { bidderCode: 'orbitsoft', @@ -341,9 +340,6 @@ describe('Orbitsoft Adapter tests', function () { }; pbjs._bidsRequested.push(bidderRequest); - // Adapter needs to be called, in order for the stub to register. - adapter(); - pbjs.handleOASCB(response); let bidResponse1 = stubAddBidResponse.getCall(0).args[1]; From 6337b57efbf1f7021d8a16cb5a6bca436a07430f Mon Sep 17 00:00:00 2001 From: Dmitriy Shimko Date: Fri, 15 Sep 2017 15:42:48 +0300 Subject: [PATCH 10/18] Adding Orbitsoft module (delete unnecessary aliases) --- modules/orbitsoftBidAdapter.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/modules/orbitsoftBidAdapter.js b/modules/orbitsoftBidAdapter.js index 3e633d59d44..a03eb25818f 100644 --- a/modules/orbitsoftBidAdapter.js +++ b/modules/orbitsoftBidAdapter.js @@ -224,9 +224,4 @@ let OrbitsoftAdapter = function OrbitsoftAdapter() { }; adaptermanager.registerBidAdapter(new OrbitsoftAdapter(), ORBITSOFT_BIDDERCODE); -adaptermanager.aliasBidAdapter('orbitsoft', 'orbitadserving'); -adaptermanager.aliasBidAdapter('orbitsoft', 'orbitscripts'); -adaptermanager.aliasBidAdapter('orbitsoft', 'orbitsoftcom'); -adaptermanager.aliasBidAdapter('orbitsoft', 'orbitsoftru'); - module.exports = OrbitsoftAdapter; From 60aa74b317ee6270257c2db0cb4dc8476bf41c74 Mon Sep 17 00:00:00 2001 From: Dmitriy Shimko Date: Fri, 15 Sep 2017 16:46:21 +0300 Subject: [PATCH 11/18] Adding Orbitsoft module (delete unnecessary aliases) --- modules/orbitsoftBidAdapter.js | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/orbitsoftBidAdapter.js b/modules/orbitsoftBidAdapter.js index a03eb25818f..e01f82a7097 100644 --- a/modules/orbitsoftBidAdapter.js +++ b/modules/orbitsoftBidAdapter.js @@ -224,4 +224,5 @@ let OrbitsoftAdapter = function OrbitsoftAdapter() { }; adaptermanager.registerBidAdapter(new OrbitsoftAdapter(), ORBITSOFT_BIDDERCODE); + module.exports = OrbitsoftAdapter; From ad39397e44289973a7d63989f6c5681e9f85ee8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A5=D0=B0=D1=82=D0=BB=D0=B0=D0=BC=D0=B0=D0=B4=D0=B6?= =?UTF-8?q?=D0=B8=D1=8F=D0=BD=20=D0=92=D0=B8=D1=82=D0=B0=D0=BB=D0=B8=D0=B9?= Date: Tue, 26 Apr 2022 15:35:22 +0300 Subject: [PATCH 12/18] fixed orbitsoftAdapter --- modules/orbitsoftBidAdapter.js | 309 ++++------- test/spec/modules/orbitsoftBidAdapter_spec.js | 488 +++++++----------- 2 files changed, 307 insertions(+), 490 deletions(-) diff --git a/modules/orbitsoftBidAdapter.js b/modules/orbitsoftBidAdapter.js index e01f82a7097..07d1052330b 100644 --- a/modules/orbitsoftBidAdapter.js +++ b/modules/orbitsoftBidAdapter.js @@ -1,15 +1,9 @@ -import { getBidRequest } from 'src/utils'; +import * as utils from '../src/utils.js'; +import {registerBidder} from '../src/adapters/bidderFactory.js'; +import {config} from '../src/config.js'; -let CONSTANTS = require('src/constants'); -let bidmanager = require('src/bidmanager'); -let bidfactory = require('src/bidfactory'); -let adloader = require('src/adloader'); -let utils = require('src/utils'); -let adaptermanager = require('src/adaptermanager'); -let Adapter = require('src/adapter').default; - -let ORBITSOFT_BIDDERCODE = 'orbitsoft'; -let styleParamsToFieldsMap = { +const BIDDER_CODE = 'orbitsoft'; +let styleParamsMap = { 'title.family': 'f1', // headerFont 'title.size': 'fs1', // headerFontSize 'title.weight': 'w1', // headerWeight @@ -29,200 +23,125 @@ let styleParamsToFieldsMap = { 'colors.border': 'c1', // borderColor 'colors.link': 'c6', // lnkColor }; - -let OrbitsoftAdapter = function OrbitsoftAdapter() { - let baseAdapter = new Adapter(ORBITSOFT_BIDDERCODE); - - baseAdapter.callBids = function(params) { - let bids = params.bids || []; - - for (let i = 0; i < bids.length; i++) { - let bidRequest = bids[i]; - let callbackId = bidRequest.bidId; - let jptCall = buildJPTCall(bidRequest, callbackId); - - if (jptCall) { - adloader.loadScript(jptCall); - } else { - // indicate that there is no bid for this placement - let bid = bidfactory.createBid(CONSTANTS.STATUS.NO_BID, bidRequest); - bid.bidderCode = params.bidderCode; - bidmanager.addBidResponse(bidRequest.placementCode, bid); - } - } - } - - function buildJPTCall(bid, callbackId) { - // Determine tag params - let placementId = utils.getBidIdParameter('placementId', bid.params); - - let referrer = utils.getBidIdParameter('ref', bid.params); - let location = utils.getBidIdParameter('loc', bid.params); - let jptCall = utils.getBidIdParameter('requestUrl', bid.params); - if (jptCall.length === 0) { - // No param requestUrl - // @if NODE_ENV='debug' - utils.logMessage('No param requestUrl'); - // @endif - return null; - } else { - jptCall += '?'; - } - - jptCall = utils.tryAppendQueryString(jptCall, 'callback', '$$PREBID_GLOBAL$$.handleOASCB'); - jptCall = utils.tryAppendQueryString(jptCall, 'callback_uid', callbackId); - jptCall = utils.tryAppendQueryString(jptCall, 'scid', placementId); - - // Sizes takes a bit more logic - let sizeQueryString; - let parsedSizes = utils.parseSizesInput(bid.sizes); - - // Combine string into proper query string - let parsedSizesLength = parsedSizes.length; - if (parsedSizesLength > 0) { - // First value should be "size" - sizeQueryString = 'size=' + parsedSizes[0]; - jptCall += sizeQueryString + '&'; - } - - // Append custom attributes: - let paramsCopy = Object.assign({}, bid.params); - - // Delete attributes already used - delete paramsCopy.placementId; - delete paramsCopy.referrer; - delete paramsCopy.style; - delete paramsCopy.customParams; - - // Get the reminder - jptCall += utils.parseQueryStringParameters(paramsCopy); - - // Append location & referrer - if (location === '') { - location = utils.getTopWindowUrl(); - } - if (referrer === '') { - referrer = window.top.document.referrer; - } - jptCall = utils.tryAppendQueryString(jptCall, 'loc', location); - jptCall = utils.tryAppendQueryString(jptCall, 'ref', referrer); - - // Remove the trailing "&" - jptCall = removeTrailingAmp(jptCall); - - // @if NODE_ENV='debug' - utils.logMessage('jpt request built: ' + jptCall); - // @endif - - // Append a timer here to track latency - bid.startTime = new Date().getTime(); - - return jptCall; - } - - // Remove the trailing "&" - function removeTrailingAmp(url) { - if (url.lastIndexOf('&') === url.length - 1) { - url = url.substring(0, url.length - 1); +export const spec = { + code: BIDDER_CODE, + aliases: ['oas', '152media'], // short code and customer aliases + isBidRequestValid: function (bid) { + switch (true) { + case !('params' in bid): + utils.logError(bid.bidder + ': No required params'); + return false; + case !(bid.params.placementId): + utils.logError(bid.bidder + ': No required param placementId'); + return false; + case !(bid.params.requestUrl): + utils.logError(bid.bidder + ': No required param requestUrl'); + return false; } - return url; - } - - // Expose the callback to the global object - $$PREBID_GLOBAL$$.handleOASCB = function (jptResponseObj) { - let bidCode; - - if (jptResponseObj && jptResponseObj.callback_uid) { - let responseCPM; - let id = jptResponseObj.callback_uid; - let placementCode = ''; - let bidObj = getBidRequest(id); - if (bidObj) { - bidCode = bidObj.bidder; - - placementCode = bidObj.placementCode; - - // Set the status - bidObj.status = CONSTANTS.STATUS.GOOD; + return true; + }, + buildRequests: function (validBidRequests) { + let bidRequest; + let serverRequests = []; + for (let i = 0; i < validBidRequests.length; i++) { + bidRequest = validBidRequests[i]; + let bidRequestParams = bidRequest.params; + let callbackId = utils.getUniqueIdentifierStr(); + let placementId = utils.getBidIdParameter('placementId', bidRequestParams); + let requestUrl = utils.getBidIdParameter('requestUrl', bidRequestParams); + let referrer = utils.getBidIdParameter('ref', bidRequestParams); + let location = utils.getBidIdParameter('loc', bidRequestParams); + // Append location & referrer + if (location === '') { + location = utils.getWindowLocation(); + } + if (referrer === '') { + referrer = bidRequest.refererInfo.referer; } - // @if NODE_ENV='debug' - utils.logMessage('JSONP callback function called for ad ID: ' + id); - // @endif - - let bid = []; - if (jptResponseObj.cpm && jptResponseObj.cpm !== 0) { - // Store bid response - responseCPM = jptResponseObj.cpm; - // Bid status is good (indicating 1) - bid = bidfactory.createBid(CONSTANTS.STATUS.GOOD, bidObj); - bid.bidderCode = bidCode; - bid.cpm = responseCPM; - bid.adUrl = jptResponseObj.content_url; - bid.width = jptResponseObj.width; - bid.height = jptResponseObj.height; - - // Styles params - let styles = utils.getBidIdParameter('style', bidObj.params); - let stylesParams = {}; - for (let currentValue in styles) { - if (styles.hasOwnProperty(currentValue)) { - let currentStyle = styles[currentValue]; - for (let field in currentStyle) { - if (currentStyle.hasOwnProperty(field)) { - let styleField = styleParamsToFieldsMap[currentValue + '.' + field]; - if (styleField !== undefined) { - stylesParams[styleField] = currentStyle[field]; - } + // Styles params + let stylesParams = utils.getBidIdParameter('style', bidRequestParams); + let stylesParamsArray = {}; + for (let currentValue in stylesParams) { + if (stylesParams.hasOwnProperty(currentValue)) { + let currentStyle = stylesParams[currentValue]; + for (let field in currentStyle) { + if (currentStyle.hasOwnProperty(field)) { + let styleField = styleParamsMap[currentValue + '.' + field]; + if (typeof styleField !== 'undefined') { + stylesParamsArray[styleField] = currentStyle[field]; } } } } - bid.adUrl += '&' + utils.parseQueryStringParameters(stylesParams); - - // Custom params - let customParams = utils.getBidIdParameter('customParams', bidObj.params); - let customParamsArray = {}; - for (let customField in customParams) { - if (customParams.hasOwnProperty(customField)) { - customParamsArray['c.' + customField] = customParams[customField]; - } - } - let customParamsLink = utils.parseQueryStringParameters(customParamsArray); - if (customParamsLink) { - // Don't append a "&" here, we have already done it in parseQueryStringParameters - bid.adUrl += customParamsLink; + } + // Custom params + let customParams = utils.getBidIdParameter('customParams', bidRequestParams); + let customParamsArray = {}; + for (let customField in customParams) { + if (customParams.hasOwnProperty(customField)) { + customParamsArray['c.' + customField] = customParams[customField]; } - - // Remove the trailing "&" - bid.adUrl = removeTrailingAmp(bid.adUrl); - - bidmanager.addBidResponse(placementCode, bid); - } else { - // No response data - // @if NODE_ENV='debug' - utils.logMessage('No prebid response from Orbitsoft for placement code ' + placementCode); - // @endif - // indicate that there is no bid for this placement - bid = bidfactory.createBid(CONSTANTS.STATUS.NO_BID, bidObj); - bid.bidderCode = bidCode; - bidmanager.addBidResponse(placementCode, bid); } - } else { - // No response data - // @if NODE_ENV='debug' - utils.logMessage('No prebid response for placement'); - // @endif + + // Sizes params (not supports by server, for future features) + let sizesParams = bidRequest.sizes; + let parsedSizes = utils.parseSizesInput(sizesParams); + + serverRequests.push({ + method: 'GET', + url: requestUrl, + data: Object.assign({ + 'scid': placementId, + 'callback_uid': callbackId, + 'loc': location, + 'ref': referrer, + 'size': parsedSizes + }, stylesParamsArray, customParamsArray), + options: {withCredentials: false}, + bidRequest: bidRequest + }); + } + return serverRequests; + }, + interpretResponse: function (serverResponse, request) { + let bidResponses = []; + if (!serverResponse || serverResponse.error) { + utils.logError(BIDDER_CODE + ': Server response error'); + return bidResponses; } - }; - return Object.assign(this, { - callBids: baseAdapter.callBids, - setBidderCode: baseAdapter.setBidderCode, - buildJPTCall: buildJPTCall - }); -}; + const serverBody = serverResponse.body; + if (!serverBody) { + utils.logError(BIDDER_CODE + ': Empty bid response'); + return bidResponses; + } -adaptermanager.registerBidAdapter(new OrbitsoftAdapter(), ORBITSOFT_BIDDERCODE); + const CPM = serverBody.cpm; + const WIDTH = serverBody.width; + const HEIGHT = serverBody.height; + const CREATIVE = serverBody.content_url; + const CALLBACK_UID = serverBody.callback_uid; + const TIME_TO_LIVE = config.getConfig('_bidderTimeout'); + const REFERER = utils.getWindowTop(); + let bidRequest = request.bidRequest; + if (CPM > 0 && WIDTH > 0 && HEIGHT > 0) { + let bidResponse = { + requestId: bidRequest.bidId, + cpm: CPM, + width: WIDTH, + height: HEIGHT, + creativeId: CALLBACK_UID, + ttl: TIME_TO_LIVE, + referrer: REFERER, + currency: 'USD', + netRevenue: true, + adUrl: CREATIVE + }; + bidResponses.push(bidResponse); + } -module.exports = OrbitsoftAdapter; + return bidResponses; + } +}; +registerBidder(spec); diff --git a/test/spec/modules/orbitsoftBidAdapter_spec.js b/test/spec/modules/orbitsoftBidAdapter_spec.js index dc37be73483..d1ecf0e739a 100644 --- a/test/spec/modules/orbitsoftBidAdapter_spec.js +++ b/test/spec/modules/orbitsoftBidAdapter_spec.js @@ -1,238 +1,41 @@ -describe('Orbitsoft Adapter tests', function () { - const expect = require('chai').expect; - const assert = require('chai').assert; - const OrbitsoftAdapter = require('modules/orbitsoftBidAdapter'); - const bidmanager = require('src/bidmanager'); - const adloader = require('src/adloader'); - const CONSTANTS = require('src/constants.json'); +import {expect} from 'chai'; +import {spec} from 'modules/orbitsoftBidAdapter.js'; - const contentCallEndPoint = 'http://orbitsoft.com/ads/show/content?'; - const jptCallEndPoint = 'http://orbitsoft.com/ads/show/hb?'; +const ENDPOINT_URL = 'https://orbitsoft.com/php/ads/hb.phps'; +const REFERRER_URL = 'http://referrer.url/?_='; - before(() => sinon.stub(document.body, 'appendChild')); - after(() => document.body.appendChild.restore()); - - describe('test orbitsoft callback response', function () { - it('should exist and be a function', function () { - expect(pbjs.handleOASCB).to.exist.and.to.be.a('function'); - }); - - it('should add empty bid responses if no bids returned', function () { - let stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); - let adapter = new OrbitsoftAdapter(); - - let bidderRequest = { - bidderCode: 'orbitsoft', - bids: [ - { - bidId: 'bidIdOrbitsoft1', +describe('Orbitsoft adapter', function () { + describe('implementation', function () { + describe('for requests', function () { + it('should accept valid bid', function () { + let validBid = { bidder: 'orbitsoft', params: { - placementId: '16', - requestUrl: jptCallEndPoint - }, - sizes: [[300, 250]], - placementCode: 'test-div-12345' - } - ] - }; - - // Empty bid response - let response = { - callback_uid: 'bidIdOrbitsoft1', - cpm: 0 - }; - - pbjs._bidsRequested.push(bidderRequest); - pbjs.handleOASCB(response); - - let bidPlacementCode1 = stubAddBidResponse.getCall(0).args[0]; - let bidResponse1 = stubAddBidResponse.getCall(0).args[1]; - expect(bidPlacementCode1).to.equal('test-div-12345'); - expect(bidResponse1.getStatusCode()).to.equal(CONSTANTS.STATUS.NO_BID); - expect(bidResponse1.bidderCode).to.equal('orbitsoft'); - stubAddBidResponse.restore(); - }); - - it('should add empty bid responses if no bidId returned', function () { - let stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); - let adapter = new OrbitsoftAdapter(); - - let bidderRequest = { - bidderCode: 'orbitsoft', - bids: [ - { - bidId: 'bidIdOrbitsoft1', - bidder: 'orbitsoft', - params: { - placementId: '16', - requestUrl: jptCallEndPoint - }, - sizes: [[300, 250]], - placementCode: 'test-div-12345' - } - ] - }; - - // Empty bid response - let response = { - cpm: 0 - }; - - pbjs._bidsRequested.push(bidderRequest); - pbjs.handleOASCB(response); - - expect(stubAddBidResponse.getCall(0)).to.equal(null); - stubAddBidResponse.restore(); - }); - }); - - it('should add bid responses if bids are returned', function () { - let stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); - let adapter = new OrbitsoftAdapter(); - - let bidderRequest = { - bidderCode: 'orbitsoft', - bids: [ - { - bidId: 'bidIdOrbitsoft1', - bidder: 'orbitsoft', - params: { - placementId: '16', - requestUrl: jptCallEndPoint - }, - sizes: [[300, 250]], - placementCode: 'test-div-12345' - } - ] - }; - - // Bid response - let response = { - callback_uid: 'bidIdOrbitsoft1', - content_url: contentCallEndPoint + 'id=1_201707031440_56069e8e70318303e5869fad86722cb0', - cpm: 0.03, - width: 300, - height: 250 - }; - - pbjs._bidsRequested.push(bidderRequest); - pbjs.handleOASCB(response); - - let bidPlacementCode1 = stubAddBidResponse.getCall(0).args[0]; - let bidResponse1 = stubAddBidResponse.getCall(0).args[1]; - let bid1width = 300; - let bid1height = 250; - let cpm = 0.03; - let content_url = contentCallEndPoint + 'id=1_201707031440_56069e8e70318303e5869fad86722cb0'; - expect(bidPlacementCode1).to.equal('test-div-12345'); - expect(bidResponse1.getStatusCode()).to.equal(CONSTANTS.STATUS.GOOD); - expect(bidResponse1.bidderCode).to.equal('orbitsoft'); - expect(bidResponse1.width).to.equal(bid1width); - expect(bidResponse1.height).to.equal(bid1height); - expect(bidResponse1.cpm).to.equal(cpm); - expect(bidResponse1.adUrl).to.equal(content_url); - stubAddBidResponse.restore(); - }); - - it('should call loadscript with the correct params', function () { - let adapter = new OrbitsoftAdapter(); - let spyLoadScript = sinon.spy(adloader, 'loadScript'); - let params = { - bids: [ - { - sizes: [[300, 250], [300, 600]], - params: { - placementId: '16', - requestUrl: jptCallEndPoint - } - } - ] - }; - adapter.callBids(params); - - sinon.assert.calledOnce(spyLoadScript); - - let bidUrl = spyLoadScript.getCall(0).args[0]; - expect(bidUrl).to.include(jptCallEndPoint); - expect(bidUrl).to.include('scid=16'); - expect(bidUrl).to.include('size=300x250'); - expect(bidUrl).to.include('loc'); - spyLoadScript.restore(); - }); - - describe('test orbitsoft callback with params', function () { - it('should not call loadscript when inputting with empty params', function () { - let adapter = new OrbitsoftAdapter(); - let spyLoadScript = sinon.spy(adloader, 'loadScript'); - adapter.callBids({}); - assert(!spyLoadScript.called); - spyLoadScript.restore(); - }); - - it('should not call loadscript when inputting without requestUrl param ', function () { - let adapter = new OrbitsoftAdapter(); - let spyLoadScript = sinon.spy(adloader, 'loadScript'); - let params = { - bids: [ - { - params: { - placementId: '16' + placementId: '123', + requestUrl: ENDPOINT_URL } - } - ] - }; - adapter.callBids(params); - assert(!spyLoadScript.called); - spyLoadScript.restore(); - }); - - it('should not call loadscript when inputting with empty params by string ', function () { - let adapter = new OrbitsoftAdapter(); - let spyLoadScript = sinon.spy(adloader, 'loadScript'); - adapter.callBids(''); - assert(!spyLoadScript.called); - spyLoadScript.restore(); - }); + }, + isValid = spec.isBidRequestValid(validBid); - it('should call loadscript without size in params', function () { - let adapter = new OrbitsoftAdapter(); - let spyLoadScript = sinon.spy(adloader, 'loadScript'); - let params = { - bids: [ - { - params: { - placementId: '16', - requestUrl: jptCallEndPoint - } - } - ] - }; - adapter.callBids(params); + expect(isValid).to.equal(true); + }); - sinon.assert.calledOnce(spyLoadScript); + it('should reject invalid bid', function () { + let invalidBid = { + bidder: 'orbitsoft' + }, + isValid = spec.isBidRequestValid(invalidBid); - let bidUrl = spyLoadScript.getCall(0).args[0]; - expect(bidUrl).to.include(jptCallEndPoint); - expect(bidUrl).to.include('scid=16'); - expect(bidUrl).to.not.include('size='); - expect(bidUrl).to.include('loc'); - spyLoadScript.restore(); + expect(isValid).to.equal(false); + }); }); - - it('should add style params to adUrl if bids are returned', function () { - let stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); - let adapter = new OrbitsoftAdapter(); - - let bidderRequest = { - bidderCode: 'orbitsoft', - bids: [ - { - bidId: 'bidIdOrbitsoft2', + describe('for requests', function () { + it('should accept valid bid with styles', function () { + let validBid = { bidder: 'orbitsoft', params: { - placementId: '16', - requestUrl: jptCallEndPoint, + placementId: '123', + requestUrl: ENDPOINT_URL, style: { title: { family: 'Tahoma', @@ -262,93 +65,188 @@ describe('Orbitsoft Adapter tests', function () { } } }, - sizes: [[300, 250]], - placementCode: 'test-div-12345' - } - ] - }; + refererInfo: {referer: REFERRER_URL}, + }, + isValid = spec.isBidRequestValid(validBid); + expect(isValid).to.equal(true); + + let buildRequest = spec.buildRequests([validBid])[0]; + let requestUrl = buildRequest.url; + let requestUrlParams = buildRequest.data; + expect(requestUrl).to.equal(ENDPOINT_URL); + expect(requestUrlParams).have.property('f1', 'Tahoma'); + expect(requestUrlParams).have.property('fs1', 'medium'); + expect(requestUrlParams).have.property('w1', 'normal'); + expect(requestUrlParams).have.property('s1', 'normal'); + expect(requestUrlParams).have.property('c3', '0053F9'); + expect(requestUrlParams).have.property('f2', 'Tahoma'); + expect(requestUrlParams).have.property('fs2', 'medium'); + expect(requestUrlParams).have.property('w2', 'normal'); + expect(requestUrlParams).have.property('s2', 'normal'); + expect(requestUrlParams).have.property('c4', '0053F9'); + expect(requestUrlParams).have.property('f3', 'Tahoma'); + expect(requestUrlParams).have.property('fs3', 'medium'); + expect(requestUrlParams).have.property('w3', 'normal'); + expect(requestUrlParams).have.property('s3', 'normal'); + expect(requestUrlParams).have.property('c5', '0053F9'); + expect(requestUrlParams).have.property('c2', 'ffffff'); + expect(requestUrlParams).have.property('c1', 'E0E0E0'); + expect(requestUrlParams).have.property('c6', '5B99FE'); + }); + + it('should accept valid bid with custom params', function () { + let validBid = { + bidder: 'orbitsoft', + params: { + placementId: '123', + requestUrl: ENDPOINT_URL, + customParams: { + cacheBuster: 'bf4d7c1', + clickUrl: 'http://testclickurl.com' + } + }, + refererInfo: {referer: REFERRER_URL}, + }, + isValid = spec.isBidRequestValid(validBid); + expect(isValid).to.equal(true); - // Bid response with content_url - let response = { - callback_uid: 'bidIdOrbitsoft2', - content_url: contentCallEndPoint + 'id=1_201707031440_56069e8e70318303e5869fad86722cb0', - cpm: 0.03, - width: 300, - height: 250 - }; + let buildRequest = spec.buildRequests([validBid])[0]; + let requestUrlCustomParams = buildRequest.data; + expect(requestUrlCustomParams).have.property('c.cacheBuster', 'bf4d7c1'); + expect(requestUrlCustomParams).have.property('c.clickUrl', 'http://testclickurl.com'); + }); - pbjs._bidsRequested.push(bidderRequest); + it('should reject invalid bid without requestUrl', function () { + let invalidBid = { + bidder: 'orbitsoft', + params: { + placementId: '123' + } + }, + isValid = spec.isBidRequestValid(invalidBid); - pbjs.handleOASCB(response); + expect(isValid).to.equal(false); + }); - let bidResponse1 = stubAddBidResponse.getCall(0).args[1]; - let adUrl = bidResponse1.adUrl; - let content_url = contentCallEndPoint + 'id=1_201707031440_56069e8e70318303e5869fad86722cb0'; - expect(adUrl).to.include(content_url); - expect(adUrl).to.include('f1=Tahoma'); - expect(adUrl).to.include('fs1=medium'); - expect(adUrl).to.include('w1=normal'); - expect(adUrl).to.include('s1=normal'); - expect(adUrl).to.include('c3=0053F9'); - expect(adUrl).to.include('f2=Tahoma'); - expect(adUrl).to.include('fs2=medium'); - expect(adUrl).to.include('w2=normal'); - expect(adUrl).to.include('s2=normal'); - expect(adUrl).to.include('c4=0053F9'); - expect(adUrl).to.include('f3=Tahoma'); - expect(adUrl).to.include('fs3=medium'); - expect(adUrl).to.include('w3=normal'); - expect(adUrl).to.include('s3=normal'); - expect(adUrl).to.include('c5=0053F9'); - expect(adUrl).to.include('c2=ffffff'); - expect(adUrl).to.include('c1=E0E0E0'); - expect(adUrl).to.include('c6=5B99FE'); + it('should reject invalid bid without placementId', function () { + let invalidBid = { + bidder: 'orbitsoft', + params: { + requestUrl: ENDPOINT_URL + } + }, + isValid = spec.isBidRequestValid(invalidBid); - stubAddBidResponse.restore(); + expect(isValid).to.equal(false); + }); }); + describe('bid responses', function () { + it('should return complete bid response', function () { + let serverResponse = { + body: { + callback_uid: '265b29b70cc106', + cpm: 0.5, + width: 240, + height: 240, + content_url: 'https://orbitsoft.com/php/ads/hb.html', + } + }; + + let bidRequests = [ + { + bidder: 'orbitsoft', + params: { + placementId: '123', + requestUrl: ENDPOINT_URL + } + } + ]; + let bids = spec.interpretResponse(serverResponse, {'bidRequest': bidRequests[0]}); + expect(bids).to.be.lengthOf(1); + expect(bids[0].cpm).to.equal(0.5); + expect(bids[0].width).to.equal(240); + expect(bids[0].height).to.equal(240); + expect(bids[0].currency).to.equal('USD'); + expect(bids[0].netRevenue).to.equal(true); + expect(bids[0].adUrl).to.have.length.above(1); + expect(bids[0].adUrl).to.have.string('https://orbitsoft.com/php/ads/hb.html'); + }); + + it('should return empty bid response', function () { + let bidRequests = [ + { + bidder: 'orbitsoft', + params: { + placementId: '123', + requestUrl: ENDPOINT_URL + } + } + ]; + let serverResponse = { + body: { + callback_uid: '265b29b70cc106', + cpm: 0 + } + }, + bids = spec.interpretResponse(serverResponse, {'bidRequest': bidRequests[0]}); - it('should add custom params to adUrl if bids are returned', function () { - let stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); - let adapter = new OrbitsoftAdapter(); + expect(bids).to.be.lengthOf(0); + }); - let bidderRequest = { - bidderCode: 'orbitsoft', - bids: [ + it('should return empty bid response on incorrect size', function () { + let bidRequests = [ { - bidId: 'bidIdOrbitsoft3', bidder: 'orbitsoft', params: { - placementId: '16', - requestUrl: jptCallEndPoint, - customParams: { - macro_name: 'macro_value' - } - }, - sizes: [[300, 250]], - placementCode: 'test-div-12345' + placementId: '123', + requestUrl: ENDPOINT_URL + } } - ] - }; + ]; + let serverResponse = { + body: { + callback_uid: '265b29b70cc106', + cpm: 1.5, + width: 0, + height: 0 + } + }, + bids = spec.interpretResponse(serverResponse, {'bidRequest': bidRequests[0]}); + + expect(bids).to.be.lengthOf(0); + }); - // Bid response with custom params - let response = { - callback_uid: 'bidIdOrbitsoft3', - content_url: contentCallEndPoint + 'id=1_201707031440_56069e8e70318303e5869fad86722cb0', - cpm: 0.03, - width: 300, - height: 250 - }; + it('should return empty bid response with error', function () { + let bidRequests = [ + { + bidder: 'orbitsoft', + params: { + placementId: '123', + requestUrl: ENDPOINT_URL + } + } + ]; + let serverResponse = {error: 'error'}, + bids = spec.interpretResponse(serverResponse, {'bidRequest': bidRequests[0]}); - pbjs._bidsRequested.push(bidderRequest); - pbjs.handleOASCB(response); + expect(bids).to.be.lengthOf(0); + }); - let bidResponse1 = stubAddBidResponse.getCall(0).args[1]; - let adUrl = bidResponse1.adUrl; - let content_url = contentCallEndPoint + 'id=1_201707031440_56069e8e70318303e5869fad86722cb0'; - expect(adUrl).to.include(content_url); - expect(adUrl).to.include('c.macro_name=macro_value'); + it('should return empty bid response on empty body', function () { + let bidRequests = [ + { + bidder: 'orbitsoft', + params: { + placementId: '123', + requestUrl: ENDPOINT_URL + } + } + ]; + let serverResponse = {}, + bids = spec.interpretResponse(serverResponse, {'bidRequest': bidRequests[0]}); - stubAddBidResponse.restore(); + expect(bids).to.be.lengthOf(0); + }); }); }); }); From c00931aabd099598a319958e3cf9b43af978f3bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A5=D0=B0=D1=82=D0=BB=D0=B0=D0=BC=D0=B0=D0=B4=D0=B6?= =?UTF-8?q?=D0=B8=D1=8F=D0=BD=20=D0=92=D0=B8=D1=82=D0=B0=D0=BB=D0=B8=D0=B9?= Date: Thu, 24 Nov 2022 16:39:12 +0300 Subject: [PATCH 13/18] fixed orbitsoftAdapter processing undefined request referrer --- modules/orbitsoftBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/orbitsoftBidAdapter.js b/modules/orbitsoftBidAdapter.js index 07d1052330b..dfed82f0199 100644 --- a/modules/orbitsoftBidAdapter.js +++ b/modules/orbitsoftBidAdapter.js @@ -55,7 +55,7 @@ export const spec = { if (location === '') { location = utils.getWindowLocation(); } - if (referrer === '') { + if (referrer === '' && bidderRequest && bidderRequest.refererInfo) { referrer = bidRequest.refererInfo.referer; } From 1f21bb9004fdd42fc5835bdbc736a12e9cc91c91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A5=D0=B0=D1=82=D0=BB=D0=B0=D0=BC=D0=B0=D0=B4=D0=B6?= =?UTF-8?q?=D0=B8=D1=8F=D0=BD=20=D0=92=D0=B8=D1=82=D0=B0=D0=BB=D0=B8=D0=B9?= Date: Thu, 24 Nov 2022 16:51:44 +0300 Subject: [PATCH 14/18] fixed orbitsoftAdapter processing undefined request referrer --- modules/orbitsoftBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/orbitsoftBidAdapter.js b/modules/orbitsoftBidAdapter.js index dfed82f0199..e5b55ed6cea 100644 --- a/modules/orbitsoftBidAdapter.js +++ b/modules/orbitsoftBidAdapter.js @@ -55,7 +55,7 @@ export const spec = { if (location === '') { location = utils.getWindowLocation(); } - if (referrer === '' && bidderRequest && bidderRequest.refererInfo) { + if (referrer === '' && bidRequest && bidRequest.refererInfo) { referrer = bidRequest.refererInfo.referer; } From 35457cfe9fb1945947fdb80e755b09290dca018c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A5=D0=B0=D1=82=D0=BB=D0=B0=D0=BC=D0=B0=D0=B4=D0=B6?= =?UTF-8?q?=D0=B8=D1=8F=D0=BD=20=D0=92=D0=B8=D1=82=D0=B0=D0=BB=D0=B8=D0=B9?= Date: Tue, 29 Nov 2022 08:50:31 +0300 Subject: [PATCH 15/18] fix-orbitsoftAdaper: codereview fixes --- modules/orbitsoftBidAdapter.js | 46 +++++++++++++++++----------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/modules/orbitsoftBidAdapter.js b/modules/orbitsoftBidAdapter.js index e5b55ed6cea..1d47be1810d 100644 --- a/modules/orbitsoftBidAdapter.js +++ b/modules/orbitsoftBidAdapter.js @@ -1,4 +1,4 @@ -import * as utils from '../src/utils.js'; +import {logError, getUniqueIdentifierStr, getBidIdParameter, getWindowLocation, parseSizesInput, getWindowTop} from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {config} from '../src/config.js'; @@ -29,13 +29,13 @@ export const spec = { isBidRequestValid: function (bid) { switch (true) { case !('params' in bid): - utils.logError(bid.bidder + ': No required params'); + logError(bid.bidder + ': No required params'); return false; case !(bid.params.placementId): - utils.logError(bid.bidder + ': No required param placementId'); + logError(bid.bidder + ': No required param placementId'); return false; case !(bid.params.requestUrl): - utils.logError(bid.bidder + ': No required param requestUrl'); + logError(bid.bidder + ': No required param requestUrl'); return false; } return true; @@ -46,21 +46,20 @@ export const spec = { for (let i = 0; i < validBidRequests.length; i++) { bidRequest = validBidRequests[i]; let bidRequestParams = bidRequest.params; - let callbackId = utils.getUniqueIdentifierStr(); - let placementId = utils.getBidIdParameter('placementId', bidRequestParams); - let requestUrl = utils.getBidIdParameter('requestUrl', bidRequestParams); - let referrer = utils.getBidIdParameter('ref', bidRequestParams); - let location = utils.getBidIdParameter('loc', bidRequestParams); + let placementId = getBidIdParameter('placementId', bidRequestParams); + let requestUrl = getBidIdParameter('requestUrl', bidRequestParams); + let referrer = getBidIdParameter('ref', bidRequestParams); + let location = getBidIdParameter('loc', bidRequestParams); // Append location & referrer if (location === '') { - location = utils.getWindowLocation(); + location = getWindowLocation(); } if (referrer === '' && bidRequest && bidRequest.refererInfo) { referrer = bidRequest.refererInfo.referer; } // Styles params - let stylesParams = utils.getBidIdParameter('style', bidRequestParams); + let stylesParams = getBidIdParameter('style', bidRequestParams); let stylesParamsArray = {}; for (let currentValue in stylesParams) { if (stylesParams.hasOwnProperty(currentValue)) { @@ -76,7 +75,7 @@ export const spec = { } } // Custom params - let customParams = utils.getBidIdParameter('customParams', bidRequestParams); + let customParams = getBidIdParameter('customParams', bidRequestParams); let customParamsArray = {}; for (let customField in customParams) { if (customParams.hasOwnProperty(customField)) { @@ -86,18 +85,19 @@ export const spec = { // Sizes params (not supports by server, for future features) let sizesParams = bidRequest.sizes; - let parsedSizes = utils.parseSizesInput(sizesParams); + let parsedSizes = parseSizesInput(sizesParams); + let requestData = Object.assign({ + 'scid': placementId, + 'callback_uid': getUniqueIdentifierStr(), + 'loc': location, + 'ref': referrer, + 'size': parsedSizes + }, stylesParamsArray, customParamsArray); serverRequests.push({ method: 'GET', url: requestUrl, - data: Object.assign({ - 'scid': placementId, - 'callback_uid': callbackId, - 'loc': location, - 'ref': referrer, - 'size': parsedSizes - }, stylesParamsArray, customParamsArray), + data: JSON.stringify(requestData), options: {withCredentials: false}, bidRequest: bidRequest }); @@ -107,13 +107,13 @@ export const spec = { interpretResponse: function (serverResponse, request) { let bidResponses = []; if (!serverResponse || serverResponse.error) { - utils.logError(BIDDER_CODE + ': Server response error'); + logError(BIDDER_CODE + ': Server response error'); return bidResponses; } const serverBody = serverResponse.body; if (!serverBody) { - utils.logError(BIDDER_CODE + ': Empty bid response'); + logError(BIDDER_CODE + ': Empty bid response'); return bidResponses; } @@ -123,7 +123,7 @@ export const spec = { const CREATIVE = serverBody.content_url; const CALLBACK_UID = serverBody.callback_uid; const TIME_TO_LIVE = config.getConfig('_bidderTimeout'); - const REFERER = utils.getWindowTop(); + const REFERER = getWindowTop(); let bidRequest = request.bidRequest; if (CPM > 0 && WIDTH > 0 && HEIGHT > 0) { let bidResponse = { From d5639ebf44a9b949934fd9083de5763e3d50b01b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A5=D0=B0=D1=82=D0=BB=D0=B0=D0=BC=D0=B0=D0=B4=D0=B6?= =?UTF-8?q?=D0=B8=D1=8F=D0=BD=20=D0=92=D0=B8=D1=82=D0=B0=D0=BB=D0=B8=D0=B9?= Date: Tue, 29 Nov 2022 10:55:57 +0300 Subject: [PATCH 16/18] added changes for new spec --- modules/orbitsoftBidAdapter.js | 7 +++++-- test/spec/modules/orbitsoftBidAdapter_spec.js | 9 ++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/modules/orbitsoftBidAdapter.js b/modules/orbitsoftBidAdapter.js index 1d47be1810d..7732df99332 100644 --- a/modules/orbitsoftBidAdapter.js +++ b/modules/orbitsoftBidAdapter.js @@ -97,7 +97,7 @@ export const spec = { serverRequests.push({ method: 'GET', url: requestUrl, - data: JSON.stringify(requestData), + data: requestData, options: {withCredentials: false}, bidRequest: bidRequest }); @@ -136,7 +136,10 @@ export const spec = { referrer: REFERER, currency: 'USD', netRevenue: true, - adUrl: CREATIVE + adUrl: CREATIVE, + meta: { + advertiserDomains: serverBody.adomain ? serverBody.adomain : [] + } }; bidResponses.push(bidResponse); } diff --git a/test/spec/modules/orbitsoftBidAdapter_spec.js b/test/spec/modules/orbitsoftBidAdapter_spec.js index d1ecf0e739a..8c3187e9324 100644 --- a/test/spec/modules/orbitsoftBidAdapter_spec.js +++ b/test/spec/modules/orbitsoftBidAdapter_spec.js @@ -149,6 +149,7 @@ describe('Orbitsoft adapter', function () { width: 240, height: 240, content_url: 'https://orbitsoft.com/php/ads/hb.html', + adomain: ['test.adomain.tld'] } }; @@ -163,13 +164,15 @@ describe('Orbitsoft adapter', function () { ]; let bids = spec.interpretResponse(serverResponse, {'bidRequest': bidRequests[0]}); expect(bids).to.be.lengthOf(1); - expect(bids[0].cpm).to.equal(0.5); - expect(bids[0].width).to.equal(240); - expect(bids[0].height).to.equal(240); + expect(bids[0].cpm).to.equal(serverResponse.body.cpm); + expect(bids[0].width).to.equal(serverResponse.body.width); + expect(bids[0].height).to.equal(serverResponse.body.height); expect(bids[0].currency).to.equal('USD'); expect(bids[0].netRevenue).to.equal(true); expect(bids[0].adUrl).to.have.length.above(1); expect(bids[0].adUrl).to.have.string('https://orbitsoft.com/php/ads/hb.html'); + expect(Object.keys(bids[0].meta)).to.include.members(['advertiserDomains']); + expect(bids[0].meta.advertiserDomains).to.deep.equal(serverResponse.body.adomain); }); it('should return empty bid response', function () { From c6ee0e7399b5981e786849abd450c3d4b5b1e4c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A5=D0=B0=D1=82=D0=BB=D0=B0=D0=BC=D0=B0=D0=B4=D0=B6?= =?UTF-8?q?=D0=B8=D1=8F=D0=BD=20=D0=92=D0=B8=D1=82=D0=B0=D0=BB=D0=B8=D0=B9?= Date: Tue, 29 Nov 2022 15:58:21 +0300 Subject: [PATCH 17/18] added changes for new spec --- modules/orbitsoftBidAdapter.js | 36 +++++++++---------- test/spec/modules/orbitsoftBidAdapter_spec.js | 4 +-- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/modules/orbitsoftBidAdapter.js b/modules/orbitsoftBidAdapter.js index 7732df99332..69c3696b4f6 100644 --- a/modules/orbitsoftBidAdapter.js +++ b/modules/orbitsoftBidAdapter.js @@ -1,4 +1,4 @@ -import {logError, getUniqueIdentifierStr, getBidIdParameter, getWindowLocation, parseSizesInput, getWindowTop} from '../src/utils.js'; +import * as utils from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {config} from '../src/config.js'; @@ -29,13 +29,13 @@ export const spec = { isBidRequestValid: function (bid) { switch (true) { case !('params' in bid): - logError(bid.bidder + ': No required params'); + utils.logError(bid.bidder + ': No required params'); return false; case !(bid.params.placementId): - logError(bid.bidder + ': No required param placementId'); + utils.logError(bid.bidder + ': No required param placementId'); return false; case !(bid.params.requestUrl): - logError(bid.bidder + ': No required param requestUrl'); + utils.logError(bid.bidder + ': No required param requestUrl'); return false; } return true; @@ -46,20 +46,20 @@ export const spec = { for (let i = 0; i < validBidRequests.length; i++) { bidRequest = validBidRequests[i]; let bidRequestParams = bidRequest.params; - let placementId = getBidIdParameter('placementId', bidRequestParams); - let requestUrl = getBidIdParameter('requestUrl', bidRequestParams); - let referrer = getBidIdParameter('ref', bidRequestParams); - let location = getBidIdParameter('loc', bidRequestParams); + let placementId = utils.getBidIdParameter('placementId', bidRequestParams); + let requestUrl = utils.getBidIdParameter('requestUrl', bidRequestParams); + let referrer = utils.getBidIdParameter('ref', bidRequestParams); + let location = utils.getBidIdParameter('loc', bidRequestParams); // Append location & referrer if (location === '') { - location = getWindowLocation(); + location = utils.getWindowLocation(); } if (referrer === '' && bidRequest && bidRequest.refererInfo) { referrer = bidRequest.refererInfo.referer; } // Styles params - let stylesParams = getBidIdParameter('style', bidRequestParams); + let stylesParams = utils.getBidIdParameter('style', bidRequestParams); let stylesParamsArray = {}; for (let currentValue in stylesParams) { if (stylesParams.hasOwnProperty(currentValue)) { @@ -75,7 +75,7 @@ export const spec = { } } // Custom params - let customParams = getBidIdParameter('customParams', bidRequestParams); + let customParams = utils.getBidIdParameter('customParams', bidRequestParams); let customParamsArray = {}; for (let customField in customParams) { if (customParams.hasOwnProperty(customField)) { @@ -85,19 +85,19 @@ export const spec = { // Sizes params (not supports by server, for future features) let sizesParams = bidRequest.sizes; - let parsedSizes = parseSizesInput(sizesParams); + let parsedSizes = utils.parseSizesInput(sizesParams); let requestData = Object.assign({ 'scid': placementId, - 'callback_uid': getUniqueIdentifierStr(), + 'callback_uid': utils.getUniqueIdentifierStr(), 'loc': location, 'ref': referrer, 'size': parsedSizes }, stylesParamsArray, customParamsArray); serverRequests.push({ - method: 'GET', + method: 'POST', url: requestUrl, - data: requestData, + data: JSON.stringify(requestData), options: {withCredentials: false}, bidRequest: bidRequest }); @@ -107,13 +107,13 @@ export const spec = { interpretResponse: function (serverResponse, request) { let bidResponses = []; if (!serverResponse || serverResponse.error) { - logError(BIDDER_CODE + ': Server response error'); + utils.logError(BIDDER_CODE + ': Server response error'); return bidResponses; } const serverBody = serverResponse.body; if (!serverBody) { - logError(BIDDER_CODE + ': Empty bid response'); + utils.logError(BIDDER_CODE + ': Empty bid response'); return bidResponses; } @@ -123,7 +123,7 @@ export const spec = { const CREATIVE = serverBody.content_url; const CALLBACK_UID = serverBody.callback_uid; const TIME_TO_LIVE = config.getConfig('_bidderTimeout'); - const REFERER = getWindowTop(); + const REFERER = utils.getWindowTop(); let bidRequest = request.bidRequest; if (CPM > 0 && WIDTH > 0 && HEIGHT > 0) { let bidResponse = { diff --git a/test/spec/modules/orbitsoftBidAdapter_spec.js b/test/spec/modules/orbitsoftBidAdapter_spec.js index 8c3187e9324..5f6a05469e3 100644 --- a/test/spec/modules/orbitsoftBidAdapter_spec.js +++ b/test/spec/modules/orbitsoftBidAdapter_spec.js @@ -72,7 +72,7 @@ describe('Orbitsoft adapter', function () { let buildRequest = spec.buildRequests([validBid])[0]; let requestUrl = buildRequest.url; - let requestUrlParams = buildRequest.data; + let requestUrlParams = JSON.parse(buildRequest.data); expect(requestUrl).to.equal(ENDPOINT_URL); expect(requestUrlParams).have.property('f1', 'Tahoma'); expect(requestUrlParams).have.property('fs1', 'medium'); @@ -111,7 +111,7 @@ describe('Orbitsoft adapter', function () { expect(isValid).to.equal(true); let buildRequest = spec.buildRequests([validBid])[0]; - let requestUrlCustomParams = buildRequest.data; + let requestUrlCustomParams = JSON.parse(buildRequest.data); expect(requestUrlCustomParams).have.property('c.cacheBuster', 'bf4d7c1'); expect(requestUrlCustomParams).have.property('c.clickUrl', 'http://testclickurl.com'); }); From 803ca2d336bec7b6e6747484422bdac632b3a221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A5=D0=B0=D1=82=D0=BB=D0=B0=D0=BC=D0=B0=D0=B4=D0=B6?= =?UTF-8?q?=D0=B8=D1=8F=D0=BD=20=D0=92=D0=B8=D1=82=D0=B0=D0=BB=D0=B8=D0=B9?= Date: Tue, 29 Nov 2022 16:22:23 +0300 Subject: [PATCH 18/18] added changes for new spec --- modules/orbitsoftBidAdapter.js | 4 ++-- test/spec/modules/orbitsoftBidAdapter_spec.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/orbitsoftBidAdapter.js b/modules/orbitsoftBidAdapter.js index 69c3696b4f6..d72a8719bd8 100644 --- a/modules/orbitsoftBidAdapter.js +++ b/modules/orbitsoftBidAdapter.js @@ -88,7 +88,7 @@ export const spec = { let parsedSizes = utils.parseSizesInput(sizesParams); let requestData = Object.assign({ 'scid': placementId, - 'callback_uid': utils.getUniqueIdentifierStr(), + 'callback_uid': utils.generateUUID(), 'loc': location, 'ref': referrer, 'size': parsedSizes @@ -97,7 +97,7 @@ export const spec = { serverRequests.push({ method: 'POST', url: requestUrl, - data: JSON.stringify(requestData), + data: requestData, options: {withCredentials: false}, bidRequest: bidRequest }); diff --git a/test/spec/modules/orbitsoftBidAdapter_spec.js b/test/spec/modules/orbitsoftBidAdapter_spec.js index 5f6a05469e3..8c3187e9324 100644 --- a/test/spec/modules/orbitsoftBidAdapter_spec.js +++ b/test/spec/modules/orbitsoftBidAdapter_spec.js @@ -72,7 +72,7 @@ describe('Orbitsoft adapter', function () { let buildRequest = spec.buildRequests([validBid])[0]; let requestUrl = buildRequest.url; - let requestUrlParams = JSON.parse(buildRequest.data); + let requestUrlParams = buildRequest.data; expect(requestUrl).to.equal(ENDPOINT_URL); expect(requestUrlParams).have.property('f1', 'Tahoma'); expect(requestUrlParams).have.property('fs1', 'medium'); @@ -111,7 +111,7 @@ describe('Orbitsoft adapter', function () { expect(isValid).to.equal(true); let buildRequest = spec.buildRequests([validBid])[0]; - let requestUrlCustomParams = JSON.parse(buildRequest.data); + let requestUrlCustomParams = buildRequest.data; expect(requestUrlCustomParams).have.property('c.cacheBuster', 'bf4d7c1'); expect(requestUrlCustomParams).have.property('c.clickUrl', 'http://testclickurl.com'); });