From 0a898dc9f217fafd090c045ee6e3b131c7ffab65 Mon Sep 17 00:00:00 2001 From: Jonathan Go Date: Fri, 26 Feb 2021 12:42:17 -0500 Subject: [PATCH 1/5] unwrapping id5id uid. Added new eid param for user id modules --- modules/sonobiBidAdapter.js | 11 ++- test/spec/modules/sonobiBidAdapter_spec.js | 85 +++++++++++++++++++++- 2 files changed, 91 insertions(+), 5 deletions(-) diff --git a/modules/sonobiBidAdapter.js b/modules/sonobiBidAdapter.js index a55992cec22..e23a44fdf62 100644 --- a/modules/sonobiBidAdapter.js +++ b/modules/sonobiBidAdapter.js @@ -4,7 +4,6 @@ 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(); @@ -117,9 +116,19 @@ export const spec = { payload.schain = JSON.stringify(validBidRequests[0].schain) } if (deepAccess(validBidRequests[0], 'userId') && Object.keys(validBidRequests[0].userId).length > 0) { + const userIds = validBidRequests[0].userId; + if (userIds.id5id) { + userIds.id5id = deepAccess(userIds, 'id5id.uid'); + } + payload.userid = JSON.stringify(validBidRequests[0].userId); } + 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 if (keywords) { diff --git a/test/spec/modules/sonobiBidAdapter_spec.js b/test/spec/modules/sonobiBidAdapter_spec.js index 52821072a21..38535017127 100644 --- a/test/spec/modules/sonobiBidAdapter_spec.js +++ b/test/spec/modules/sonobiBidAdapter_spec.js @@ -414,15 +414,92 @@ describe('SonobiBidAdapter', function () { expect(JSON.parse(bidRequests.data.schain)).to.deep.equal(bidRequest[0].schain) }); + it('should return a properly formatte drequest 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 () { @@ -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 () { From a85e9e8862df7e1e689034b2f325a3630339f663 Mon Sep 17 00:00:00 2001 From: Jonathan Go Date: Fri, 26 Feb 2021 12:46:09 -0500 Subject: [PATCH 2/5] set userid to new variable --- modules/sonobiBidAdapter.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/sonobiBidAdapter.js b/modules/sonobiBidAdapter.js index e23a44fdf62..91caeee6f53 100644 --- a/modules/sonobiBidAdapter.js +++ b/modules/sonobiBidAdapter.js @@ -116,19 +116,21 @@ export const spec = { payload.schain = JSON.stringify(validBidRequests[0].schain) } if (deepAccess(validBidRequests[0], 'userId') && Object.keys(validBidRequests[0].userId).length > 0) { + const userIds = validBidRequests[0].userId; - if (userIds.id5id) { + if(userIds.id5id) { userIds.id5id = deepAccess(userIds, 'id5id.uid'); } - payload.userid = JSON.stringify(validBidRequests[0].userId); + payload.userid = JSON.stringify(userIds); } const eids = deepAccess(validBidRequests[0], 'userIdAsEids'); - if (Array.isArray(eids) && eids.length > 0) { + if(Array.isArray(eids) && eids.length > 0) { payload.eids = JSON.stringify(eids); } + let keywords = validBidRequests[0].params.keywords; // a CSV of keywords if (keywords) { From 34b8b8ba003bea897f0e504312ad47ef2ddc1d16 Mon Sep 17 00:00:00 2001 From: JonGoSonobi Date: Tue, 2 Mar 2021 09:27:52 -0500 Subject: [PATCH 3/5] fixed spelling mistake in unit test Co-authored-by: Scott Menzer --- test/spec/modules/sonobiBidAdapter_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/spec/modules/sonobiBidAdapter_spec.js b/test/spec/modules/sonobiBidAdapter_spec.js index 38535017127..d1ac200394c 100644 --- a/test/spec/modules/sonobiBidAdapter_spec.js +++ b/test/spec/modules/sonobiBidAdapter_spec.js @@ -414,7 +414,7 @@ describe('SonobiBidAdapter', function () { expect(JSON.parse(bidRequests.data.schain)).to.deep.equal(bidRequest[0].schain) }); - it('should return a properly formatte drequest with eids as a JSON-encoded set of eids', function () { + it('should return a properly formatted request with eids as a JSON-encoded set of eids', function () { bidRequest[0].userIdAsEids = [ { 'source': 'pubcid.org', From 468f9fc4feadc432f0d2cdb23b3de6b283cf2bd0 Mon Sep 17 00:00:00 2001 From: Jonathan Go Date: Tue, 2 Mar 2021 09:32:32 -0500 Subject: [PATCH 4/5] copying userid object so the referenced object does not get updated. --- modules/sonobiBidAdapter.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/sonobiBidAdapter.js b/modules/sonobiBidAdapter.js index 91caeee6f53..0d1abc52bc8 100644 --- a/modules/sonobiBidAdapter.js +++ b/modules/sonobiBidAdapter.js @@ -116,9 +116,11 @@ export const spec = { payload.schain = JSON.stringify(validBidRequests[0].schain) } if (deepAccess(validBidRequests[0], 'userId') && Object.keys(validBidRequests[0].userId).length > 0) { + const userIds = { + ...validBidRequests[0].userId + }; - const userIds = validBidRequests[0].userId; - if(userIds.id5id) { + if (userIds.id5id) { userIds.id5id = deepAccess(userIds, 'id5id.uid'); } @@ -126,11 +128,10 @@ export const spec = { } const eids = deepAccess(validBidRequests[0], 'userIdAsEids'); - if(Array.isArray(eids) && eids.length > 0) { + if (Array.isArray(eids) && eids.length > 0) { payload.eids = JSON.stringify(eids); } - let keywords = validBidRequests[0].params.keywords; // a CSV of keywords if (keywords) { From cf60a14914c65438fed01a09e42a959f63f63d98 Mon Sep 17 00:00:00 2001 From: Jonathan Go Date: Wed, 10 Mar 2021 10:05:47 -0500 Subject: [PATCH 5/5] using deepClone instead of spreading the top userId object --- modules/sonobiBidAdapter.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/modules/sonobiBidAdapter.js b/modules/sonobiBidAdapter.js index 0d1abc52bc8..0e4bfb37829 100644 --- a/modules/sonobiBidAdapter.js +++ b/modules/sonobiBidAdapter.js @@ -1,5 +1,5 @@ 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'; @@ -116,9 +116,7 @@ export const spec = { payload.schain = JSON.stringify(validBidRequests[0].schain) } if (deepAccess(validBidRequests[0], 'userId') && Object.keys(validBidRequests[0].userId).length > 0) { - const userIds = { - ...validBidRequests[0].userId - }; + const userIds = deepClone(validBidRequests[0].userId); if (userIds.id5id) { userIds.id5id = deepAccess(userIds, 'id5id.uid');