Skip to content

Commit

Permalink
Sonobi Bid Adapter: send eids in bid request. (#6364)
Browse files Browse the repository at this point in the history
* unwrapping id5id uid. Added new eid param for user id modules

* set userid to new variable

* fixed spelling mistake in unit test

Co-authored-by: Scott Menzer <smenzer@gmail.com>

* copying userid object so the referenced object does not get updated.

* using deepClone instead of spreading the top userId object

Co-authored-by: Scott Menzer <smenzer@gmail.com>
  • Loading branch information
JonGoSonobi and smenzer authored Mar 11, 2021
1 parent 41b8607 commit f88a55a
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 7 deletions.
16 changes: 13 additions & 3 deletions modules/sonobiBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { parseSizesInput, logError, generateUUID, isEmpty, deepAccess, logWarn, logMessage } from '../src/utils.js';
import { parseSizesInput, logError, generateUUID, isEmpty, deepAccess, logWarn, logMessage, deepClone } from '../src/utils.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { config } from '../src/config.js';
import { Renderer } from '../src/Renderer.js';
import { userSync } from '../src/userSync.js';

const BIDDER_CODE = 'sonobi';
const STR_ENDPOINT = 'https://apex.go.sonobi.com/trinity.json';
const PAGEVIEW_ID = generateUUID();
Expand Down Expand Up @@ -117,7 +116,18 @@ export const spec = {
payload.schain = JSON.stringify(validBidRequests[0].schain)
}
if (deepAccess(validBidRequests[0], 'userId') && Object.keys(validBidRequests[0].userId).length > 0) {
payload.userid = JSON.stringify(validBidRequests[0].userId);
const userIds = deepClone(validBidRequests[0].userId);

if (userIds.id5id) {
userIds.id5id = deepAccess(userIds, 'id5id.uid');
}

payload.userid = JSON.stringify(userIds);
}

const eids = deepAccess(validBidRequests[0], 'userIdAsEids');
if (Array.isArray(eids) && eids.length > 0) {
payload.eids = JSON.stringify(eids);
}

let keywords = validBidRequests[0].params.keywords; // a CSV of keywords
Expand Down
85 changes: 81 additions & 4 deletions test/spec/modules/sonobiBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,15 +414,92 @@ describe('SonobiBidAdapter', function () {
expect(JSON.parse(bidRequests.data.schain)).to.deep.equal(bidRequest[0].schain)
});

it('should return a properly formatted request with eids as a JSON-encoded set of eids', function () {
bidRequest[0].userIdAsEids = [
{
'source': 'pubcid.org',
'uids': [
{
'id': '97b1ff9b-6bf1-41fc-95de-acfd33dbb95a',
'atype': 1
}
]
},
{
'source': 'sharedid.org',
'uids': [
{
'id': '01ERJ6W40EXJZNQJVJZWASEG7J',
'atype': 1,
'ext': {
'third': '01ERJ6W40EXJZNQJVJZWASEG7J'
}
}
]
}
];
bidRequest[1].userIdAsEids = [
{
'source': 'pubcid.org',
'uids': [
{
'id': '97b1ff9b-6bf1-41fc-95de-acfd33dbb95a',
'atype': 1
}
]
},
{
'source': 'sharedid.org',
'uids': [
{
'id': '01ERJ6W40EXJZNQJVJZWASEG7J',
'atype': 1,
'ext': {
'third': '01ERJ6W40EXJZNQJVJZWASEG7J'
}
}
]
}
];
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(JSON.parse(bidRequests.data.eids)).to.eql([
{
'source': 'pubcid.org',
'uids': [
{
'id': '97b1ff9b-6bf1-41fc-95de-acfd33dbb95a',
'atype': 1
}
]
},
{
'source': 'sharedid.org',
'uids': [
{
'id': '01ERJ6W40EXJZNQJVJZWASEG7J',
'atype': 1,
'ext': {
'third': '01ERJ6W40EXJZNQJVJZWASEG7J'
}
}
]
}
]);
});

it('should return a properly formatted request with userid as a JSON-encoded set of User ID results', function () {
bidRequest[0].userId = {'pubcid': 'abcd-efg-0101', 'tdid': 'td-abcd-efg-0101'};
bidRequest[1].userId = {'pubcid': 'abcd-efg-0101', 'tdid': 'td-abcd-efg-0101'};
bidRequest[0].userId = {'pubcid': 'abcd-efg-0101', 'tdid': 'td-abcd-efg-0101', 'id5id': {'uid': 'ID5-ZHMOrVeUVTUKgrZ-a2YGxeh5eS_pLzHCQGYOEAiTBQ', 'ext': {'linkType': 2}}};
bidRequest[1].userId = {'pubcid': 'abcd-efg-0101', 'tdid': 'td-abcd-efg-0101', 'id5id': {'uid': 'ID5-ZHMOrVeUVTUKgrZ-a2YGxeh5eS_pLzHCQGYOEAiTBQ', 'ext': {'linkType': 2}}};
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(JSON.parse(bidRequests.data.userid)).to.eql({'pubcid': 'abcd-efg-0101', 'tdid': 'td-abcd-efg-0101'});
expect(JSON.parse(bidRequests.data.userid)).to.eql({'pubcid': 'abcd-efg-0101', 'tdid': 'td-abcd-efg-0101', 'id5id': 'ID5-ZHMOrVeUVTUKgrZ-a2YGxeh5eS_pLzHCQGYOEAiTBQ'});
});

it('should return a properly formatted request with userid omitted if there are no userIds', function () {
Expand Down Expand Up @@ -469,7 +546,7 @@ describe('SonobiBidAdapter', function () {
];
const bidRequests = spec.buildRequests(bRequest, bidderRequests);
expect(bidRequests.url).to.equal('https://iad-2-apex.go.sonobi.com/trinity.json');
})
});
});

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

0 comments on commit f88a55a

Please sign in to comment.