diff --git a/modules/coxBidAdapter.js b/modules/coxBidAdapter.js deleted file mode 100644 index eac1b2081d2..00000000000 --- a/modules/coxBidAdapter.js +++ /dev/null @@ -1,165 +0,0 @@ -'use strict'; - -import * as utils from 'src/utils'; -import { BANNER } from 'src/mediaTypes'; -import { config } from 'src/config'; -import { registerBidder } from 'src/adapters/bidderFactory'; - -const helper = (() => { - let srTestCapabilities = () => { // Legacy - let plugins = navigator.plugins; - let flashVer = -1; - let sf = 'Shockwave Flash'; - - if (plugins && plugins.length > 0) { - if (plugins[sf + ' 2.0'] || plugins[sf]) { - var swVer2 = plugins[sf + ' 2.0'] ? ' 2.0' : ''; - var flashDescription = plugins[sf + swVer2].description; - flashVer = flashDescription.split(' ')[2].split('.')[0]; - } - } - if (flashVer > 4) return 15; else return 7; - }; - - let getRand = () => { - return Math.round(Math.random() * 100000000); - }; - - return { - ingest: function(rawBids = []) { - const adZoneAttributeKeys = ['id', 'size', 'thirdPartyClickUrl', 'dealId']; - const otherKeys = ['siteId', 'wrapper', 'referrerUrl']; - let state = this.createState(); - - rawBids.forEach(oneBid => { - let params = oneBid.params || {}; - - state.tag.auctionId = oneBid.auctionId; - state.tag.responseJSON = true; - - if (params.id && (/^\d+x\d+$/).test(params.size)) { - let adZoneKey = 'as' + params.id; - let zone = {}; - - zone.transactionId = oneBid.transactionId; - zone.bidId = oneBid.bidId; - state.tag.zones = state.tag.zones || {}; - state.tag.zones[adZoneKey] = zone; - - adZoneAttributeKeys.forEach(key => { if (params[key]) zone[key] = params[key]; }); - otherKeys.forEach(key => { if (params[key]) state.tag[key] = params[key]; }); - - // Check for an environment setting - if (params.env) state.env = params.env; - - // Update the placement map - let [x, y] = (params.size).split('x'); - state.placementMap[adZoneKey] = { - 'b': oneBid.bidId, - 'w': x, - 'h': y - }; - } - }); - return state; - }, - - transform: function(coxRawBids = {}, state) { - const pbjsBids = []; - - for (let adZoneKey in state.placementMap) { - let responded = coxRawBids[adZoneKey] - let ingested = state.placementMap[adZoneKey]; - - utils.logInfo('coxBidAdapter.transform', adZoneKey, responded, ingested); - - if (ingested && responded && responded['ad'] && responded['price'] > 0) { - pbjsBids.push({ - requestId: ingested['b'], - cpm: responded['price'], - width: ingested['w'], - height: ingested['h'], - creativeId: responded['adid'], - dealId: responded['dealid'], - currency: 'USD', - netRevenue: true, - ttl: 300, - ad: responded['ad'] - }); - } - } - return pbjsBids; - }, - - getUrl: state => { - // Bounce if the tag is invalid - if (!state.tag.zones) return null; - - let src = (document.location.protocol === 'https:' ? 'https://' : 'http://') + - (!state.env || state.env === 'PRD' ? '' : state.env === 'PPE' ? 'ppe-' : state.env === 'STG' ? 'staging-' : '') + - 'ad.afy11.net/ad?mode=11&nif=0&sf=0&sfd=0&ynw=0&hb=1' + - '&ct=' + srTestCapabilities() + - '&rand=' + getRand() + - '&rk1=' + getRand() + - '&rk2=' + new Date().valueOf() / 1000; - - state.tag.pageUrl = config.getConfig('pageUrl') || utils.getTopWindowUrl(); - state.tag.puTop = true; - - // Attach the serialized tag to our string - src += '&ab=' + encodeURIComponent(JSON.stringify(state.tag)); - - return src; - }, - - createState: () => ({ - env: '', - tag: {}, - placementMap: {} - }) - }; -})(); - -export const spec = { - code: 'cox', - supportedMediaTypes: [BANNER], - - isBidRequestValid: function(bid) { - return !!(bid.params && bid.params.id && bid.params.size); - }, - - buildRequests: function(validBidReqs) { - let state = helper.ingest(validBidReqs); - let url = helper.getUrl(state); - - return !url ? {} : { - method: 'GET', - url: url, - state - }; - }, - - interpretResponse: function({ body: { zones: coxRawBids } }, { state }) { - let bids = helper.transform(coxRawBids, state); - - utils.logInfo('coxBidAdapter.interpretResponse', bids); - return bids; - }, - - getUserSyncs: function(syncOptions, thing) { - try { - var [{ body: { tpCookieSync: urls = [] } }] = thing; - } catch (ignore) { - return []; - } - - let syncs = []; - if (syncOptions.pixelEnabled && urls.length > 0) { - syncs = urls.map((url) => ({ type: 'image', url: url })) - } - utils.logInfo('coxBidAdapter.getuserSyncs', syncs); - return syncs; - } -}; - -registerBidder(spec); diff --git a/modules/coxBidAdapter.md b/modules/coxBidAdapter.md deleted file mode 100644 index f4460b969ed..00000000000 --- a/modules/coxBidAdapter.md +++ /dev/null @@ -1,41 +0,0 @@ -# Overview - -``` -Module Name: Cox/COMET Bid Adapter -Module Type: Bidder Adapter -Maintainer: reynold@coxds.com -``` - -# Description - -Cox/COMET's adapter integration to the Prebid library. - -# Test Parameters - -``` -var adUnits = [ - { - code: 'test-leaderboard', - sizes: [[728, 90]], - bids: [{ - bidder: 'cox', - params: { - size: '728x90', - id: 2000005991607, - siteId: 2000100948180, - } - }] - }, { - code: 'test-banner', - sizes: [[300, 250]], - bids: [{ - bidder: 'cox', - params: { - size: '300x250', - id: 2000005991707, - siteId: 2000100948180, - } - }] - } -] -``` \ No newline at end of file diff --git a/test/spec/modules/coxBidAdapter_spec.js b/test/spec/modules/coxBidAdapter_spec.js deleted file mode 100644 index 8d8b29ed4d7..00000000000 --- a/test/spec/modules/coxBidAdapter_spec.js +++ /dev/null @@ -1,233 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/coxBidAdapter'; -import { newBidder } from 'src/adapters/bidderFactory'; -import { deepClone } from 'src/utils'; - -describe('CoxBidAdapter', function () { - const adapter = newBidder(spec); - - describe('isBidRequestValid', function () { - const CONFIG = { - 'bidder': 'cox', - 'params': { - 'id': '8888', - 'siteId': '1000', - 'size': '300x250' - } - }; - - it('should return true when required params present', function () { - expect(spec.isBidRequestValid(CONFIG)).to.equal(true); - }); - - it('should return false when id param is missing', function () { - let config = deepClone(CONFIG); - config.params.id = null; - - expect(spec.isBidRequestValid(config)).to.equal(false); - }); - - it('should return false when size param is missing', function () { - let config = deepClone(CONFIG); - config.params.size = null; - - expect(spec.isBidRequestValid(config)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - const PROD_DOMAIN = 'ad.afy11.net'; - const PPE_DOMAIN = 'ppe-ad.afy11.net'; - const STG_DOMAIN = 'staging-ad.afy11.net'; - - const BID_INFO = [{ - 'bidder': 'cox', - 'params': { - 'id': '8888', - 'siteId': '1000', - 'size': '300x250' - }, - 'sizes': [[300, 250]], - 'transactionId': 'tId-foo', - 'bidId': 'bId-bar' - }]; - - it('should send bid request to PROD_DOMAIN via GET', function () { - let request = spec.buildRequests(BID_INFO); - expect(request.url).to.have.string(PROD_DOMAIN); - expect(request.method).to.equal('GET'); - }); - - it('should send bid request to PPE_DOMAIN when configured', function () { - let clone = deepClone(BID_INFO); - clone[0].params.env = 'PPE'; - - let request = spec.buildRequests(clone); - expect(request.url).to.have.string(PPE_DOMAIN); - }); - - it('should send bid request to STG_DOMAIN when configured', function () { - let clone = deepClone(BID_INFO); - clone[0].params.env = 'STG'; - - let request = spec.buildRequests(clone); - expect(request.url).to.have.string(STG_DOMAIN); - }); - - it('should return empty when id is invalid', function () { - let clone = deepClone(BID_INFO); - clone[0].params.id = null; - - let request = spec.buildRequests(clone); - expect(request).to.be.an('object').that.is.empty; - }); - - it('should return empty when size is invalid', function () { - let clone = deepClone(BID_INFO); - clone[0].params.size = 'FOO'; - - let request = spec.buildRequests(clone); - expect(request).to.be.an('object').that.is.empty; - }); - }) - - describe('interpretResponse', function () { - const BID_INFO_1 = [{ - 'bidder': 'cox', - 'params': { - 'id': '2000005657007', - 'siteId': '2000101880180', - 'size': '728x90' - }, - 'transactionId': 'foo_1', - 'bidId': 'bar_1' - }]; - - const BID_INFO_2 = [{ - 'bidder': 'cox', - 'params': { - 'id': '2000005658887', - 'siteId': '2000101880180', - 'size': '300x250' - }, - 'transactionId': 'foo_2', - 'bidId': 'bar_2' - }]; - - const RESPONSE_1 = { body: { - 'zones': { - 'as2000005657007': { - 'price': 1.88, - 'dealid': 'AA128460', - 'ad': '

2000005657007
728x90

', - 'adid': '7007-728-90' - }}}}; - - const RESPONSE_2 = { body: { - 'zones': { - 'as2000005658887': { - 'price': 2.88, - 'ad': '

2000005658887
300x250

', - 'adid': '888-88' - }}}}; - - const PBJS_BID_1 = { - 'requestId': 'bar_1', - 'cpm': 1.88, - 'width': '728', - 'height': '90', - 'creativeId': '7007-728-90', - 'dealId': 'AA128460', - 'currency': 'USD', - 'netRevenue': true, - 'ttl': 300, - 'ad': '

2000005657007
728x90

' - }; - - const PBJS_BID_2 = { - 'requestId': 'bar_2', - 'cpm': 2.88, - 'width': '300', - 'height': '250', - 'creativeId': '888-88', - 'dealId': undefined, - 'currency': 'USD', - 'netRevenue': true, - 'ttl': 300, - 'ad': '

2000005658887
300x250

' - }; - - it('should return correct pbjs bid', function () { - let result = spec.interpretResponse(RESPONSE_2, spec.buildRequests(BID_INFO_2)); - expect(result[0]).to.eql(PBJS_BID_2); - }); - - it('should handle multiple bid instances', function () { - let request1 = spec.buildRequests(BID_INFO_1); - let request2 = spec.buildRequests(BID_INFO_2); - - let result2 = spec.interpretResponse(RESPONSE_2, request2); - expect(result2[0]).to.eql(PBJS_BID_2); - - let result1 = spec.interpretResponse(RESPONSE_1, request1); - expect(result1[0]).to.eql(PBJS_BID_1); - }); - - it('should return empty when price is zero', function () { - let clone = deepClone(RESPONSE_1); - clone.body.zones.as2000005657007.price = 0; - - let result = spec.interpretResponse(clone, spec.buildRequests(BID_INFO_1)); - expect(result).to.be.an('array').that.is.empty; - }); - - it('should return empty when there is no ad', function () { - let clone = deepClone(RESPONSE_1); - clone.body.zones.as2000005657007.ad = null; - - let result = spec.interpretResponse(clone, spec.buildRequests(BID_INFO_1)); - expect(result).to.be.an('array').that.is.empty; - }); - - it('should return empty when there is no ad unit info', function () { - let clone = deepClone(RESPONSE_1); - delete (clone.body.zones.as2000005657007); - - let result = spec.interpretResponse(clone, spec.buildRequests(BID_INFO_1)); - expect(result).to.be.an('array').that.is.empty; - }); - }); - - describe('getUserSyncs', function () { - const RESPONSE = [{ body: { - 'zones': {}, - 'tpCookieSync': ['http://pixel.foo.com/', 'http://pixel.bar.com/'] - }}]; - - it('should return correct pbjs syncs when pixels are enabled', function () { - let syncs = spec.getUserSyncs({ pixelEnabled: true }, RESPONSE); - - expect(syncs.map(x => x.type)).to.eql(['image', 'image']); - expect(syncs.map(x => x.url)).to.have.members(['http://pixel.bar.com/', 'http://pixel.foo.com/']); - }); - - it('should return empty when pixels are not enabled', function () { - let syncs = spec.getUserSyncs({ pixelEnabled: false }, RESPONSE); - - expect(syncs).to.be.an('array').that.is.empty; - }); - - it('should return empty when response has no sync data', function () { - let clone = deepClone(RESPONSE); - delete (clone[0].body.tpCookieSync); - - let syncs = spec.getUserSyncs({ pixelEnabled: true }, clone); - expect(syncs).to.be.an('array').that.is.empty; - }); - - it('should return empty when response is empty', function () { - let syncs = spec.getUserSyncs({ pixelEnabled: true }, [{}]); - expect(syncs).to.be.an('array').that.is.empty; - }); - }); -});