diff --git a/modules/prebidServerBidAdapter/index.js b/modules/prebidServerBidAdapter/index.js index 4ac1bccaeda..e857bf1d665 100644 --- a/modules/prebidServerBidAdapter/index.js +++ b/modules/prebidServerBidAdapter/index.js @@ -495,11 +495,21 @@ const OPEN_RTB_PROTOCOL = { const imp = { id: adUnit.code, ext, secure: _s2sConfig.secure }; if (banner) { imp.banner = banner; } - if (video) { imp.video = video; } - - imps.push(imp); + if (video) { + if (video.context === 'outstream' && !adUnit.renderer) { + // Don't push oustream w/o renderer to request object. + utils.logError('Outstream bid without renderer cannot be sent to Prebid Server.'); + } else { + imp.video = video; + } + } + if (imp.banner || imp.video) { imps.push(imp); } }); + if (!imps.length) { + utils.logError('Request to Prebid Server rejected due to invalid media type(s) in adUnit.') + return; + } const request = { id: s2sBidRequest.tid, source: {tid: s2sBidRequest.tid}, @@ -626,6 +636,9 @@ const OPEN_RTB_PROTOCOL = { if (utils.deepAccess(bid, 'ext.prebid.type') === VIDEO) { bidObject.mediaType = VIDEO; + let sizes = bidRequest.sizes && bidRequest.sizes[0]; + bidObject.playerHeight = sizes[0]; + bidObject.playerWidth = sizes[1]; // try to get cache values from 'response.ext.prebid.cache' // else try 'bid.ext.prebid.targeting' as fallback @@ -721,17 +734,18 @@ export function PrebidServer() { } const request = protocolAdapter().buildRequest(s2sBidRequest, bidRequests, adUnitsWithSizes); - const requestJson = JSON.stringify(request); - - ajax( - _s2sConfig.endpoint, - { - success: response => handleResponse(response, requestedBidders, bidRequests, addBidResponse, done), - error: done - }, - requestJson, - { contentType: 'text/plain', withCredentials: true } - ); + const requestJson = request && JSON.stringify(request); + if (request && requestJson) { + ajax( + _s2sConfig.endpoint, + { + success: response => handleResponse(response, requestedBidders, bidRequests, addBidResponse, done), + error: done + }, + requestJson, + { contentType: 'text/plain', withCredentials: true } + ); + } }; /* Notify Prebid of bid responses so bids can get in the auction */ diff --git a/test/spec/modules/prebidServerBidAdapter_spec.js b/test/spec/modules/prebidServerBidAdapter_spec.js index e2a3a5b111a..9562b2f4c07 100644 --- a/test/spec/modules/prebidServerBidAdapter_spec.js +++ b/test/spec/modules/prebidServerBidAdapter_spec.js @@ -80,6 +80,69 @@ const VIDEO_REQUEST = { ] }; +const OUTSTREAM_VIDEO_REQUEST = { + 'account_id': '1', + 'tid': '437fbbf5-33f5-487a-8e16-a7112903cfe5', + 'max_bids': 1, + 'timeout_millis': 1000, + 'secure': 0, + 'url': '', + 'prebid_version': '1.4.0-pre', + 'ad_units': [ + { + 'code': 'div-gpt-ad-1460505748561-0', + 'sizes': [640, 480], + 'mediaTypes': { + 'video': { + playerSize: [[ 640, 480 ]], + context: 'outstream', + mimes: ['video/mp4'] + }, + banner: { sizes: [[300, 250]] } + }, + 'transactionId': '4ef956ad-fd83-406d-bd35-e4bb786ab86c', + 'bids': [ + { + 'bid_id': '123', + 'bidder': 'appnexus', + 'params': { 'placementId': '12349520' } + } + ] + }, + { + code: 'video1', + mediaTypes: { + video: { + playerSize: [640, 480], + context: 'outstream', + mimes: ['video/mp4'] + } + }, + bids: [ + { + bidder: 'appnexus', + params: { + placementId: 13232385, + video: { + skippable: true, + playback_method: ['auto_play_sound_off'] + } + } + } + ], + renderer: { + url: 'http://cdn.adnxs.com/renderer/video/ANOutstreamVideo.js', + render: function (bid) { + ANOutstreamVideo.renderAd({ + targetId: bid.adUnitCode, + adResponse: bid.adResponse, + }); + } + } + } + ] +}; + let BID_REQUESTS; const RESPONSE = { @@ -390,6 +453,18 @@ describe('S2S Adapter', function () { xhr.restore(); }); + it('should not add outstrean without renderer', function() { + let ortb2Config = utils.deepClone(CONFIG); + ortb2Config.endpoint = 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction' + + config.setConfig({s2sConfig: ortb2Config}); + adapter.callBids(OUTSTREAM_VIDEO_REQUEST, BID_REQUESTS, addBidResponse, done, ajax); + + const requestBid = JSON.parse(requests[0].requestBody); + expect(requestBid.imp[0].banner).to.exist; + expect(requestBid.imp[0].video).to.not.exist; + }); + it('exists and is a function', function () { expect(adapter.callBids).to.exist.and.to.be.a('function'); });