-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new adapter districtmDMX #811
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
"appnexus", | ||
"appnexusAst", | ||
"conversant", | ||
"districtmDMX", | ||
"getintent", | ||
"hiromedia", | ||
"indexExchange", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the |
||
}) | ||
|
||
|
||
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(); | ||
}) | ||
|
||
}); | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
}); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The spacing on this line 6 and this line is causing a jscs error:
Expected indentation of 2 characters
. Please use two spaces on these lines rather than 3, or alternatively, place// jscs:disable
at the top of this file to avoid these errors from displaying during the build process