Skip to content

Commit

Permalink
admixer adapter: add "video" mediaType support (#1200)
Browse files Browse the repository at this point in the history
* Atomx adapter: add "video" mediaType support

* admixer adapter: fix lint errors
  • Loading branch information
Galphimbl authored and protonate committed Jun 6, 2017
1 parent 4b34352 commit 803ef04
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 11 deletions.
5 changes: 5 additions & 0 deletions adapters.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,10 @@
"rhythmone": {
"supportedMediaTypes": ["video"]
}
},
{
"admixer": {
"supportedMediaTypes": ["video"]
}
}
]
20 changes: 18 additions & 2 deletions src/adapters/admixer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var utils = require('../utils.js');
*/
var AdmixerAdapter = function AdmixerAdapter() {
var invUrl = '//inv-nets.admixer.net/prebid.aspx';
var invVastUrl = '//inv-nets.admixer.net/videoprebid.aspx';

function _callBids(data) {
var bids = data.bids || [];
Expand All @@ -21,7 +22,16 @@ var AdmixerAdapter = function AdmixerAdapter() {
'callback_uid': bid.placementCode
};
if (params.zone) {
_requestBid(invUrl, params);
if (bid.mediaType === 'video') {
var videoParams = {};
if (typeof bid.video === 'object') {
Object.assign(videoParams, bid.video);
}
Object.assign(videoParams, params);
_requestBid(invVastUrl, params);
} else {
_requestBid(invUrl, params);
}
} else {
var bidObject = bidfactory.createBid(2);
bidObject.bidderCode = 'admixer';
Expand All @@ -48,7 +58,13 @@ var AdmixerAdapter = function AdmixerAdapter() {
bidObject = bidfactory.createBid(1);
bidObject.bidderCode = 'admixer';
bidObject.cpm = bid.cpm;
bidObject.ad = bid.ad;
if (bid.vastUrl) {
bidObject.mediaType = 'video';
bidObject.vastUrl = bid.vastUrl;
bidObject.descriptionUrl = bid.vastUrl;
} else {
bidObject.ad = bid.ad;
}
bidObject.width = bid.width;
bidObject.height = bid.height;
} else {
Expand Down
125 changes: 116 additions & 9 deletions test/spec/adapters/admixer_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,54 @@ describe('Admixer adapter', function () {
}
]
};
var validVideoData_1 = {
bids: [
{
mediaType: 'video',
bidder: 'admixer',
bidId: 'bid_id',
params: {zone: 'zone_id'},
placementCode: 'ad-unit-1',
sizes: [[300, 250], [300, 600]]
}
]
};
var validVideoData_2 = {
bids: [
{
mediaType: 'video',
bidder: 'admixer',
bidId: 'bid_id',
params: {zone: 'zone_id'},
placementCode: 'ad-unit-1',
sizes: [300, 250]
}
]
};
var validVideoData_3 = {
bids: [
{
mediaType: 'video',
bidder: 'admixer',
bidId: 'bid_id',
params: {zone: 'zone_id', video: {skippable: true}},
placementCode: 'ad-unit-1',
sizes: [300, 250]
}
]
};
var invalidVideoData = {
bids: [
{
mediaType: 'video',
bidder: 'admixer',
bidId: 'bid_id',
params: {},
placementCode: 'ad-unit-1',
sizes: [[300, 250], [300, 600]]
}
]
};
var responseWithAd = JSON.stringify({
'result': {
'cpm': 2.2,
Expand All @@ -57,13 +105,38 @@ describe('Admixer adapter', function () {
},
'callback_uid': 'ad-unit-1'
});
var responseWithVideoAd = JSON.stringify({
'result': {
'cpm': 2.2,
'vastUrl': 'http://inv-nets.admixer.net/vastxml.aspx?req=9d651544-daf4-48ed-ae0c-38a60a4e1920&vk=e914f026449e49aeb6eea07b9642a2ce',
'width': 300,
'height': 250
},
'callback_uid': 'ad-unit-1'
});
var responseWithoutVideoAd = JSON.stringify({
'result': {
'cpm': 0,
'vastUrl': '',
'width': 0,
'height': 0
},
'callback_uid': 'ad-unit-1'
});
var responseEmpty = '';
var invUrl = '//inv-nets.admixer.net/prebid.aspx';
var invVastUrl = '//inv-nets.admixer.net/videoprebid.aspx';
var validJsonParams = {
zone: 'zone_id',
callback_uid: 'ad-unit-1',
sizes: '300x250-300x600'
};
var validJsonVideoParams = {
zone: 'zone_id',
callback_uid: 'ad-unit-1',
sizes: '300x250-300x600',
skippable: true
};
describe('bid request with valid data', function () {
var stubAjax;
beforeEach(function () {
Expand All @@ -73,19 +146,32 @@ describe('Admixer adapter', function () {
afterEach(function () {
stubAjax.restore();
});
it('bid request should be called. sizes style -> [[],[]]', function () {
it('display: bid request should be called. sizes style -> [[],[]]', function () {
Adapter.callBids(validData_1);
sinon.assert.calledOnce(stubAjax);
});
it('bid request should be called. sizes style -> []', function () {
it('video: bid request should be called. sizes style -> [[],[]]', function () {
Adapter.callBids(validVideoData_1);
sinon.assert.calledOnce(stubAjax);
});
it('display: bid request should be called. sizes style -> []', function () {
Adapter.callBids(validData_2);
sinon.assert.calledOnce(stubAjax);
});
it('ajax params should be matched', function () {
it('video: bid request should be called. sizes style -> []', function () {
Adapter.callBids(validVideoData_2);
sinon.assert.calledOnce(stubAjax);
});
it('display: ajax params should be matched', function () {
Adapter.callBids(validData_1);
sinon.assert.calledWith(stubAjax, sinon.match(invUrl, function () {
}, validJsonParams, {method: 'GET'}));
});
it('video: ajax params should be matched', function () {
Adapter.callBids(validVideoData_3);
sinon.assert.calledWith(stubAjax, sinon.match(invVastUrl, function () {
}, validJsonVideoParams, {method: 'GET'}));
});
});
describe('bid request with invalid data', function () {
var addBidResponse, stubAjax;
Expand All @@ -98,15 +184,24 @@ describe('Admixer adapter', function () {
addBidResponse.restore();
stubAjax.restore();
});
it('ajax shouldn\'t be called', function () {
it('display: ajax shouldn\'t be called', function () {
Adapter.callBids(invalidData);
sinon.assert.notCalled(stubAjax);
});
it('bidmanager.addBidResponse status code must to be equal "' + CONSTANTS.STATUS.NO_BID + '"', function () {
it('video: ajax shouldn\'t be called', function () {
Adapter.callBids(invalidVideoData);
sinon.assert.notCalled(stubAjax);
});
it('display: bidmanager.addBidResponse status code must to be equal "' + CONSTANTS.STATUS.NO_BID + '"', function () {
Adapter.callBids(invalidData);
expect(addBidResponse.firstCall.args[1].getStatusCode()).to.equal(CONSTANTS.STATUS.NO_BID);
expect(addBidResponse.firstCall.args[1].bidderCode).to.equal('admixer');
});
it('video: bidmanager.addBidResponse status code must to be equal "' + CONSTANTS.STATUS.NO_BID + '"', function () {
Adapter.callBids(invalidVideoData);
expect(addBidResponse.firstCall.args[1].getStatusCode()).to.equal(CONSTANTS.STATUS.NO_BID);
expect(addBidResponse.firstCall.args[1].bidderCode).to.equal('admixer');
});
});
describe('bid response', function () {
var addBidResponse;
Expand All @@ -116,23 +211,35 @@ describe('Admixer adapter', function () {
afterEach(function () {
addBidResponse.restore();
});
it('response with ad. bidmanager.addBidResponse status code must to be equal "' + CONSTANTS.STATUS.GOOD + '"', function () {
it('display: response with ad. bidmanager.addBidResponse status code must to be equal "' + CONSTANTS.STATUS.GOOD + '"', function () {
Adapter.responseCallback(responseWithAd);
var arg = addBidResponse.firstCall.args[1];
expect(arg.getStatusCode()).to.equal(CONSTANTS.STATUS.GOOD);
expect(arg.bidderCode).to.equal('admixer');
});
it('response without ad. bidmanager.addBidResponse status code must to be equal "' + CONSTANTS.STATUS.NO_BID, function () {
it('video: response with ad. bidmanager.addBidResponse status code must to be equal "' + CONSTANTS.STATUS.GOOD + '"', function () {
Adapter.responseCallback(responseWithVideoAd);
var arg = addBidResponse.firstCall.args[1];
expect(arg.getStatusCode()).to.equal(CONSTANTS.STATUS.GOOD);
expect(arg.bidderCode).to.equal('admixer');
});
it('display: response without ad. bidmanager.addBidResponse status code must to be equal "' + CONSTANTS.STATUS.NO_BID, function () {
Adapter.responseCallback(responseWithoutAd);
var arg = addBidResponse.firstCall.args[1];
expect(arg.getStatusCode()).to.equal(CONSTANTS.STATUS.NO_BID);
expect(arg.bidderCode).to.equal('admixer');
});
it('response empty. bidmanager.addBidResponse status code must to be equal "' + CONSTANTS.STATUS.NO_BID, function () {
it('video: response without ad. bidmanager.addBidResponse status code must to be equal "' + CONSTANTS.STATUS.NO_BID, function () {
Adapter.responseCallback(responseWithoutVideoAd);
var arg = addBidResponse.firstCall.args[1];
expect(arg.getStatusCode()).to.equal(CONSTANTS.STATUS.NO_BID);
expect(arg.bidderCode).to.equal('admixer');
});
it('display/video: response empty. bidmanager.addBidResponse status code must to be equal "' + CONSTANTS.STATUS.NO_BID, function () {
Adapter.responseCallback(responseEmpty);
var arg = addBidResponse.firstCall.args[1];
expect(arg.getStatusCode()).to.equal(CONSTANTS.STATUS.NO_BID);
expect(arg.bidderCode).to.equal('admixer');
})
});
});
});

0 comments on commit 803ef04

Please sign in to comment.