Skip to content

Commit

Permalink
Added publisher common ID support to sonobi adapter. (#3363)
Browse files Browse the repository at this point in the history
  • Loading branch information
edahood-sonobi authored and bretg committed Dec 10, 2018
1 parent 13182f7 commit 5a2282e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
7 changes: 4 additions & 3 deletions modules/sonobiBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { registerBidder } from 'src/adapters/bidderFactory';
import { parseSizesInput, logError, generateUUID, isEmpty } from '../src/utils';
import { parseSizesInput, logError, generateUUID, isEmpty, deepAccess } from '../src/utils';
import { BANNER, VIDEO } from '../src/mediaTypes';
import { config } from '../src/config';

Expand Down Expand Up @@ -59,9 +59,10 @@ export const spec = {
payload.us = config.getConfig('userSync').syncsPerBidder;
}

if (validBidRequests[0].params.hfa) {
payload.hfa = validBidRequests[0].params.hfa;
if (deepAccess(validBidRequests[0], 'crumbs.pubcid') || deepAccess(validBidRequests[0], 'params.hfa')) {
payload.hfa = deepAccess(validBidRequests[0], 'params.hfa') ? deepAccess(validBidRequests[0], 'params.hfa') : `PRE-${deepAccess(validBidRequests[0], 'crumbs.pubcid')}`;
}

if (validBidRequests[0].params.referrer) {
payload.ref = validBidRequests[0].params.referrer;
}
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 @@ -236,6 +236,32 @@ describe('SonobiBidAdapter', function () {
const bidRequests = spec.buildRequests([{params: {}}], bidderRequests)
expect(bidRequests).to.equal(null);
})

it('should return a properly formatted request with commonid as hfa', function () {
delete bidRequest[0].params.hfa;
delete bidRequest[1].params.hfa;
bidRequest[0].crumbs = {'pubcid': 'abcd-efg-0101'};
bidRequest[1].crumbs = {'pubcid': 'abcd-efg-0101'};
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.ref).not.to.be.empty
expect(bidRequests.data.s).not.to.be.empty
expect(bidRequests.data.hfa).to.equal('PRE-abcd-efg-0101');
})

it('should return a properly formatted request with hfa preferred over commonid', function () {
bidRequest[0].params.hfa = 'hfakey';
bidRequest[1].params.hfa = 'hfakey';
bidRequest[0].crumbs = {'pubcid': 'abcd-efg-0101'};
bidRequest[1].crumbs = {'pubcid': 'abcd-efg-0101'};
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.ref).not.to.be.empty
expect(bidRequests.data.s).not.to.be.empty
expect(bidRequests.data.hfa).to.equal('hfakey')
})
})

describe('.interpretResponse', function () {
Expand Down

0 comments on commit 5a2282e

Please sign in to comment.