Skip to content
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 3 commits into from
Dec 5, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions adapters.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"appnexus",
"appnexusAst",
"conversant",
"districtmDMX",
"getintent",
"hiromedia",
"indexExchange",
Expand Down
56 changes: 56 additions & 0 deletions src/adapters/districtmDMX.js
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 =>{
Copy link
Collaborator

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

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;
293 changes: 293 additions & 0 deletions test/spec/adapters/districtm_spec.js
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}`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the test directory we try to avoid logging to the console to avoid having non-build related activity displayed during the build process. Please convert this to an assertion if it makes sense or remove the line

})


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();
})

});







});