Skip to content

Commit

Permalink
AdkernelAdn adapter minor update (prebid#4033)
Browse files Browse the repository at this point in the history
* Updated maintainer email

* Minor refactoring & more unit tests

* Updated config example
  • Loading branch information
ckbo3hrk authored and sa1omon committed Nov 28, 2019
1 parent 4579247 commit 6912365
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 62 deletions.
36 changes: 16 additions & 20 deletions modules/adkernelAdnBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import * as utils from '../src/utils';
import {registerBidder} from '../src/adapters/bidderFactory';
import {BANNER, VIDEO} from '../src/mediaTypes';
import includes from 'core-js/library/fn/array/includes';
import {parse as parseUrl} from '../src/url';

const DEFAULT_ADKERNEL_DSP_DOMAIN = 'tag.adkernel.com';
const VIDEO_TARGETING = ['mimes', 'protocols', 'api'];
const DEFAULT_MIMES = ['video/mp4', 'video/webm', 'application/x-shockwave-flash', 'application/javascript'];
const DEFAULT_PROTOCOLS = [2, 3, 5, 6];
const DEFAULT_APIS = [1, 2];
Expand All @@ -19,25 +17,22 @@ function buildImp(bidRequest) {
id: bidRequest.bidId,
tagid: bidRequest.adUnitCode
};
if (utils.deepAccess(bidRequest, `mediaTypes.banner`)) {
let sizes = canonicalizeSizesArray(bidRequest.mediaTypes.banner.sizes);
let bannerReq = utils.deepAccess(bidRequest, `mediaTypes.banner`);
let videoReq = utils.deepAccess(bidRequest, `mediaTypes.video`);
if (bannerReq) {
let sizes = canonicalizeSizesArray(bannerReq.sizes);
imp.banner = {
format: utils.parseSizesInput(sizes)
}
} else if (utils.deepAccess(bidRequest, `mediaTypes.video`)) {
let size = canonicalizeSizesArray(bidRequest.mediaTypes.video.playerSize)[0];
} else if (videoReq) {
let size = canonicalizeSizesArray(videoReq.playerSize)[0];
imp.video = {
w: size[0],
h: size[1],
mimes: DEFAULT_MIMES,
protocols: DEFAULT_PROTOCOLS,
api: DEFAULT_APIS
mimes: videoReq.mimes || DEFAULT_MIMES,
protocols: videoReq.protocols || DEFAULT_PROTOCOLS,
api: videoReq.api || DEFAULT_APIS
};
if (bidRequest.params.video) {
Object.keys(bidRequest.params.video)
.filter(param => includes(VIDEO_TARGETING, param))
.forEach(param => imp.video[param] = bidRequest.params.video[param]);
}
}
return imp;
}
Expand Down Expand Up @@ -118,8 +113,11 @@ export const spec = {
aliases: ['engagesimply'],

isBidRequestValid: function(bidRequest) {
return 'params' in bidRequest && (typeof bidRequest.params.host === 'undefined' || typeof bidRequest.params.host === 'string') &&
typeof bidRequest.params.pubId === 'number' && 'mediaTypes' in bidRequest && ('banner' in bidRequest.mediaTypes || 'video' in bidRequest.mediaTypes);
return 'params' in bidRequest &&
(typeof bidRequest.params.host === 'undefined' || typeof bidRequest.params.host === 'string') &&
typeof bidRequest.params.pubId === 'number' &&
'mediaTypes' in bidRequest &&
('banner' in bidRequest.mediaTypes || 'video' in bidRequest.mediaTypes);
},

buildRequests: function(bidRequests, bidderRequest) {
Expand All @@ -133,10 +131,8 @@ export const spec = {
acc[host][pubId].push(curr);
return acc;
}, {});
let auctionId = bidderRequest.auctionId;
let gdprConsent = bidderRequest.gdprConsent;
let transactionId = bidderRequest.transactionId;
let refererInfo = bidderRequest.refererInfo;

let {auctionId, gdprConsent, transactionId, refererInfo} = bidderRequest;
let requests = [];
Object.keys(dispatch).forEach(host => {
Object.keys(dispatch[host]).forEach(pubId => {
Expand Down
63 changes: 34 additions & 29 deletions modules/adkernelAdnBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
```
Module Name: AdKernel ADN Bidder Adapter
Module Type: Bidder Adapter
Maintainer: denis@adkernel.com
Maintainer: prebid-dev@adkernel.com
```

# Description
Expand All @@ -14,32 +14,37 @@ Banner and video formats are supported.

# Test Parameters
```
var adUnits = [
{
code: 'banner-ad-div',
sizes: [[300, 250], [300, 200]],
bids: [
{
bidder: 'adkernelAdn',
params: {
pubId: 50357,
host: 'dsp-staging.adkernel.com'
}
}
]
}, {
code: 'video-ad-player',
sizes: [640, 480],
bids: [
{
bidder: 'adkernelAdn',
mediaType : 'video',
params: {
pubId: 50357,
host: 'dsp-staging.adkernel.com'
}
}
]
}
];
var adUnits = [{
code: 'banner-ad-div',
mediaTypes: {
banner: {
sizes: [
[300, 250],
[300, 200] // banner sizes
],
}
},
bids: [{
bidder: 'adkernelAdn',
params: {
pubId: 50357,
host: 'dsp-staging.adkernel.com'
}
}]
}, {
code: 'video-ad-player',
mediaTypes: {
video: {
context: 'instream', // or 'outstream'
playerSize: [640, 480] // video player size
}
},
bids: [{
bidder: 'adkernelAdn',
params: {
pubId: 50357,
host: 'dsp-staging.adkernel.com'
}
}]
}];
```
70 changes: 57 additions & 13 deletions test/spec/modules/adkernelAdnBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ describe('AdkernelAdn adapter', function () {
}
},
adUnitCode: 'ad-unit-1',
},
bid2_pub1 = {
}, bid2_pub1 = {
bidder: 'adkernelAdn',
transactionId: 'transact0',
bidderRequestId: 'req0',
Expand All @@ -34,8 +33,7 @@ describe('AdkernelAdn adapter', function () {
sizes: [[300, 250]]
}
}
},
bid1_pub2 = {
}, bid1_pub2 = {
bidder: 'adkernelAdn',
transactionId: 'transact2',
bidderRequestId: 'req1',
Expand All @@ -60,17 +58,15 @@ describe('AdkernelAdn adapter', function () {
mediaTypes: {
video: {
context: 'instream',
playerSize: [640, 300]
}
},
adUnitCode: 'video_wrapper',
params: {
pubId: 7,
video: {
playerSize: [640, 300],
mimes: ['video/mp4', 'video/webm'],
api: [1, 2],
protocols: [5, 6]
}
},
adUnitCode: 'video_wrapper',
params: {
pubId: 7
}
}, bid_video2 = {
bidder: 'adkernelAdn',
Expand All @@ -85,11 +81,23 @@ describe('AdkernelAdn adapter', function () {
context: 'instream'
}
},

adUnitCode: 'video_wrapper2',
params: {
pubId: 7
}
}, bid_multiformat = {
bidder: 'adkernelAdn',
transactionId: 'f82c64b8-c602-42a4-9791-4a268f6559ed',
bidderRequestId: 'req-001',
auctionId: 'auc-001',
bidId: 'Bid_01',
sizes: [[300, 250], [300, 200]],
mediaTypes: {
banner: {sizes: [[300, 250], [300, 200]]},
video: {context: 'instream', playerSize: [[640, 480]]}
},
adUnitCode: 'ad-unit-1',
params: {pubId: 7}
};

const response = {
Expand Down Expand Up @@ -137,9 +145,11 @@ describe('AdkernelAdn adapter', function () {

describe('input parameters validation', () => {
it('empty request shouldn\'t generate exception', () => {
expect(spec.isBidRequestValid({bidderCode: 'adkernelAdn'
expect(spec.isBidRequestValid({
bidderCode: 'adkernelAdn'
})).to.be.equal(false);
});

it('request without pubid should be ignored', () => {
expect(spec.isBidRequestValid({
bidder: 'adkernelAdn',
Expand All @@ -148,6 +158,7 @@ describe('AdkernelAdn adapter', function () {
sizes: [[300, 250]]
})).to.be.equal(false);
});

it('request with invalid pubid should be ignored', () => {
expect(spec.isBidRequestValid({
bidder: 'adkernelAdn',
Expand All @@ -158,6 +169,7 @@ describe('AdkernelAdn adapter', function () {
sizes: [[300, 250]]
})).to.be.equal(false);
});

it('request with totally invalid host should be ignored', () => {
expect(spec.isBidRequestValid({
bidder: 'adkernelAdn',
Expand All @@ -169,6 +181,7 @@ describe('AdkernelAdn adapter', function () {
sizes: [[300, 250]]
})).to.be.equal(false);
});

it('valid request should be accepted', () => {
expect(spec.isBidRequestValid({
bidder: 'adkernelAdn',
Expand Down Expand Up @@ -205,19 +218,24 @@ describe('AdkernelAdn adapter', function () {
it('should have request id', function () {
expect(tagRequest).to.have.property('id');
});

it('should have transaction id', function () {
expect(tagRequest).to.have.property('tid');
});

it('should have sizes', function () {
expect(tagRequest.imp[0].banner).to.have.property('format');
expect(tagRequest.imp[0].banner.format).to.be.eql(['300x250', '300x200']);
});

it('should have impression id', function () {
expect(tagRequest.imp[0]).to.have.property('id', 'bidid_1');
});

it('should have tagid', function () {
expect(tagRequest.imp[0]).to.have.property('tagid', 'ad-unit-1');
});

it('should create proper site block', function () {
expect(tagRequest.site).to.have.property('page', 'https://example.com/index.html');
expect(tagRequest.site).to.have.property('secure', 1);
Expand Down Expand Up @@ -256,16 +274,19 @@ describe('AdkernelAdn adapter', function () {
expect(tagRequest.imp[0]).to.have.property('video');
expect(tagRequest.imp[1]).to.have.property('video');
});

it('should have tagid', () => {
expect(tagRequest.imp[0]).to.have.property('tagid', 'video_wrapper');
expect(tagRequest.imp[1]).to.have.property('tagid', 'video_wrapper2');
});

it('should have size', () => {
expect(tagRequest.imp[0].video).to.have.property('w', 640);
expect(tagRequest.imp[0].video).to.have.property('h', 300);
expect(tagRequest.imp[1].video).to.have.property('w', 1920);
expect(tagRequest.imp[1].video).to.have.property('h', 1080);
});

it('should have video params', () => {
expect(tagRequest.imp[0].video).to.have.property('mimes');
expect(tagRequest.imp[0].video.mimes).to.be.eql(['video/mp4', 'video/webm']);
Expand All @@ -276,6 +297,21 @@ describe('AdkernelAdn adapter', function () {
});
});

describe('multiformat request building', function () {
let [_, tagRequests] = buildRequest([bid_multiformat]);

it('should contain single request', function () {
expect(tagRequests).to.have.length(1);
expect(tagRequests[0].imp).to.have.length(1);
});

it('should contain banner-only impression', function () {
expect(tagRequests[0].imp).to.have.length(1);
expect(tagRequests[0].imp[0]).to.have.property('banner');
expect(tagRequests[0].imp[0]).to.not.have.property('video');
});
});

describe('requests routing', function () {
it('should issue a request for each publisher', function () {
let [pbRequests, tagRequests] = buildRequest([bid1_pub1, bid_video1]);
Expand All @@ -285,6 +321,7 @@ describe('AdkernelAdn adapter', function () {
expect(tagRequests[0].imp).to.have.length(1);
expect(tagRequests[1].imp).to.have.length(1);
});

it('should issue a request for each host', function () {
let [pbRequests, tagRequests] = buildRequest([bid1_pub1, bid1_pub2]);
expect(pbRequests).to.have.length(2);
Expand All @@ -297,12 +334,15 @@ describe('AdkernelAdn adapter', function () {

describe('responses processing', function () {
let responses;

before(function () {
responses = spec.interpretResponse({body: response});
});

it('should parse all responses', function () {
expect(responses).to.have.length(3);
});

it('should return fully-initialized bid-response', function () {
let resp = responses[0];
expect(resp).to.have.property('bidderCode', 'adkernelAdn');
Expand All @@ -317,6 +357,7 @@ describe('AdkernelAdn adapter', function () {
expect(resp).to.have.property('ad');
expect(resp.ad).to.have.string('<!-- tag goes here -->');
});

it('should return fully-initialized video bid-response', function () {
let resp = responses[2];
expect(resp).to.have.property('bidderCode', 'adkernelAdn');
Expand All @@ -329,6 +370,7 @@ describe('AdkernelAdn adapter', function () {
expect(resp).to.have.property('vastUrl', 'http://vast.com/vast.xml');
expect(resp).to.not.have.property('ad');
});

it('should perform usersync', function () {
let syncs = spec.getUserSyncs({iframeEnabled: false}, [{body: response}]);
expect(syncs).to.have.length(0);
Expand All @@ -337,11 +379,13 @@ describe('AdkernelAdn adapter', function () {
expect(syncs[0]).to.have.property('type', 'iframe');
expect(syncs[0]).to.have.property('url', 'https://dsp.adkernel.com/sync');
});

it('should handle user-sync only response', function () {
let [pbRequests, tagRequests] = buildRequest([bid1_pub1]);
let resp = spec.interpretResponse({body: usersyncOnlyResponse}, pbRequests[0]);
expect(resp).to.have.length(0);
});

it('shouldn\' fail on empty response', function () {
let syncs = spec.getUserSyncs({iframeEnabled: true}, [{body: ''}]);
expect(syncs).to.have.length(0);
Expand Down

0 comments on commit 6912365

Please sign in to comment.