From 6c715ab226c884ea6c122fed94c969eff79e4dd1 Mon Sep 17 00:00:00 2001 From: Valentin Souche Date: Mon, 7 Jan 2019 17:29:07 +0100 Subject: [PATCH 1/3] Teads adapter: handle playerSize --- modules/teadsBidAdapter.js | 19 ++++++- test/spec/modules/teadsBidAdapter_spec.js | 66 +++++++++++++++++++---- 2 files changed, 73 insertions(+), 12 deletions(-) diff --git a/modules/teadsBidAdapter.js b/modules/teadsBidAdapter.js index e8dbe4e1c6b..af74ea820ec 100644 --- a/modules/teadsBidAdapter.js +++ b/modules/teadsBidAdapter.js @@ -116,7 +116,7 @@ function buildRequestObject(bid) { let placementId = utils.getValue(bid.params, 'placementId'); let pageId = utils.getValue(bid.params, 'pageId'); - reqObj.sizes = utils.parseSizesInput(bid.sizes); + reqObj.sizes = getSizes(bid); reqObj.bidId = utils.getBidIdParameter('bidId', bid); reqObj.bidderRequestId = utils.getBidIdParameter('bidderRequestId', bid); reqObj.placementId = parseInt(placementId, 10); @@ -127,6 +127,23 @@ function buildRequestObject(bid) { return reqObj; } +function getSizes(bid) { + let sizes; + if (isVideoBid(bid)) { + sizes = utils.deepAccess(bid, 'mediaTypes.video.playerSize') || + utils.deepAccess(bid, 'mediaTypes.video.sizes') || + bid.sizes; + } else { + sizes = utils.deepAccess(bid, 'mediaTypes.banner.sizes') || bid.sizes; + } + + return utils.parseSizesInput(sizes); +} + +function isVideoBid(bid) { + return bid.mediaType === 'video' || utils.deepAccess(bid, 'mediaTypes.video'); +} + function _validateId(id) { return (parseInt(id) > 0); } diff --git a/test/spec/modules/teadsBidAdapter_spec.js b/test/spec/modules/teadsBidAdapter_spec.js index ab34c600a53..333aafd3903 100644 --- a/test/spec/modules/teadsBidAdapter_spec.js +++ b/test/spec/modules/teadsBidAdapter_spec.js @@ -3,7 +3,7 @@ import {spec} from 'modules/teadsBidAdapter'; import {newBidder} from 'src/adapters/bidderFactory'; const ENDPOINT = '//a.teads.tv/hb/bid-request'; -const AD_SCRIPT = '"'; +const AD_SCRIPT = '"'; describe('teadsBidAdapter', function() { const adapter = newBidder(spec); @@ -96,13 +96,14 @@ describe('teadsBidAdapter', function() { } ]; + let bidderResquestDefault = { + 'auctionId': '1d1a030790a475', + 'bidderRequestId': '22edbae2733bf6', + 'timeout': 3000 + }; + it('sends bid request to ENDPOINT via POST', function() { - let bidderRequest = { - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000 - }; - const request = spec.buildRequests(bidRequests, bidderRequest); + const request = spec.buildRequests(bidRequests, bidderResquestDefault); expect(request.url).to.equal(ENDPOINT); expect(request.method).to.equal('POST'); @@ -129,7 +130,7 @@ describe('teadsBidAdapter', function() { expect(payload.gdpr_iab).to.exist; expect(payload.gdpr_iab.consent).to.equal(consentString); expect(payload.gdpr_iab.status).to.equal(12); - }) + }); it('should send GDPR to endpoint with 11 status', function() { let consentString = 'JRJ8RKfDeBNsERRDCSAAZ+A=='; @@ -152,7 +153,7 @@ describe('teadsBidAdapter', function() { expect(payload.gdpr_iab).to.exist; expect(payload.gdpr_iab.consent).to.equal(consentString); expect(payload.gdpr_iab.status).to.equal(11); - }) + }); it('should send GDPR to endpoint with 22 status', function() { let consentString = 'JRJ8RKfDeBNsERRDCSAAZ+A=='; @@ -173,7 +174,7 @@ describe('teadsBidAdapter', function() { expect(payload.gdpr_iab).to.exist; expect(payload.gdpr_iab.consent).to.equal(''); expect(payload.gdpr_iab.status).to.equal(22); - }) + }); it('should send GDPR to endpoint with 0 status', function() { let consentString = 'JRJ8RKfDeBNsERRDCSAAZ+A=='; @@ -196,7 +197,50 @@ describe('teadsBidAdapter', function() { expect(payload.gdpr_iab).to.exist; expect(payload.gdpr_iab.consent).to.equal(consentString); expect(payload.gdpr_iab.status).to.equal(0); - }) + }); + + it('should use good mediaTypes video playerSizes', function() { + const mediaTypesPlayerSize = { + 'mediaTypes': { + 'video': { + 'playerSize': [32, 34] + } + } + }; + checkMediaTypesSizes(mediaTypesPlayerSize, '32x34') + }); + + it('should use good mediaTypes video sizes', function() { + const mediaTypesVideoSizes = { + 'mediaTypes': { + 'video': { + 'sizes': [12, 14] + } + } + }; + checkMediaTypesSizes(mediaTypesVideoSizes, '12x14') + }); + + it('should use good mediaTypes banner sizes', function() { + const mediaTypesBannerSize = { + 'mediaTypes': { + 'banner': { + 'sizes': [46, 48] + } + } + }; + checkMediaTypesSizes(mediaTypesBannerSize, '46x48') + }); + + function checkMediaTypesSizes(mediaTypes, expectedSizes) { + const bidRequestWithBannerSizes = Object.assign(bidRequests[0], mediaTypes); + const requestWithBannerSizes = spec.buildRequests([bidRequestWithBannerSizes], bidderResquestDefault); + const payloadWithBannerSizes = JSON.parse(requestWithBannerSizes.data); + + return payloadWithBannerSizes.data.forEach(bid => { + expect(bid.sizes[0]).to.equal(expectedSizes); + }); + } }); describe('interpretResponse', function() { From e189b643bfac6d436b9115e2498e3ba8a7686add Mon Sep 17 00:00:00 2001 From: Valentin Souche Date: Mon, 14 Jan 2019 18:18:21 +0100 Subject: [PATCH 2/3] Handle multiple mediatypes sizes --- modules/teadsBidAdapter.js | 34 ++++++++++++++++++++++- test/spec/modules/teadsBidAdapter_spec.js | 20 ++++++++++++- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/modules/teadsBidAdapter.js b/modules/teadsBidAdapter.js index af74ea820ec..63b5ed50690 100644 --- a/modules/teadsBidAdapter.js +++ b/modules/teadsBidAdapter.js @@ -129,7 +129,9 @@ function buildRequestObject(bid) { function getSizes(bid) { let sizes; - if (isVideoBid(bid)) { + if (isHybridBid(bid)) { + sizes = concatHybridBidSizes(bid); + } else if (isVideoBid(bid)) { sizes = utils.deepAccess(bid, 'mediaTypes.video.playerSize') || utils.deepAccess(bid, 'mediaTypes.video.sizes') || bid.sizes; @@ -144,6 +146,36 @@ function isVideoBid(bid) { return bid.mediaType === 'video' || utils.deepAccess(bid, 'mediaTypes.video'); } +function isHybridBid(bid) { + return isVideoBid(bid) && utils.deepAccess(bid, 'mediaTypes.banner'); +} + +function concatHybridBidSizes(bid) { + let playerSize = utils.deepAccess(bid, 'mediaTypes.video.playerSize'); + let videoSizes = utils.deepAccess(bid, 'mediaTypes.video.sizes'); + let bannerSizes = utils.deepAccess(bid, 'mediaTypes.banner.sizes'); + let sizes; + + if (utils.isArray(bannerSizes) || utils.isArray(playerSize) || utils.isArray(videoSizes)) { + let mediaTypesSizes = [bannerSizes, videoSizes, playerSize]; + sizes = mediaTypesSizes + .reduce(function(acc, currSize) { + if (utils.isArray(currSize)) { + if (utils.isArray(currSize[0])) { + currSize.forEach(function (childSize) { acc.push(childSize) }) + } else { + acc.push(currSize); + } + } + return acc; + }, []) + } else { + sizes = bid.sizes; + } + + return sizes; +} + function _validateId(id) { return (parseInt(id) > 0); } diff --git a/test/spec/modules/teadsBidAdapter_spec.js b/test/spec/modules/teadsBidAdapter_spec.js index 333aafd3903..20fdbe947c0 100644 --- a/test/spec/modules/teadsBidAdapter_spec.js +++ b/test/spec/modules/teadsBidAdapter_spec.js @@ -232,13 +232,31 @@ describe('teadsBidAdapter', function() { checkMediaTypesSizes(mediaTypesBannerSize, '46x48') }); + it('should use good mediaTypes for both video and banner sizes', function() { + const hybridMediaTypes = { + 'mediaTypes': { + 'banner': { + 'sizes': [46, 48] + }, + 'video': { + 'sizes': [[50, 34], [45, 45]] + } + } + }; + checkMediaTypesSizes(hybridMediaTypes, ['46x48', '50x34', '45x45']) + }); + function checkMediaTypesSizes(mediaTypes, expectedSizes) { const bidRequestWithBannerSizes = Object.assign(bidRequests[0], mediaTypes); const requestWithBannerSizes = spec.buildRequests([bidRequestWithBannerSizes], bidderResquestDefault); const payloadWithBannerSizes = JSON.parse(requestWithBannerSizes.data); return payloadWithBannerSizes.data.forEach(bid => { - expect(bid.sizes[0]).to.equal(expectedSizes); + if (Array.isArray(expectedSizes)) { + expect(JSON.stringify(bid.sizes)).to.equal(JSON.stringify(expectedSizes)); + } else { + expect(bid.sizes[0]).to.equal(expectedSizes); + } }); } }); From 9cd8787a7f63e2be501de829d92b51875ffaadc1 Mon Sep 17 00:00:00 2001 From: Valentin Souche Date: Tue, 15 Jan 2019 10:49:12 +0100 Subject: [PATCH 3/3] Clean sizes logic --- modules/teadsBidAdapter.js | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/modules/teadsBidAdapter.js b/modules/teadsBidAdapter.js index 63b5ed50690..96855e56882 100644 --- a/modules/teadsBidAdapter.js +++ b/modules/teadsBidAdapter.js @@ -128,37 +128,17 @@ function buildRequestObject(bid) { } function getSizes(bid) { - let sizes; - if (isHybridBid(bid)) { - sizes = concatHybridBidSizes(bid); - } else if (isVideoBid(bid)) { - sizes = utils.deepAccess(bid, 'mediaTypes.video.playerSize') || - utils.deepAccess(bid, 'mediaTypes.video.sizes') || - bid.sizes; - } else { - sizes = utils.deepAccess(bid, 'mediaTypes.banner.sizes') || bid.sizes; - } - - return utils.parseSizesInput(sizes); -} - -function isVideoBid(bid) { - return bid.mediaType === 'video' || utils.deepAccess(bid, 'mediaTypes.video'); -} - -function isHybridBid(bid) { - return isVideoBid(bid) && utils.deepAccess(bid, 'mediaTypes.banner'); + return utils.parseSizesInput(concatSizes(bid)); } -function concatHybridBidSizes(bid) { +function concatSizes(bid) { let playerSize = utils.deepAccess(bid, 'mediaTypes.video.playerSize'); let videoSizes = utils.deepAccess(bid, 'mediaTypes.video.sizes'); let bannerSizes = utils.deepAccess(bid, 'mediaTypes.banner.sizes'); - let sizes; if (utils.isArray(bannerSizes) || utils.isArray(playerSize) || utils.isArray(videoSizes)) { let mediaTypesSizes = [bannerSizes, videoSizes, playerSize]; - sizes = mediaTypesSizes + return mediaTypesSizes .reduce(function(acc, currSize) { if (utils.isArray(currSize)) { if (utils.isArray(currSize[0])) { @@ -170,10 +150,8 @@ function concatHybridBidSizes(bid) { return acc; }, []) } else { - sizes = bid.sizes; + return bid.sizes; } - - return sizes; } function _validateId(id) {