From 5711b573b3f4742a66774cf4be439bc14727c7cb Mon Sep 17 00:00:00 2001 From: Steve Alliance Date: Thu, 17 Nov 2016 18:09:48 -0500 Subject: [PATCH 1/3] adding DMX test @97%, two files added one updated --- adapters.json | 1 + src/adapters/districtmDMX.js | 56 +++++ test/spec/adapters/districtm_spec.js | 293 +++++++++++++++++++++++++++ 3 files changed, 350 insertions(+) create mode 100644 src/adapters/districtmDMX.js create mode 100644 test/spec/adapters/districtm_spec.js diff --git a/adapters.json b/adapters.json index aa4b747ef51..7deb8b85eb5 100644 --- a/adapters.json +++ b/adapters.json @@ -10,6 +10,7 @@ "appnexus", "appnexusAst", "conversant", + "districtmDMX", "getintent", "hiromedia", "indexExchange", diff --git a/src/adapters/districtmDMX.js b/src/adapters/districtmDMX.js new file mode 100644 index 00000000000..25ed58c702e --- /dev/null +++ b/src/adapters/districtmDMX.js @@ -0,0 +1,56 @@ +var bidfactory = require('../bidfactory.js'); +var bidmanager = require('../bidmanager.js'); +var adLoader = require('../adloader'); + +var DistrictmAdaptor = function districtmAdaptor(){ + let districtmUrl = window.location.protocol + '//prebid.districtm.ca/lib.js'; + this.callBids = params =>{ + if(!window.hb_dmx_res){ + adLoader.loadScript(districtmUrl,()=>{ + this.sendBids(params); + }); + }else{ + this.sendBids(params); + } + return params; + }; + + + this.handlerRes = function(response, bidObject){ + let bid; + if(parseFloat(response.result.cpm) > 0){ + bid = bidfactory.createBid(1); + bid.bidderCode = bidObject.bidder; + bid.cpm = response.result.cpm; + bid.width = response.result.width; + bid.height = response.result.height; + bid.ad = response.result.banner; + bidmanager.addBidResponse(bidObject.placementCode, bid); + }else{ + bid = bidfactory.createBid(2); + bid.bidderCode = bidObject.bidder; + bidmanager.addBidResponse(bidObject.placementCode, bid); + } + + return bid; + }; + + + this.sendBids = function(params){ + var bids = params.bids; + for(var i = 0; i < bids.length; i++){ + bids[i].params.sizes = window.hb_dmx_res.auction.fixSize(bids[i].sizes); + } + window.hb_dmx_res.auction.run(window.hb_dmx_res.ssp, bids, this.handlerRes); + return bids; + }; + + + return { + callBids: this.callBids, + sendBids: this.sendBids, + handlerRes: this.handlerRes + }; +}; + +module.exports = DistrictmAdaptor; \ No newline at end of file diff --git a/test/spec/adapters/districtm_spec.js b/test/spec/adapters/districtm_spec.js new file mode 100644 index 00000000000..0bd8e494967 --- /dev/null +++ b/test/spec/adapters/districtm_spec.js @@ -0,0 +1,293 @@ +/** + * Created by stevealliance on 2016-11-15. + */ + + + +import {expect} from "chai"; +import {should} from "chai"; +import Adaptor from '../../../src/adapters/districtmDMX'; + +import adLoader from '../../../src/adloader'; + + + +var _each = function(obj, fn){ + for(var o in obj){ + fn(o, obj[o]); + } +} + +let districtm; +const PREBID_RESPONSE = function(){ + return { + result: { + cpm: '3.45', + callbackId: '1490bd6bdc59ce', + width: 300, + height: 250, + banner: 'html' + }, + callback_uid: '1490bd6bdc59ce' + }; +} +const PREBID_PARAMS = { + bidderCode: 'districtmDMX', + requestId: '5ccedbd5-86c1-436f-8649-964262461eac', + bidderRequestId: '1490bd6bdc59ce', + start: new Date().getTime(), + bids: [{ + bidder: 'districtmDMX', + bidId: '84ab500420319d', + bidderRequestId: '1490bd6bdc59ce', + requestId: '5ccedbd5-86c1-436f-8649-964262461eac', + placementCode: 'golden', + params: { + placement: 109801, + floor: '1.00' + }, + sizes: [[300, 250], [300, 600]] + }] +}; + +function resetDm() { + window.hb_dmx_res = undefined; +} + +function activated() { + window.hb_dmx_res = { + ssp: {}, + bh(){ + + }, + auction: { + fixSize(s){ + let size; + if (!Array.isArray(s[0])) { + size = [s[0] + 'x' + s[1]]; + } else { + size = s.map(ss => { + return ss[0] + 'x' + ss[1]; + }) + } + + return size; + + }, + + run(a, b, c){ + + } + } + } +} + + +function definitions(){ + districtm.callBids({ + bidderCode: 'districtmDMX', + bids: [ + { + bidder: 'districtmDMX', + adUnitCode: 'golden', + sizes: [[728, 90]], + params: { + siteId: '101000' + } + }, + { + bidder: 'districtmDMX', + adUnitCode: 'stevealliance', + sizes: [[300, 250]], + params: { + siteId: '101000' + } + } + ] + }); +} +describe('DistrictM adapter test', () => { + + + describe('File loading', ()=>{ + let districtm; + afterEach(()=>{ + + districtm = new Adaptor(); + adLoader.loadScript(districtm.districtUrl, function(){}); + + }) + + it('For loading file ', ()=>{ + expect(!window.hb_dmx_res).to.equal(true); + }) + + + }) + + + describe('check for library do exists', ()=>{ + it('library was not loaded', ()=>{ + + expect(!window.hb_dmx_res).to.equal(true); + }) + + it('library is now available', ()=>{ + activated(); + + expect(!!window.hb_dmx_res).to.equal(true); + + }) + }) + + + describe('Check if size get clean', ()=>{ + beforeEach(()=>{ + activated(); + }) + it('size clean up using fixe size', ()=>{ + activated(); + + expect(window.hb_dmx_res.auction.fixSize([728, 90])[0]).to.equal(['728x90'][0]); + expect(window.hb_dmx_res.auction.fixSize([[300, 250], [300,600]]).toString()).to.equal(['300x250', '300x600'].toString()); + + }) + }) + + describe('Check call bids return no errors', ()=>{ + let districtm; + beforeEach(()=>{ + districtm = new Adaptor(); + }); + it('check value push using cal bids', ()=>{ + let obj = districtm.callBids(PREBID_PARAMS); + obj.should.have.property('bidderCode'); + obj.should.have.property('requestId'); + obj.should.have.property('bidderRequestId'); + obj.should.have.property('start'); + obj.should.have.property('bids'); + + }) + it('check if value got pass correctly for DM params', ()=>{ + let dm = districtm.callBids(PREBID_PARAMS).bids.map( bid => bid); + dm.forEach( a =>{ + a.should.have.property('bidder'); + a.should.have.property('requestId'); + a.should.have.property('bidderRequestId'); + a.should.have.property('placementCode'); + a.should.have.property('params'); + a.should.have.property('sizes'); + expect(a.bidder).to.equal('districtmDMX'); + expect(a.placementCode).to.equal('golden'); + expect(a.params.placement).to.equal(109801); + }) + + + }) + }) + + describe('Run prebid definitions !', ()=>{ + let districtm; + beforeEach(()=>{ + districtm = new Adaptor(); + }) + + it('Run and return send bids', ()=>{ + let sendBids = districtm.sendBids(PREBID_PARAMS); + sendBids.forEach(sb =>{ + + expect(sb.sizes.toString()).to.equal([[300, 250], [300, 600]].toString()); + }) + + }) + + + }) + + describe('HandlerRes function test', ()=>{ + let districtm; + + beforeEach(()=>{ + districtm = new Adaptor(); + }) + + it('it\'s now time to play with the response ...', ()=>{ + let result = districtm.handlerRes(PREBID_RESPONSE(), PREBID_PARAMS); + _each(result, function(k, v){ + console.log(11, `${k} value is ${v}`); + }) + + + expect(result.cpm).to.equal('3.45'); + expect(result.width).to.equal(300); + expect(result.height).to.equal(250); + expect(result.ad).to.equal('html'); + + + + } ) + it('it\'s now time to play with the response failure...', ()=>{ + let result = districtm.handlerRes({result:{cpm:0}}, PREBID_PARAMS); + + result.should.have.property('bidderCode'); + + + } ) + + }) + + describe('look at the adloader', ()=>{ + let districtm; + beforeEach(()=>{ + districtm = new Adaptor(); + sinon.stub(adLoader, "loadScript"); + }) + + it('Verify districtm library is downloaded if nessesary', () => { + resetDm(); + districtm.callBids(PREBID_PARAMS); + let libraryLoadCall = adLoader.loadScript.firstCall.args[0]; + let callback = adLoader.loadScript.firstCall.args[1]; + expect(libraryLoadCall).to.equal('http://prebid.districtm.ca/lib.js'); + expect(callback).to.be.a('function'); + + + }); + + afterEach(()=>{ + adLoader.loadScript.restore(); + }) + + + + + }); + describe('run send bid from within !!!', ()=> { + beforeEach(()=> { + districtm = new Adaptor(); + sinon.stub(districtm, 'sendBids'); + }) + + it('last test on send bids', ()=>{ + resetDm(); + districtm.sendBids(PREBID_PARAMS); + expect(districtm.sendBids.calledOnce).to.be.true; + expect(districtm.sendBids.firstCall.args[0]).to.be.a('object'); + + + }); + + afterEach(()=> { + districtm.sendBids.restore(); + }) + + }); + + + + + + + +}); + From ad33b564ec13d4f8b6aac9e5f9d61e35f9b90f81 Mon Sep 17 00:00:00 2001 From: Steve Alliance Date: Wed, 30 Nov 2016 17:43:46 -0500 Subject: [PATCH 2/3] Update districtm_spec.js --- test/spec/adapters/districtm_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/spec/adapters/districtm_spec.js b/test/spec/adapters/districtm_spec.js index 0bd8e494967..4b457fe8d3a 100644 --- a/test/spec/adapters/districtm_spec.js +++ b/test/spec/adapters/districtm_spec.js @@ -214,7 +214,7 @@ describe('DistrictM adapter test', () => { it('it\'s now time to play with the response ...', ()=>{ let result = districtm.handlerRes(PREBID_RESPONSE(), PREBID_PARAMS); _each(result, function(k, v){ - console.log(11, `${k} value is ${v}`); + }) From fbd31ff13205bda50fcfdcc66a15d6ef9cd04669 Mon Sep 17 00:00:00 2001 From: Steve Alliance Date: Wed, 30 Nov 2016 17:45:31 -0500 Subject: [PATCH 3/3] Update districtmDMX.js --- src/adapters/districtmDMX.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/adapters/districtmDMX.js b/src/adapters/districtmDMX.js index 25ed58c702e..9dd6bf4c36d 100644 --- a/src/adapters/districtmDMX.js +++ b/src/adapters/districtmDMX.js @@ -3,8 +3,8 @@ var bidmanager = require('../bidmanager.js'); var adLoader = require('../adloader'); var DistrictmAdaptor = function districtmAdaptor(){ - let districtmUrl = window.location.protocol + '//prebid.districtm.ca/lib.js'; - this.callBids = params =>{ + let districtmUrl = window.location.protocol + '//prebid.districtm.ca/lib.js'; + this.callBids = params =>{ if(!window.hb_dmx_res){ adLoader.loadScript(districtmUrl,()=>{ this.sendBids(params); @@ -53,4 +53,4 @@ var DistrictmAdaptor = function districtmAdaptor(){ }; }; -module.exports = DistrictmAdaptor; \ No newline at end of file +module.exports = DistrictmAdaptor;