diff --git a/modules/vidazooBidAdapter.js b/modules/vidazooBidAdapter.js index b3ab8a4d275..d974c0e1eb7 100644 --- a/modules/vidazooBidAdapter.js +++ b/modules/vidazooBidAdapter.js @@ -1,6 +1,7 @@ import * as utils from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER} from '../src/mediaTypes.js'; + export const URL = 'https://prebid.cootlogix.com'; const BIDDER_CODE = 'vidazoo'; const CURRENCY = 'USD'; @@ -19,25 +20,29 @@ function isBidRequestValid(bid) { return !!(params.cId && params.pId); } -function buildRequest(bid, topWindowUrl, size, bidderRequest) { +function buildRequest(bid, topWindowUrl, sizes, bidderRequest) { const {params, bidId} = bid; const {bidFloor, cId, pId, ext} = params; - // Prebid's util function returns AppNexus style sizes (i.e. 300x250) - const [width, height] = size.split('x'); - - const dto = { - method: 'GET', - url: `${URL}/prebid/${cId}`, - data: { - url: encodeURIComponent(topWindowUrl), - cb: Date.now(), - bidFloor: bidFloor, - bidId: bidId, - publisherId: pId, - consent: bidderRequest.gdprConsent && bidderRequest.gdprConsent.consentString, - width, - height + let data = { + url: encodeURIComponent(topWindowUrl), + cb: Date.now(), + bidFloor: bidFloor, + bidId: bidId, + publisherId: pId, + sizes: sizes, + }; + if (bidderRequest.gdprConsent) { + if (bidderRequest.gdprConsent.consentString) { + data.gdprConsent = bidderRequest.gdprConsent.consentString; } + if (bidderRequest.gdprConsent.gdprApplies !== undefined) { + data.gdpr = bidderRequest.gdprConsent.gdprApplies ? 1 : 0; + } + } + const dto = { + method: 'POST', + url: `${URL}/prebid/multi/${cId}`, + data: data }; utils._each(ext, (value, key) => { @@ -52,10 +57,8 @@ function buildRequests(validBidRequests, bidderRequest) { const requests = []; validBidRequests.forEach(validBidRequest => { const sizes = utils.parseSizesInput(validBidRequest.sizes); - sizes.forEach(size => { - const request = buildRequest(validBidRequest, topWindowUrl, size, bidderRequest); - requests.push(request); - }); + const request = buildRequest(validBidRequest, topWindowUrl, sizes, bidderRequest); + requests.push(request); }); return requests; } @@ -64,23 +67,30 @@ function interpretResponse(serverResponse, request) { if (!serverResponse || !serverResponse.body) { return []; } - const {creativeId, ad, price, exp} = serverResponse.body; - if (!ad || !price) { - return []; - } - const {bidId, width, height} = request.data; + const {bidId} = request.data; + const {results} = serverResponse.body; + + let output = []; + try { - return [{ - requestId: bidId, - cpm: price, - width: width, - height: height, - creativeId: creativeId, - currency: CURRENCY, - netRevenue: true, - ttl: exp || TTL_SECONDS, - ad: ad - }]; + results.forEach(result => { + const {creativeId, ad, price, exp, width, height, currency} = result; + if (!ad || !price) { + return; + } + output.push({ + requestId: bidId, + cpm: price, + width: width, + height: height, + creativeId: creativeId, + currency: currency || CURRENCY, + netRevenue: true, + ttl: exp || TTL_SECONDS, + ad: ad + }) + }); + return output; } catch (e) { return []; } @@ -101,20 +111,18 @@ function getUserSyncs(syncOptions, responses) { const syncs = []; responses.forEach(response => { const {body} = response; - const cookies = body ? body.cookies || [] : []; - cookies.forEach(cookie => { - switch (cookie.type) { - case INTERNAL_SYNC_TYPE.IFRAME: - break; - case INTERNAL_SYNC_TYPE.IMAGE: + const results = body ? body.results || [] : []; + results.forEach(result => { + (result.cookies || []).forEach(cookie => { + if (cookie.type === INTERNAL_SYNC_TYPE.IMAGE) { if (pixelEnabled && !lookup[cookie.src]) { syncs.push({ type: EXTERNAL_SYNC_TYPE.IMAGE, url: cookie.src }); } - break; - } + } + }); }); }); return syncs; diff --git a/test/spec/modules/vidazooBidAdapter_spec.js b/test/spec/modules/vidazooBidAdapter_spec.js index 755295c7bd6..a52669b773b 100644 --- a/test/spec/modules/vidazooBidAdapter_spec.js +++ b/test/spec/modules/vidazooBidAdapter_spec.js @@ -22,7 +22,8 @@ const BID = { const BIDDER_REQUEST = { 'gdprConsent': { - 'consentString': 'consent_string' + 'consentString': 'consent_string', + 'gdprApplies': true }, 'refererInfo': { 'referer': 'https://www.greatsite.com' @@ -31,16 +32,20 @@ const BIDDER_REQUEST = { const SERVER_RESPONSE = { body: { - 'ad': '', - 'price': 0.8, - 'creativeId': '12610997325162499419', - 'exp': 30, - 'cookies': [{ - 'src': 'https://sync.com', - 'type': 'iframe' - }, { - 'src': 'https://sync.com', - 'type': 'img' + results: [{ + 'ad': '', + 'price': 0.8, + 'creativeId': '12610997325162499419', + 'exp': 30, + 'width': 300, + 'height': 250, + 'cookies': [{ + 'src': 'https://sync.com', + 'type': 'iframe' + }, { + 'src': 'https://sync.com', + 'type': 'img' + }] }] } }; @@ -119,30 +124,14 @@ describe('VidazooBidAdapter', function () { it('should build request for each size', function () { const requests = adapter.buildRequests([BID], BIDDER_REQUEST); - expect(requests).to.have.length(2); + expect(requests).to.have.length(1); expect(requests[0]).to.deep.equal({ - method: 'GET', - url: `${URL}/prebid/59db6b3b4ffaa70004f45cdc`, + method: 'POST', + url: `${URL}/prebid/multi/59db6b3b4ffaa70004f45cdc`, data: { - consent: 'consent_string', - width: '300', - height: '250', - url: 'https%3A%2F%2Fwww.greatsite.com', - cb: 1000, - bidFloor: 0.1, - bidId: '2d52001cabd527', - publisherId: '59ac17c192832d0011283fe3', - 'ext.param1': 'loremipsum', - 'ext.param2': 'dolorsitamet', - } - }); - expect(requests[1]).to.deep.equal({ - method: 'GET', - url: `${URL}/prebid/59db6b3b4ffaa70004f45cdc`, - data: { - consent: 'consent_string', - width: '300', - height: '600', + gdprConsent: 'consent_string', + gdpr: 1, + sizes: ['300x250', '300x600'], url: 'https%3A%2F%2Fwww.greatsite.com', cb: 1000, bidFloor: 0.1, @@ -158,6 +147,25 @@ describe('VidazooBidAdapter', function () { sandbox.restore(); }); }); + describe('getUserSyncs', function () { + it('should have valid user sync with iframeEnabled', function () { + const result = adapter.getUserSyncs({iframeEnabled: true}, [SERVER_RESPONSE]); + + expect(result).to.deep.equal([{ + type: 'iframe', + url: 'https://static.cootlogix.com/basev/sync/user_sync.html' + }]); + }); + + it('should have valid user sync with pixelEnabled', function () { + const result = adapter.getUserSyncs({pixelEnabled: true}, [SERVER_RESPONSE]); + + expect(result).to.deep.equal([{ + 'url': 'https://sync.com', + 'type': 'image' + }]); + }) + }); describe('interpret response', function () { it('should return empty array when there is no response', function () { @@ -193,7 +201,7 @@ describe('VidazooBidAdapter', function () { it('should take default TTL', function () { const serverResponse = utils.deepClone(SERVER_RESPONSE); - delete serverResponse.body.exp; + delete serverResponse.body.results[0].exp; const responses = adapter.interpretResponse(serverResponse, REQUEST); expect(responses).to.have.length(1); expect(responses[0].ttl).to.equal(300);