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

Sonobi - support video and display same adunit #3325

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
12 changes: 4 additions & 8 deletions modules/sonobiBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { registerBidder } from 'src/adapters/bidderFactory';
import { getTopWindowLocation, parseSizesInput, logError, generateUUID, deepAccess, isEmpty } from '../src/utils';
import { getTopWindowLocation, parseSizesInput, logError, generateUUID, isEmpty } from '../src/utils';
import { BANNER, VIDEO } from '../src/mediaTypes';
import find from 'core-js/library/fn/array/find';
import { config } from '../src/config';

const BIDDER_CODE = 'sonobi';
Expand Down Expand Up @@ -104,12 +103,10 @@ export const spec = {
}

Object.keys(bidResponse.slots).forEach(slot => {
const bid = bidResponse.slots[slot];
const bidId = _getBidIdFromTrinityKey(slot);
const bidRequest = find(bidderRequests, bidReqest => bidReqest.bidId === bidId);
const videoMediaType = deepAccess(bidRequest, 'mediaTypes.video');
const mediaType = bidRequest.mediaType || (videoMediaType ? 'video' : null);
const mediaType = (bid.sbi_ct === 'video') ? 'video' : null;
const createCreative = _creative(mediaType);
const bid = bidResponse.slots[slot];
if (bid.sbi_aid && bid.sbi_mouse && bid.sbi_size) {
const [
width = 1,
Expand All @@ -132,8 +129,7 @@ export const spec = {
bids.dealId = bid.sbi_dozer;
}

const creativeType = bid.sbi_ct;
if (creativeType && (creativeType === 'video' || creativeType === 'outstream')) {
if (mediaType === 'video') {
bids.mediaType = 'video';
bids.vastUrl = createCreative(bidResponse.sbi_dc, bid.sbi_aid);
delete bids.ad;
Expand Down
39 changes: 33 additions & 6 deletions test/spec/modules/sonobiBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,7 @@ describe('SonobiBidAdapter', function () {
},
'adUnitCode': 'adunit-code-2',
'sizes': [[120, 600], [300, 600], [160, 600]],
'bidId': '30b31c1838de1e',
'mediaType': 'video'
'bidId': '30b31c1838de1e'
},
{
'bidder': 'sonobi',
Expand Down Expand Up @@ -274,6 +273,14 @@ describe('SonobiBidAdapter', function () {
'sbi_aid': '30292e432662bd5f86d90774b944b038',
'sbi_mouse': 1.25,
'sbi_dozer': 'dozerkey',
'sbi_ct': 'video'
},
'/7780971/sparks_prebid_LB_OUTSTREAM|30b31c1838de1g': {
'sbi_size': '300x600',
'sbi_apoc': 'remnant',
'sbi_crid': '1234abcd',
'sbi_aid': '30292e432662bd5f86d90774b944b038',
'sbi_mouse': 1.07,
},
'/7780971/sparks_prebid_LB|30b31c1838de1g': {},
},
Expand Down Expand Up @@ -313,22 +320,42 @@ describe('SonobiBidAdapter', function () {
'currency': 'USD',
'dealId': 'dozerkey',
'aid': '30292e432662bd5f86d90774b944b038'
}
},
{
'requestId': '30b31c1838de1g',
'cpm': 1.07,
'width': 300,
'height': 600,
'ad': `<script type="text/javascript" src="https://mco-1-apex.go.sonobi.com/sbi.js?aid=30292e432662bd5f86d90774b944b038&as=null&ref=http%3A%2F%2Flocalhost%2F"></script>`,
'ttl': 500,
'creativeId': '1234abcd',
'netRevenue': true,
'currency': 'USD',
'aid': '30292e432662bd5f86d90774b944b038'
},
];

it('should map bidResponse to prebidResponse', function () {
const response = spec.interpretResponse(bidResponse, bidRequests);
response.forEach((resp, i) => {
expect(resp.requestId).to.equal(prebidResponse[i].requestId);
expect(resp.cpm).to.equal(prebidResponse[i].cpm);
expect(resp.width).to.equal(prebidResponse[i].width);
expect(resp.height).to.equal(prebidResponse[i].height);

expect(resp.ttl).to.equal(prebidResponse[i].ttl);
expect(resp.creativeId).to.equal(prebidResponse[i].creativeId);
expect(resp.netRevenue).to.equal(prebidResponse[i].netRevenue);
expect(resp.currency).to.equal(prebidResponse[i].currency);
expect(resp.aid).to.equal(prebidResponse[i].aid);
expect(resp.ad.indexOf('localhost')).to.be.greaterThan(0);
if (resp.mediaType === 'video') {
expect(resp.vastUrl.indexOf('vast.xml')).to.be.greaterThan(0);
expect(resp.ad).to.be.undefined;
expect(resp.width).to.be.undefined;
expect(resp.height).to.be.undefined;
} else {
expect(resp.ad.indexOf('localhost')).to.be.greaterThan(0);
expect(resp.width).to.equal(prebidResponse[i].width);
expect(resp.height).to.equal(prebidResponse[i].height);
}
});
});
});
Expand Down