diff --git a/modules/telariaBidAdapter.js b/modules/telariaBidAdapter.js index e59ed6cd0f6..7bbd7573307 100644 --- a/modules/telariaBidAdapter.js +++ b/modules/telariaBidAdapter.js @@ -1,7 +1,6 @@ import * as utils from 'src/utils'; import * as bidfactory from 'src/bidfactory'; import {registerBidder} from 'src/adapters/bidderFactory'; -import {config} from 'src/config'; import {VIDEO} from '../src/mediaTypes'; import {STATUS} from 'src/constants'; @@ -24,17 +23,18 @@ export const spec = { /** * Make a server request from the list of BidRequests. * @param validBidRequests list of valid bid requests that have passed isBidRequestValid check + * @param bidderRequest * @returns {Array} of url objects */ - buildRequests: function (validBidRequests) { + buildRequests: function (validBidRequests, bidderRequest) { let requests = []; validBidRequests.forEach(bid => { - let url = generateUrl(bid); + let url = generateUrl(bid, bidderRequest); if (url) { requests.push({ method: 'GET', - url: generateUrl(bid), + url: generateUrl(bid, bidderRequest), bidId: bid.bidId, vastUrl: url.split('&fmt=json')[0] }); @@ -84,7 +84,7 @@ export const spec = { utils.logError(errorMessage); } else if (bidResult.seatbid && bidResult.seatbid.length > 0) { bidResult.seatbid[0].bid.forEach(tag => { - bids.push(createBid(STATUS.GOOD, bidderRequest, tag, width, height, bidResult.seatbid[0].seat)); + bids.push(createBid(STATUS.GOOD, bidderRequest, tag, width, height, bidResult.seatbid[0].seat.toLowerCase())); }); } @@ -112,28 +112,36 @@ export const spec = { * Generates the url based on the parameters given. Sizes, supplyCode & adCode are required. * The format is: [L,W] or [[L1,W1],...] * @param bid + * @param bidderRequest * @returns {string} */ -function generateUrl(bid) { - let width, height; - if (!bid.sizes) { - return ''; +function generateUrl(bid, bidderRequest) { + let playerSize = (bid.mediaTypes && bid.mediaTypes.video && bid.mediaTypes.video.playerSize); + if (!playerSize) { + utils.logWarn('Although player size isn\'t required it is highly recommended'); } - if (utils.isArray(bid.sizes) && (bid.sizes.length === 2) && (!isNaN(bid.sizes[0]) && !isNaN(bid.sizes[1]))) { - width = bid.sizes[0]; - height = bid.sizes[1]; - } else if (typeof bid.sizes === 'object') { - // take the primary (first) size from the array - width = bid.sizes[0][0]; - height = bid.sizes[0][1]; + let width, height; + if (playerSize) { + if (utils.isArray(playerSize) && (playerSize.length === 2) && (!isNaN(playerSize[0]) && !isNaN(playerSize[1]))) { + width = playerSize[0]; + height = playerSize[1]; + } else if (typeof playerSize === 'object') { + width = playerSize[0][0]; + height = playerSize[0][1]; + } } - if (width && height && bid.params.supplyCode && bid.params.adCode) { + + if (bid.params.supplyCode && bid.params.adCode) { let scheme = ((document.location.protocol === 'https:') ? 'https' : 'http') + '://'; let url = scheme + bid.params.supplyCode + ENDPOINT + '?adCode=' + bid.params.adCode; - url += ('&playerWidth=' + width); - url += ('&playerHeight=' + height); + if (width) { + url += ('&playerWidth=' + width); + } + if (height) { + url += ('&playerHeight=' + height); + } for (let key in bid.params) { if (bid.params.hasOwnProperty(key) && bid.params[key]) { @@ -145,8 +153,8 @@ function generateUrl(bid) { url += ('&srcPageUrl=' + encodeURIComponent(document.location.href)); } - url += ('&transactionId=' + bid.transactionId); - url += ('&referrer=' + config.getConfig('pageUrl') || utils.getTopWindowUrl()); + url += ('&transactionId=' + bid.transactionId + '&hb=1'); + url += ('&referrer=' + encodeURIComponent(bidderRequest.refererInfo.referer)); return (url + '&fmt=json'); } diff --git a/test/spec/modules/telariaBidAdapter_spec.js b/test/spec/modules/telariaBidAdapter_spec.js index 6b5278c20ae..88b61844ea4 100644 --- a/test/spec/modules/telariaBidAdapter_spec.js +++ b/test/spec/modules/telariaBidAdapter_spec.js @@ -8,7 +8,12 @@ const SUPPLY_CODE = 'ssp-demo-rm6rh'; const SIZES = [640, 480]; const REQUEST = { 'code': 'video1', - 'sizes': [640, 480], + 'mediaTypes': { + 'video': { + 'playerSize': [[640, 480]], + 'context': 'instream' + } + }, 'mediaType': 'video', 'bids': [{ 'bidder': 'tremor', @@ -19,6 +24,12 @@ const REQUEST = { }] }; +const BIDDER_REQUEST = { + 'refererInfo': { + 'referer': 'www.test.com' + } +}; + const RESPONSE = { 'cur': 'USD', 'id': '3dba13e35f3d42f998bc7e65fd871889', @@ -34,26 +45,26 @@ const RESPONSE = { }] }; -describe('TelariaAdapter', function () { +describe('TelariaAdapter', () => { const adapter = newBidder(spec); - describe('inherited functions', function () { - it('exists and is a function', function () { + describe('inherited functions', () => { + it('exists and is a function', () => { expect(adapter.callBids).to.exist.and.to.be.a('function'); }); }); - describe('isBidRequestValid', function () { + describe('isBidRequestValid', () => { let bid = REQUEST.bids[0]; - it('should return true when required params found', function () { + it('should return true when required params found', () => { let tempBid = bid; tempBid.params.adCode = 'ssp-!demo!-lufip'; tempBid.params.supplyCode = 'ssp-demo-rm6rh'; expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should return true when required params found', function () { + it('should return true when required params found', () => { let tempBid = bid; delete tempBid.params; tempBid.params = { @@ -64,17 +75,22 @@ describe('TelariaAdapter', function () { expect(spec.isBidRequestValid(tempBid)).to.equal(true); }); - it('should return false when required params are not passed', function () { + it('should return false when required params are not passed', () => { let tempBid = bid; tempBid.params = {}; expect(spec.isBidRequestValid(tempBid)).to.equal(false); }); }); - describe('buildRequests', function () { + describe('buildRequests', () => { const stub = [{ + mediaTypes: { + video: { + playerSize: [[640, 480]], + context: 'instream' + } + }, bidder: 'tremor', - sizes: [[300, 250], [300, 600]], params: { supplyCode: 'ssp-demo-rm6rh', adCode: 'ssp-!demo!-lufip', @@ -82,17 +98,17 @@ describe('TelariaAdapter', function () { } }]; - it('exists and is a function', function () { + it('exists and is a function', () => { expect(spec.buildRequests).to.exist.and.to.be.a('function'); }); - it('requires supply code, ad code and sizes to make a request', function () { - const tempRequest = spec.buildRequests(stub); + it('requires supply code & ad code to make a request', () => { + const tempRequest = spec.buildRequests(stub, BIDDER_REQUEST); expect(tempRequest.length).to.equal(1); }); - it('generates an array of requests with 4 params, method, url, bidId and vastUrl', function () { - const tempRequest = spec.buildRequests(stub); + it('generates an array of requests with 4 params, method, url, bidId and vastUrl', () => { + const tempRequest = spec.buildRequests(stub, BIDDER_REQUEST); expect(tempRequest.length).to.equal(1); expect(tempRequest[0].method).to.equal('GET'); @@ -101,36 +117,44 @@ describe('TelariaAdapter', function () { expect(tempRequest[0].vastUrl).to.exist; }); - it('requires sizes to make a request', function () { + it('doesn\'t require player size but is highly recommended', () => { let tempBid = stub; - tempBid[0].sizes = null; - const tempRequest = spec.buildRequests(tempBid); + tempBid[0].mediaTypes.video.playerSize = null; + const tempRequest = spec.buildRequests(tempBid, BIDDER_REQUEST); - expect(tempRequest.length).to.equal(0); + expect(tempRequest.length).to.equal(1); }); - it('generates a valid request with sizes as an array of two elements', function () { + it('generates a valid request with sizes as an array of two elements', () => { let tempBid = stub; - tempBid[0].sizes = [640, 480]; - expect(spec.buildRequests(tempBid).length).to.equal(1); + tempBid[0].mediaTypes.video.playerSize = [640, 480]; + tempBid[0].params.adCode = 'ssp-!demo!-lufip'; + tempBid[0].params.supplyCode = 'ssp-demo-rm6rh'; + let builtRequests = spec.buildRequests(tempBid, BIDDER_REQUEST); + expect(builtRequests.length).to.equal(1); }); - it('requires ad code and supply code to make a request', function () { + it('requires ad code and supply code to make a request', () => { let tempBid = stub; tempBid[0].params.adCode = null; tempBid[0].params.supplyCode = null; - const tempRequest = spec.buildRequests(tempBid); + const tempRequest = spec.buildRequests(tempBid, BIDDER_REQUEST); expect(tempRequest.length).to.equal(0); }); }); - describe('interpretResponse', function () { + describe('interpretResponse', () => { const responseStub = RESPONSE; const stub = [{ + mediaTypes: { + video: { + playerSize: [[640, 480]], + context: 'instream' + } + }, bidder: 'tremor', - sizes: [[300, 250], [300, 600]], params: { supplyCode: 'ssp-demo-rm6rh', adCode: 'ssp-!demo!-lufip', @@ -138,40 +162,40 @@ describe('TelariaAdapter', function () { } }]; - it('should get correct bid response', function () { + it('should get correct bid response', () => { let expectedResponseKeys = ['bidderCode', 'width', 'height', 'statusMessage', 'adId', 'mediaType', 'source', 'getStatusCode', 'getSize', 'requestId', 'cpm', 'creativeId', 'vastXml', 'vastUrl', 'currency', 'netRevenue', 'ttl', 'ad']; - let bidRequest = spec.buildRequests(stub)[0]; + let bidRequest = spec.buildRequests(stub, BIDDER_REQUEST)[0]; bidRequest.bidId = '1234'; let result = spec.interpretResponse({body: responseStub}, bidRequest); expect(Object.keys(result[0])).to.have.members(expectedResponseKeys); }); - it('handles nobid responses', function () { + it('handles nobid responses', () => { let tempResponse = responseStub; tempResponse.seatbid = []; - let bidRequest = spec.buildRequests(stub)[0]; + let bidRequest = spec.buildRequests(stub, BIDDER_REQUEST)[0]; bidRequest.bidId = '1234'; let result = spec.interpretResponse({body: tempResponse}, bidRequest); expect(result.length).to.equal(0); }); - it('handles invalid responses', function () { + it('handles invalid responses', () => { let result = spec.interpretResponse(null, {bbidderCode: 'telaria'}); expect(result.length).to.equal(0); }); - it('handles error responses', function () { + it('handles error responses', () => { let result = spec.interpretResponse({body: {error: 'Invalid request'}}, {bbidderCode: 'telaria'}); expect(result.length).to.equal(0); }); }); - describe('getUserSyncs', function () { + describe('getUserSyncs', () => { const responses = [{body: RESPONSE}]; responses[0].body.ext = { telaria: { @@ -182,7 +206,7 @@ describe('TelariaAdapter', function () { } }; - it('should get the correct number of sync urls', function () { + it('should get the correct number of sync urls', () => { let urls = spec.getUserSyncs({pixelEnabled: true}, responses); expect(urls.length).to.equal(2); });