Skip to content

Commit

Permalink
ShowHeroes - schain support (prebid#5193)
Browse files Browse the repository at this point in the history
* ITDEV-4723 PrebidJS adapter support with SupplyChain module object

* ITDEV-4723 Fix tests

* ITDEV-4723 New entry point

Co-authored-by: veranevera <vera.yukhina@showheroes.com>
Co-authored-by: Elizaveta Voziyanova <44549195+h2p4x8@users.noreply.github.com>
  • Loading branch information
3 people authored and Jimmy Tu committed Jun 12, 2020
1 parent 65d957a commit dd4b990
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 13 deletions.
8 changes: 5 additions & 3 deletions modules/showheroes-bsBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { registerBidder } from '../src/adapters/bidderFactory.js';
import { VIDEO, BANNER } from '../src/mediaTypes.js';
import { loadExternalScript } from '../src/adloader.js';

const PROD_ENDPOINT = 'https://bs1.showheroes.com/api/v1/bid';
const PROD_ENDPOINT = 'https://bs.showheroes.com/api/v1/bid';
const STAGE_ENDPOINT = 'https://bid-service.stage.showheroes.com/api/v1/bid';
const PROD_PUBLISHER_TAG = 'https://static.showheroes.com/publishertag.js';
const STAGE_PUBLISHER_TAG = 'https://pubtag.stage.showheroes.com/publishertag.js';
Expand Down Expand Up @@ -38,6 +38,7 @@ export const spec = {
const isNativeRender = utils.deepAccess(validBidRequests[0], 'renderer');
const outstreamOptions = utils.deepAccess(validBidRequests[0], 'params.outstreamOptions');
const isBanner = !!validBidRequests[0].mediaTypes.banner || (isOutstream && !(isCustomRender || isNativeRender || isNodeRender));
const defaultSchain = validBidRequests[0].schain || {};

validBidRequests.forEach((bid) => {
const videoSizes = getVideoSizes(bid);
Expand Down Expand Up @@ -76,6 +77,7 @@ export const spec = {
height: size[1]
},
params: bid.params,
schain: bid.schain || defaultSchain,
};
};

Expand Down Expand Up @@ -215,7 +217,7 @@ function outstreamRender(bid) {
return;
}

const slot = utils.getBidIdParameter('slot', bid.renderer.config);
const slot = utils.getBidIdParameter('slot', bid.renderer.config) || bid.adUnitCode;
if (slot && window.document.getElementById(slot)) {
window.document.getElementById(slot).appendChild(embedCode);
} else if (slot) {
Expand Down Expand Up @@ -274,7 +276,7 @@ function getVideoSizes(bidRequest) {
}

function getBannerSizes(bidRequest) {
return formatSizes(utils.deepAccess(bidRequest, 'mediaTypes.banner.sizes') || bidRequest.sizes || []);
return formatSizes(utils.deepAccess(bidRequest, 'mediaTypes.banner.sizes') || []);
}

function formatSizes(sizes) {
Expand Down
56 changes: 46 additions & 10 deletions test/spec/modules/showheroes-bsBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,23 @@ const gdpr = {
}
}

const schain = {
'schain': {
'validation': 'strict',
'config': {
'ver': '1.0',
'complete': 1,
'nodes': [
{
'asi': 'some.com',
'sid': '00001',
'hp': 1
}
]
}
}
}

const bidRequestCommonParams = {
'bidder': 'showheroes-bs',
'params': {
Expand Down Expand Up @@ -91,8 +108,11 @@ const bidRequestBannerMultiSizes = {
}

const bidRequestVideoAndBanner = {
...bidRequestBanner,
...bidRequestVideo
...bidRequestCommonParams,
'mediaTypes': {
...bidRequestBanner.mediaTypes,
...bidRequestVideo.mediaTypes
}
}

describe('shBidAdapter', function () {
Expand Down Expand Up @@ -131,23 +151,29 @@ describe('shBidAdapter', function () {
it('check sizes formats', function () {
const request = spec.buildRequests([{
'params': {},
'mediaTypes': {},
'sizes': [[640, 480]],
'mediaTypes': {
'banner': {
'sizes': [[320, 240]]
}
},
}], bidderRequest)
const payload = request.data.requests[0];
expect(payload).to.be.an('object');
expect(payload.size).to.have.property('width', 640);
expect(payload.size).to.have.property('height', 480);
expect(payload.size).to.have.property('width', 320);
expect(payload.size).to.have.property('height', 240);

const request2 = spec.buildRequests([{
'params': {},
'mediaTypes': {},
'sizes': [320, 240],
'mediaTypes': {
'video': {
'playerSize': [640, 360]
}
},
}], bidderRequest)
const payload2 = request2.data.requests[0];
expect(payload).to.be.an('object');
expect(payload2.size).to.have.property('width', 320);
expect(payload2.size).to.have.property('height', 240);
expect(payload2.size).to.have.property('width', 640);
expect(payload2.size).to.have.property('height', 360);
})

it('should get size from mediaTypes when sizes property is empty', function () {
Expand Down Expand Up @@ -245,6 +271,16 @@ describe('shBidAdapter', function () {
expect(payload).to.be.an('object');
expect(payload.gdprConsent).to.eql(gdpr.gdprConsent)
})

it('passes schain object if present', function() {
const request = spec.buildRequests([{
...bidRequestVideo,
...schain
}], bidderRequest)
const payload = request.data.requests[0];
expect(payload).to.be.an('object');
expect(payload.schain).to.eql(schain.schain);
})
})

describe('interpretResponse', function () {
Expand Down

0 comments on commit dd4b990

Please sign in to comment.