Skip to content

Commit

Permalink
Sonobi Adapter GDPR Support (prebid#2582)
Browse files Browse the repository at this point in the history
* return null from buildRequests if there is no keymakers

* fixed issue where isEmpty was being called from old utils var. Changed test port expectations to the original 9876 port

* Add gdpr support
  • Loading branch information
bansawbanchee authored and dluxemburg committed Jul 17, 2018
1 parent 493a681 commit 628793c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
10 changes: 8 additions & 2 deletions modules/sonobiBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const spec = {
* @param {BidRequest[]} validBidRequests - an array of bids
* @return {object} ServerRequest - Info describing the request to the server.
*/
buildRequests: (validBidRequests) => {
buildRequests: (validBidRequests, bidderRequest) => {
const bids = validBidRequests.map(bid => {
let slotIdentifier = _validateSlot(bid);
if (/^[\/]?[\d]+[[\/].+[\/]?]?$/.test(slotIdentifier)) {
Expand Down Expand Up @@ -61,7 +61,13 @@ export const spec = {
payload.ref = validBidRequests[0].params.referrer;
}

// If there is no key_maker data, then dont make the request.
// Apply GDPR parameters to request.
if (bidderRequest && bidderRequest.gdprConsent) {
payload.gdpr = bidderRequest.gdprConsent.gdprApplies ? 'true' : 'false';
payload.consent_string = bidderRequest.gdprConsent.consentString;
}

// If there is no key_maker data, then don't make the request.
if (isEmpty(data)) {
return null;
}
Expand Down
26 changes: 26 additions & 0 deletions test/spec/modules/sonobiBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ describe('SonobiBidAdapter', () => {
'/7780971/sparks_prebid_LB|30b31c1838de1e': '300x250,300x600',
};

let bidderRequests = {
'gdprConsent': {
'consentString': 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==',
'vendorData': {},
'gdprApplies': true
},
};

it('should return a properly formatted request', () => {
const bidRequests = spec.buildRequests(bidRequest)
const bidRequestsPageViewID = spec.buildRequests(bidRequest)
Expand All @@ -145,6 +153,23 @@ describe('SonobiBidAdapter', () => {
expect(['mobile', 'tablet', 'desktop']).to.contain(bidRequests.data.vp);
})

it('should return a properly formatted request with GDPR applies set to true', () => {
const bidRequests = spec.buildRequests(bidRequest, bidderRequests)
expect(bidRequests.url).to.equal('https://apex.go.sonobi.com/trinity.json')
expect(bidRequests.method).to.equal('GET')
expect(bidRequests.data.gdpr).to.equal('true')
expect(bidRequests.data.consent_string).to.equal('BOJ/P2HOJ/P2HABABMAAAAAZ+A==')
})

it('should return a properly formatted request with GDPR applies set to false', () => {
bidderRequests.gdprConsent.gdprApplies = false;
const bidRequests = spec.buildRequests(bidRequest, bidderRequests)
expect(bidRequests.url).to.equal('https://apex.go.sonobi.com/trinity.json')
expect(bidRequests.method).to.equal('GET')
expect(bidRequests.data.gdpr).to.equal('false')
expect(bidRequests.data.consent_string).to.equal('BOJ/P2HOJ/P2HABABMAAAAAZ+A==')
})

it('should return a properly formatted request with hfa', () => {
bidRequest[0].params.hfa = 'hfakey'
bidRequest[1].params.hfa = 'hfakey'
Expand All @@ -155,6 +180,7 @@ describe('SonobiBidAdapter', () => {
expect(bidRequests.data.s).not.to.be.empty
expect(bidRequests.data.hfa).to.equal('hfakey')
})

it('should return null if there is nothing to bid on', () => {
const bidRequests = spec.buildRequests([{params: {}}])
expect(bidRequests).to.equal(null);
Expand Down

0 comments on commit 628793c

Please sign in to comment.