From 2c5f61571aafe961d5fa902cbbf911b06bbfe45a Mon Sep 17 00:00:00 2001 From: Marcian123 Date: Tue, 29 May 2018 16:28:05 +0200 Subject: [PATCH 1/7] Add files via upload --- rtbhouseBidAdapter.js | 125 ++++++++++++++++++++++++++++ rtbhouseBidAdapter_spec.js | 162 +++++++++++++++++++++++++++++++++++++ 2 files changed, 287 insertions(+) create mode 100644 rtbhouseBidAdapter.js create mode 100644 rtbhouseBidAdapter_spec.js diff --git a/rtbhouseBidAdapter.js b/rtbhouseBidAdapter.js new file mode 100644 index 00000000000..0ee5c42b368 --- /dev/null +++ b/rtbhouseBidAdapter.js @@ -0,0 +1,125 @@ +import * as utils from 'src/utils'; +import { BANNER } from 'src/mediaTypes'; +import { registerBidder } from 'src/adapters/bidderFactory'; +import includes from 'core-js/library/fn/array/includes'; + +const BIDDER_CODE = 'rtbhouse'; +const REGIONS = ['prebid-eu', 'prebid-us', 'prebid-asia']; +const ENDPOINT_URL = 'creativecdn.com/bidder/prebid/bids'; +const DEFAULT_CURRENCY_ARR = ['USD']; // NOTE - USD is the only supported currency right now; Hardcoded for bids + +/** + * Helpers + */ + +function buildEndpointUrl(region) { + return 'https://' + region + '.' + ENDPOINT_URL; +} + +/** + * Produces an OpenRTBImpression from a slot config. + */ +function mapImpression(slot) { + return { + id: slot.bidId, + banner: mapBanner(slot), + tagid: slot.adUnitCode.toString(), + }; +} + +/** + * Produces an OpenRTB Banner object for the slot given. + */ +function mapBanner(slot) { + return { + w: slot.sizes[0][0], + h: slot.sizes[0][1], + format: mapSizes(slot.sizes) + }; +} + +/** + * Produce openRTB banner.format object + */ +function mapSizes(slot_sizes) { + const format = []; + slot_sizes.forEach(elem => { + format.push({ + w: elem[0], + h: elem[1] + }); + }); + return format; +} + +/** + * Produces an OpenRTB site object. + */ +function mapSite(validRequest) { + const pubId = validRequest && validRequest.length > 0 ? validRequest[0].params.publisherId : 'unknown'; + return { + publisher: { + id: pubId.toString(), + }, + page: utils.getTopWindowUrl(), + name: utils.getOrigin() + } +} + +export const spec = { + code: BIDDER_CODE, + supportedMediaTypes: [BANNER], + + isBidRequestValid: function (bid) { + return !!(includes(REGIONS, bid.params.region) && bid.params.publisherId); + }, + buildRequests: function (validBidRequests) { + const request = { + id: validBidRequests[0].auctionId, + imp: validBidRequests.map(slot => mapImpression(slot)), + site: mapSite(validBidRequests), + cur: DEFAULT_CURRENCY_ARR, + test: validBidRequests[0].params.test || 0, + }; + if (validBidRequests[0].gdprConsent && validBidRequests[0].gdprConsent.gdprApplies) { + const consentStr = (validBidRequests[0].gdprConsent.consentString) + ? validBidRequests[0].gdprConsent.consentString.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '') : ''; + const gdpr = validBidRequests[0].gdprConsent.gdprApplies ? 1 : 0; + request.regs = {ext: {gdpr: gdpr}}; + request.user = {ext: {consent: consentStr}}; + }; + + return { + method: 'POST', + url: buildEndpointUrl(validBidRequests[0].params.region), + data: JSON.stringify(request) + }; + }, + interpretResponse: function (serverResponse, originalRequest) { + serverResponse = serverResponse.body; + const bids = []; + + if (utils.isArray(serverResponse)) { + serverResponse.forEach(serverBid => { + if (serverBid.price !== 0) { + const bid = { + requestId: serverBid.impid, + mediaType: BANNER, + cpm: serverBid.price, + creativeId: serverBid.adid, + ad: serverBid.adm, + width: serverBid.w, + height: serverBid.h, + ttl: 55, + netRevenue: true, + currency: 'USD' + }; + bids.push(bid); + } + }); + } + return bids; + } +}; + +registerBidder(spec); diff --git a/rtbhouseBidAdapter_spec.js b/rtbhouseBidAdapter_spec.js new file mode 100644 index 00000000000..9304e50e908 --- /dev/null +++ b/rtbhouseBidAdapter_spec.js @@ -0,0 +1,162 @@ +import { expect } from 'chai'; +import { spec } from 'modules/rtbhouseBidAdapter'; +import { newBidder } from 'src/adapters/bidderFactory'; + +const REGIONS = ['prebid-eu', 'prebid-us', 'prebid-asia']; +const ENDPOINT_URL = 'creativecdn.com/bidder/prebid/bids'; +const consentStr = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='; +/** + * Helpers + */ + +function buildEndpointUrl(region) { + return 'https://' + region + '.' + ENDPOINT_URL; +} + +/** + * endof Helpers + */ + +describe('RTBHouseAdapter', () => { + const adapter = newBidder(spec); + + describe('inherited functions', () => { + it('exists and is a function', () => { + expect(adapter.callBids).to.exist.and.to.be.a('function'); + }); + }); + + describe('isBidRequestValid', () => { + let bid = { + 'bidder': 'rtbhouse', + 'params': { + 'publisherId': 'PREBID_TEST', + 'region': 'prebid-eu' + }, + 'adUnitCode': 'adunit-code', + 'sizes': [[300, 250], [300, 600]], + 'bidId': '30b31c1838de1e', + 'bidderRequestId': '22edbae2733bf6', + 'auctionId': '1d1a030790a475' + }; + + it('should return true when required params found', () => { + expect(spec.isBidRequestValid(bid)).to.equal(true); + }); + + it('should return false when required params are not passed', () => { + let bid = Object.assign({}, bid); + delete bid.params; + bid.params = { + 'someIncorrectParam': 0 + }; + expect(spec.isBidRequestValid(bid)).to.equal(false); + }); + }); + + describe('buildRequests', () => { + let bidRequests = [ + { + 'bidder': 'rtbhouse', + 'params': { + 'publisherId': 'PREBID_TEST', + 'region': 'prebid-eu', + 'test': 1 + }, + 'adUnitCode': 'adunit-code', + 'sizes': [[300, 250], [300, 600]], + 'bidId': '30b31c1838de1e', + 'bidderRequestId': '22edbae2733bf6', + 'auctionId': '1d1a030790a475' + } + ]; + + it('should build test param into the request', () => { + let builtTestRequest = spec.buildRequests(bidRequests).data; + expect(JSON.parse(builtTestRequest).test).to.equal(1); + }); + + it('sends bid request to ENDPOINT via POST', () => { + let bidRequest = Object.assign([], bidRequests); + delete bidRequest[0].params.test; + const request = spec.buildRequests(bidRequest); + expect(request.url).to.equal(buildEndpointUrl(bidRequest[0].params.region)); + expect(request.method).to.equal('POST'); + }); + + it('should not populate GDPR if for non-EEA users', () => { + let bidRequest = Object.assign([], bidRequests); + delete bidRequest[0].params.test; + const request = spec.buildRequests(bidRequest); + let data = JSON.parse(request.data); + expect(data).to.not.have.property('regs'); + expect(data).to.not.have.property('user'); + }); + + it('should populate GDPR and consent string if available for EEA users', () => { + let bidRequest = Object.assign([], bidRequests); + bidRequests[0].gdprConsent = { + 'consentString': consentStr, + 'gdprApplies': true + }; + delete bidRequest[0].params.test; + const request = spec.buildRequests(bidRequest); + let data = JSON.parse(request.data); + expect(data.regs.ext.gdpr).to.equal(1); + expect(data.user.ext.consent).to.equal('BOJ8RZsOJ8RZsABAB8AAAAAZ-A'); + }); + + it('should populate GDPR and empty consent string if available for EEA users without consent string but with consent', () => { + let bidRequest = Object.assign([], bidRequests); + bidRequests[0].gdprConsent = { + 'gdprApplies': true + }; + delete bidRequest[0].params.test; + const request = spec.buildRequests(bidRequest); + let data = JSON.parse(request.data); + expect(data.regs.ext.gdpr).to.equal(1); + expect(data.user.ext.consent).to.equal(''); + }); + }); + + describe('interpretResponse', () => { + let response = [{ + 'id': 'bidder_imp_identifier', + 'impid': '552b8922e28f27', + 'price': 0.5, + 'adid': 'Ad_Identifier', + 'adm': '', + 'adomain': ['rtbhouse.com'], + 'cid': 'Ad_Identifier', + 'w': 300, + 'h': 250 + }]; + + it('should get correct bid response', () => { + let expectedResponse = [ + { + 'requestId': '552b8922e28f27', + 'cpm': 0.5, + 'creativeId': 29681110, + 'width': 300, + 'height': 250, + 'ad': '', + 'mediaType': 'banner', + 'currency': 'USD', + 'ttl': 300, + 'netRevenue': true + } + ]; + let bidderRequest; + let result = spec.interpretResponse({ body: response }, {bidderRequest}); + expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); + }); + + it('handles nobid responses', () => { + let response = ''; + let bidderRequest; + let result = spec.interpretResponse({ body: response }, {bidderRequest}); + expect(result.length).to.equal(0); + }); + }); +}); From d6b4863c6a02c5a24d886714110d781871582543 Mon Sep 17 00:00:00 2001 From: Marcian123 Date: Tue, 29 May 2018 16:28:31 +0200 Subject: [PATCH 2/7] Delete rtbhouseBidAdapter_spec.js --- rtbhouseBidAdapter_spec.js | 162 ------------------------------------- 1 file changed, 162 deletions(-) delete mode 100644 rtbhouseBidAdapter_spec.js diff --git a/rtbhouseBidAdapter_spec.js b/rtbhouseBidAdapter_spec.js deleted file mode 100644 index 9304e50e908..00000000000 --- a/rtbhouseBidAdapter_spec.js +++ /dev/null @@ -1,162 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/rtbhouseBidAdapter'; -import { newBidder } from 'src/adapters/bidderFactory'; - -const REGIONS = ['prebid-eu', 'prebid-us', 'prebid-asia']; -const ENDPOINT_URL = 'creativecdn.com/bidder/prebid/bids'; -const consentStr = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='; -/** - * Helpers - */ - -function buildEndpointUrl(region) { - return 'https://' + region + '.' + ENDPOINT_URL; -} - -/** - * endof Helpers - */ - -describe('RTBHouseAdapter', () => { - const adapter = newBidder(spec); - - describe('inherited functions', () => { - it('exists and is a function', () => { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', () => { - let bid = { - 'bidder': 'rtbhouse', - 'params': { - 'publisherId': 'PREBID_TEST', - 'region': 'prebid-eu' - }, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475' - }; - - it('should return true when required params found', () => { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when required params are not passed', () => { - let bid = Object.assign({}, bid); - delete bid.params; - bid.params = { - 'someIncorrectParam': 0 - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - }); - - describe('buildRequests', () => { - let bidRequests = [ - { - 'bidder': 'rtbhouse', - 'params': { - 'publisherId': 'PREBID_TEST', - 'region': 'prebid-eu', - 'test': 1 - }, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475' - } - ]; - - it('should build test param into the request', () => { - let builtTestRequest = spec.buildRequests(bidRequests).data; - expect(JSON.parse(builtTestRequest).test).to.equal(1); - }); - - it('sends bid request to ENDPOINT via POST', () => { - let bidRequest = Object.assign([], bidRequests); - delete bidRequest[0].params.test; - const request = spec.buildRequests(bidRequest); - expect(request.url).to.equal(buildEndpointUrl(bidRequest[0].params.region)); - expect(request.method).to.equal('POST'); - }); - - it('should not populate GDPR if for non-EEA users', () => { - let bidRequest = Object.assign([], bidRequests); - delete bidRequest[0].params.test; - const request = spec.buildRequests(bidRequest); - let data = JSON.parse(request.data); - expect(data).to.not.have.property('regs'); - expect(data).to.not.have.property('user'); - }); - - it('should populate GDPR and consent string if available for EEA users', () => { - let bidRequest = Object.assign([], bidRequests); - bidRequests[0].gdprConsent = { - 'consentString': consentStr, - 'gdprApplies': true - }; - delete bidRequest[0].params.test; - const request = spec.buildRequests(bidRequest); - let data = JSON.parse(request.data); - expect(data.regs.ext.gdpr).to.equal(1); - expect(data.user.ext.consent).to.equal('BOJ8RZsOJ8RZsABAB8AAAAAZ-A'); - }); - - it('should populate GDPR and empty consent string if available for EEA users without consent string but with consent', () => { - let bidRequest = Object.assign([], bidRequests); - bidRequests[0].gdprConsent = { - 'gdprApplies': true - }; - delete bidRequest[0].params.test; - const request = spec.buildRequests(bidRequest); - let data = JSON.parse(request.data); - expect(data.regs.ext.gdpr).to.equal(1); - expect(data.user.ext.consent).to.equal(''); - }); - }); - - describe('interpretResponse', () => { - let response = [{ - 'id': 'bidder_imp_identifier', - 'impid': '552b8922e28f27', - 'price': 0.5, - 'adid': 'Ad_Identifier', - 'adm': '', - 'adomain': ['rtbhouse.com'], - 'cid': 'Ad_Identifier', - 'w': 300, - 'h': 250 - }]; - - it('should get correct bid response', () => { - let expectedResponse = [ - { - 'requestId': '552b8922e28f27', - 'cpm': 0.5, - 'creativeId': 29681110, - 'width': 300, - 'height': 250, - 'ad': '', - 'mediaType': 'banner', - 'currency': 'USD', - 'ttl': 300, - 'netRevenue': true - } - ]; - let bidderRequest; - let result = spec.interpretResponse({ body: response }, {bidderRequest}); - expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); - }); - - it('handles nobid responses', () => { - let response = ''; - let bidderRequest; - let result = spec.interpretResponse({ body: response }, {bidderRequest}); - expect(result.length).to.equal(0); - }); - }); -}); From 3800985e4eb87ce191ec07036f375e627d27aec6 Mon Sep 17 00:00:00 2001 From: Marcian123 Date: Tue, 29 May 2018 16:28:44 +0200 Subject: [PATCH 3/7] Delete rtbhouseBidAdapter.js --- rtbhouseBidAdapter.js | 125 ------------------------------------------ 1 file changed, 125 deletions(-) delete mode 100644 rtbhouseBidAdapter.js diff --git a/rtbhouseBidAdapter.js b/rtbhouseBidAdapter.js deleted file mode 100644 index 0ee5c42b368..00000000000 --- a/rtbhouseBidAdapter.js +++ /dev/null @@ -1,125 +0,0 @@ -import * as utils from 'src/utils'; -import { BANNER } from 'src/mediaTypes'; -import { registerBidder } from 'src/adapters/bidderFactory'; -import includes from 'core-js/library/fn/array/includes'; - -const BIDDER_CODE = 'rtbhouse'; -const REGIONS = ['prebid-eu', 'prebid-us', 'prebid-asia']; -const ENDPOINT_URL = 'creativecdn.com/bidder/prebid/bids'; -const DEFAULT_CURRENCY_ARR = ['USD']; // NOTE - USD is the only supported currency right now; Hardcoded for bids - -/** - * Helpers - */ - -function buildEndpointUrl(region) { - return 'https://' + region + '.' + ENDPOINT_URL; -} - -/** - * Produces an OpenRTBImpression from a slot config. - */ -function mapImpression(slot) { - return { - id: slot.bidId, - banner: mapBanner(slot), - tagid: slot.adUnitCode.toString(), - }; -} - -/** - * Produces an OpenRTB Banner object for the slot given. - */ -function mapBanner(slot) { - return { - w: slot.sizes[0][0], - h: slot.sizes[0][1], - format: mapSizes(slot.sizes) - }; -} - -/** - * Produce openRTB banner.format object - */ -function mapSizes(slot_sizes) { - const format = []; - slot_sizes.forEach(elem => { - format.push({ - w: elem[0], - h: elem[1] - }); - }); - return format; -} - -/** - * Produces an OpenRTB site object. - */ -function mapSite(validRequest) { - const pubId = validRequest && validRequest.length > 0 ? validRequest[0].params.publisherId : 'unknown'; - return { - publisher: { - id: pubId.toString(), - }, - page: utils.getTopWindowUrl(), - name: utils.getOrigin() - } -} - -export const spec = { - code: BIDDER_CODE, - supportedMediaTypes: [BANNER], - - isBidRequestValid: function (bid) { - return !!(includes(REGIONS, bid.params.region) && bid.params.publisherId); - }, - buildRequests: function (validBidRequests) { - const request = { - id: validBidRequests[0].auctionId, - imp: validBidRequests.map(slot => mapImpression(slot)), - site: mapSite(validBidRequests), - cur: DEFAULT_CURRENCY_ARR, - test: validBidRequests[0].params.test || 0, - }; - if (validBidRequests[0].gdprConsent && validBidRequests[0].gdprConsent.gdprApplies) { - const consentStr = (validBidRequests[0].gdprConsent.consentString) - ? validBidRequests[0].gdprConsent.consentString.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '') : ''; - const gdpr = validBidRequests[0].gdprConsent.gdprApplies ? 1 : 0; - request.regs = {ext: {gdpr: gdpr}}; - request.user = {ext: {consent: consentStr}}; - }; - - return { - method: 'POST', - url: buildEndpointUrl(validBidRequests[0].params.region), - data: JSON.stringify(request) - }; - }, - interpretResponse: function (serverResponse, originalRequest) { - serverResponse = serverResponse.body; - const bids = []; - - if (utils.isArray(serverResponse)) { - serverResponse.forEach(serverBid => { - if (serverBid.price !== 0) { - const bid = { - requestId: serverBid.impid, - mediaType: BANNER, - cpm: serverBid.price, - creativeId: serverBid.adid, - ad: serverBid.adm, - width: serverBid.w, - height: serverBid.h, - ttl: 55, - netRevenue: true, - currency: 'USD' - }; - bids.push(bid); - } - }); - } - return bids; - } -}; - -registerBidder(spec); From a64c1ad23cacd65067da8f4f34cfc0fac633ce32 Mon Sep 17 00:00:00 2001 From: Marcian123 Date: Tue, 29 May 2018 16:30:05 +0200 Subject: [PATCH 4/7] Added GDPR integration to RTBhouse adapter --- modules/rtbhouseBidAdapter.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/modules/rtbhouseBidAdapter.js b/modules/rtbhouseBidAdapter.js index cd60925b2c7..0ee5c42b368 100644 --- a/modules/rtbhouseBidAdapter.js +++ b/modules/rtbhouseBidAdapter.js @@ -73,15 +73,22 @@ export const spec = { isBidRequestValid: function (bid) { return !!(includes(REGIONS, bid.params.region) && bid.params.publisherId); }, - buildRequests: function (validBidRequests) { const request = { id: validBidRequests[0].auctionId, imp: validBidRequests.map(slot => mapImpression(slot)), site: mapSite(validBidRequests), cur: DEFAULT_CURRENCY_ARR, - test: validBidRequests[0].params.test || 0 + test: validBidRequests[0].params.test || 0, + }; + if (validBidRequests[0].gdprConsent && validBidRequests[0].gdprConsent.gdprApplies) { + const consentStr = (validBidRequests[0].gdprConsent.consentString) + ? validBidRequests[0].gdprConsent.consentString.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '') : ''; + const gdpr = validBidRequests[0].gdprConsent.gdprApplies ? 1 : 0; + request.regs = {ext: {gdpr: gdpr}}; + request.user = {ext: {consent: consentStr}}; }; + return { method: 'POST', url: buildEndpointUrl(validBidRequests[0].params.region), From e2fb9a5c58b9fa67b29daa01249976323576909d Mon Sep 17 00:00:00 2001 From: Marcian123 Date: Tue, 29 May 2018 16:31:09 +0200 Subject: [PATCH 5/7] Update rtbhouseBidAdapter_spec.js --- test/spec/modules/rtbhouseBidAdapter_spec.js | 39 ++++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/test/spec/modules/rtbhouseBidAdapter_spec.js b/test/spec/modules/rtbhouseBidAdapter_spec.js index 69bd3f40f72..9304e50e908 100644 --- a/test/spec/modules/rtbhouseBidAdapter_spec.js +++ b/test/spec/modules/rtbhouseBidAdapter_spec.js @@ -4,7 +4,7 @@ import { newBidder } from 'src/adapters/bidderFactory'; const REGIONS = ['prebid-eu', 'prebid-us', 'prebid-asia']; const ENDPOINT_URL = 'creativecdn.com/bidder/prebid/bids'; - +const consentStr = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='; /** * Helpers */ @@ -79,12 +79,45 @@ describe('RTBHouseAdapter', () => { it('sends bid request to ENDPOINT via POST', () => { let bidRequest = Object.assign([], bidRequests); delete bidRequest[0].params.test; - const request = spec.buildRequests(bidRequest); expect(request.url).to.equal(buildEndpointUrl(bidRequest[0].params.region)); expect(request.method).to.equal('POST'); }); - }) + + it('should not populate GDPR if for non-EEA users', () => { + let bidRequest = Object.assign([], bidRequests); + delete bidRequest[0].params.test; + const request = spec.buildRequests(bidRequest); + let data = JSON.parse(request.data); + expect(data).to.not.have.property('regs'); + expect(data).to.not.have.property('user'); + }); + + it('should populate GDPR and consent string if available for EEA users', () => { + let bidRequest = Object.assign([], bidRequests); + bidRequests[0].gdprConsent = { + 'consentString': consentStr, + 'gdprApplies': true + }; + delete bidRequest[0].params.test; + const request = spec.buildRequests(bidRequest); + let data = JSON.parse(request.data); + expect(data.regs.ext.gdpr).to.equal(1); + expect(data.user.ext.consent).to.equal('BOJ8RZsOJ8RZsABAB8AAAAAZ-A'); + }); + + it('should populate GDPR and empty consent string if available for EEA users without consent string but with consent', () => { + let bidRequest = Object.assign([], bidRequests); + bidRequests[0].gdprConsent = { + 'gdprApplies': true + }; + delete bidRequest[0].params.test; + const request = spec.buildRequests(bidRequest); + let data = JSON.parse(request.data); + expect(data.regs.ext.gdpr).to.equal(1); + expect(data.user.ext.consent).to.equal(''); + }); + }); describe('interpretResponse', () => { let response = [{ From 63bccf5e941f626b99edb410e31de74ad54456c4 Mon Sep 17 00:00:00 2001 From: Marcian123 Date: Wed, 30 May 2018 11:24:59 +0200 Subject: [PATCH 6/7] Added GDPR consent as second build attribute. --- modules/rtbhouseBidAdapter.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/rtbhouseBidAdapter.js b/modules/rtbhouseBidAdapter.js index 0ee5c42b368..678e156c5e6 100644 --- a/modules/rtbhouseBidAdapter.js +++ b/modules/rtbhouseBidAdapter.js @@ -73,18 +73,18 @@ export const spec = { isBidRequestValid: function (bid) { return !!(includes(REGIONS, bid.params.region) && bid.params.publisherId); }, - buildRequests: function (validBidRequests) { + buildRequests: function (validBidRequests, bidderRequest) { const request = { id: validBidRequests[0].auctionId, imp: validBidRequests.map(slot => mapImpression(slot)), site: mapSite(validBidRequests), cur: DEFAULT_CURRENCY_ARR, - test: validBidRequests[0].params.test || 0, + test: validBidRequests[0].params.test || 0 }; - if (validBidRequests[0].gdprConsent && validBidRequests[0].gdprConsent.gdprApplies) { - const consentStr = (validBidRequests[0].gdprConsent.consentString) - ? validBidRequests[0].gdprConsent.consentString.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '') : ''; - const gdpr = validBidRequests[0].gdprConsent.gdprApplies ? 1 : 0; + if (bidderRequest && bidderRequest.gdprConsent && bidderRequest.gdprConsent.gdprApplies) { + const consentStr = (bidderRequest.gdprConsent.consentString) + ? bidderRequest.gdprConsent.consentString.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '') : ''; + const gdpr = bidderRequest.gdprConsent.gdprApplies ? 1 : 0; request.regs = {ext: {gdpr: gdpr}}; request.user = {ext: {consent: consentStr}}; }; From 404aa0be5739256aaee6c506924cdc1c4eac9060 Mon Sep 17 00:00:00 2001 From: Marcian123 Date: Wed, 30 May 2018 11:28:41 +0200 Subject: [PATCH 7/7] Added gdpr as second attribute in test. --- test/spec/modules/rtbhouseBidAdapter_spec.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/test/spec/modules/rtbhouseBidAdapter_spec.js b/test/spec/modules/rtbhouseBidAdapter_spec.js index 9304e50e908..70f21d2c868 100644 --- a/test/spec/modules/rtbhouseBidAdapter_spec.js +++ b/test/spec/modules/rtbhouseBidAdapter_spec.js @@ -95,12 +95,8 @@ describe('RTBHouseAdapter', () => { it('should populate GDPR and consent string if available for EEA users', () => { let bidRequest = Object.assign([], bidRequests); - bidRequests[0].gdprConsent = { - 'consentString': consentStr, - 'gdprApplies': true - }; delete bidRequest[0].params.test; - const request = spec.buildRequests(bidRequest); + const request = spec.buildRequests(bidRequest, {gdprConsent: {gdprApplies: true, consentString: consentStr}}); let data = JSON.parse(request.data); expect(data.regs.ext.gdpr).to.equal(1); expect(data.user.ext.consent).to.equal('BOJ8RZsOJ8RZsABAB8AAAAAZ-A'); @@ -108,11 +104,8 @@ describe('RTBHouseAdapter', () => { it('should populate GDPR and empty consent string if available for EEA users without consent string but with consent', () => { let bidRequest = Object.assign([], bidRequests); - bidRequests[0].gdprConsent = { - 'gdprApplies': true - }; delete bidRequest[0].params.test; - const request = spec.buildRequests(bidRequest); + const request = spec.buildRequests(bidRequest, {gdprConsent: {gdprApplies: true}}); let data = JSON.parse(request.data); expect(data.regs.ext.gdpr).to.equal(1); expect(data.user.ext.consent).to.equal('');