From f9485cdcd39c80cf915e7dd79e169f714d956015 Mon Sep 17 00:00:00 2001 From: Chris Pan Date: Thu, 17 May 2018 11:29:32 -0700 Subject: [PATCH] Sharethrough GDPR updates --- modules/sharethroughBidAdapter.js | 12 ++++++++---- test/spec/modules/sharethroughBidAdapter_spec.js | 14 +++++++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/modules/sharethroughBidAdapter.js b/modules/sharethroughBidAdapter.js index f8cb2c99400..bb7f778089a 100644 --- a/modules/sharethroughBidAdapter.js +++ b/modules/sharethroughBidAdapter.js @@ -14,12 +14,16 @@ export const sharethroughAdapterSpec = { placement_key: bid.params.pkey, hbVersion: '$prebid.version$', strVersion: VERSION, - hbSource: 'prebid' + hbSource: 'prebid', + consent_required: false }; - if (bidderRequest && bidderRequest.gdprConsent) { + if (bidderRequest && bidderRequest.gdprConsent && bidderRequest.gdprConsent.consentString) { query.consent_string = bidderRequest.gdprConsent.consentString; - query.consent_required = bidderRequest.gdprConsent.gdprApplies; + } + + if (bidderRequest && bidderRequest.gdprConsent) { + query.consent_required = !!bidderRequest.gdprConsent.gdprApplies; } return { @@ -51,7 +55,7 @@ export const sharethroughAdapterSpec = { }, getUserSyncs: (syncOptions, serverResponses) => { const syncs = []; - if (syncOptions.pixelEnabled && serverResponses.length > 0) { + if (syncOptions.pixelEnabled && serverResponses.length > 0 && serverResponses[0].body) { serverResponses[0].body.cookieSyncUrls.forEach(url => { syncs.push({ type: 'image', url: url }); }); diff --git a/test/spec/modules/sharethroughBidAdapter_spec.js b/test/spec/modules/sharethroughBidAdapter_spec.js index aa9477d2557..2aef88fe7eb 100644 --- a/test/spec/modules/sharethroughBidAdapter_spec.js +++ b/test/spec/modules/sharethroughBidAdapter_spec.js @@ -105,8 +105,15 @@ describe('sharethrough adapter spec', () => { const gdprConsent = { consentString: 'consent_string123', gdprApplies: true }; const fakeBidRequest = { gdprConsent: gdprConsent }; const bidRequest = spec.buildRequests(bidderRequest, fakeBidRequest)[0]; - expect(bidRequest.data.consent_string).to.eq('consent_string123'); expect(bidRequest.data.consent_required).to.eq(true); + expect(bidRequest.data.consent_string).to.eq('consent_string123'); + }); + + it('should handle gdprConsent is present but values are undefined case', () => { + const gdprConsent = { consent_string: undefined, gdprApplies: undefined }; + const fakeBidRequest = { gdprConsent: gdprConsent }; + const bidRequest = spec.buildRequests(bidderRequest, fakeBidRequest)[0]; + expect(bidRequest.data).to.not.include.any.keys('consent_string') }); }); @@ -171,6 +178,11 @@ describe('sharethrough adapter spec', () => { ); }); + it('returns an empty array if the body is null', () => { + const syncArray = spec.getUserSyncs({ pixelEnabled: true }, [{ body: null }]); + expect(syncArray).to.be.an('array').that.is.empty; + }); + it('returns an empty array if pixels are not enabled', () => { const syncArray = spec.getUserSyncs({ pixelEnabled: false }, serverResponses); expect(syncArray).to.be.an('array').that.is.empty;