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

admixer adapter: add "video" mediaType support #1200

Merged
merged 3 commits into from
Jun 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions adapters.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,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');
})
});
});
});