From 6c926a42589ad342fdcad4cb35567a64843f335e Mon Sep 17 00:00:00 2001 From: Harshad Mane Date: Mon, 29 Apr 2019 13:06:39 -0700 Subject: [PATCH 1/4] in-dev --- modules/pubmaticBidAdapter.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/modules/pubmaticBidAdapter.js b/modules/pubmaticBidAdapter.js index 6891285fcc2..dbc5df3c7c4 100644 --- a/modules/pubmaticBidAdapter.js +++ b/modules/pubmaticBidAdapter.js @@ -601,13 +601,19 @@ function _handleDigitrustId(eids) { } } -function _handleTTDId(eids) { +function _handleTTDId(eids, validBidRequests) { let adsrvrOrgId = config.getConfig('adsrvrOrgId'); - if (adsrvrOrgId && utils.isStr(adsrvrOrgId.TDID)) { + let ttd_id = ''; + if (adsrvrOrgId && utils.isStr(adsrvrOrgId.TDID)){ + ttd_id = adsrvrOrgId.TDID; + } else if(validBidRequests.userId && validBidRequests.userId.tdid){ + ttd_id = validBidRequests.userId.tdid; + } + if (ttd_id) { eids.push({ 'source': 'adserver.org', 'uids': [{ - 'id': adsrvrOrgId.TDID, + 'id': ttd_id, 'atype': 1, 'ext': { 'rtiPartner': 'TDID' @@ -617,10 +623,10 @@ function _handleTTDId(eids) { } } -function _handleEids(payload) { +function _handleEids(payload, validBidRequests) { let eids = []; _handleDigitrustId(eids); - _handleTTDId(eids); + _handleTTDId(eids, validBidRequests); if (eids.length > 0) { payload.user.eids = eids; } @@ -887,7 +893,7 @@ export const spec = { } } - _handleEids(payload); + _handleEids(payload, validBidRequests); _blockedIabCategoriesValidation(payload, blockedIabCategories); return { method: 'POST', From 22ad021761192f05ce5e8a8a9ae47d243b10c168 Mon Sep 17 00:00:00 2001 From: Harshad Mane Date: Mon, 29 Apr 2019 15:29:34 -0700 Subject: [PATCH 2/4] added unit test cases --- modules/pubmaticBidAdapter.js | 15 +++-- test/spec/modules/pubmaticBidAdapter_spec.js | 68 ++++++++++++++++++++ 2 files changed, 76 insertions(+), 7 deletions(-) diff --git a/modules/pubmaticBidAdapter.js b/modules/pubmaticBidAdapter.js index dbc5df3c7c4..82d932df918 100644 --- a/modules/pubmaticBidAdapter.js +++ b/modules/pubmaticBidAdapter.js @@ -602,18 +602,19 @@ function _handleDigitrustId(eids) { } function _handleTTDId(eids, validBidRequests) { + let ttdId = null; let adsrvrOrgId = config.getConfig('adsrvrOrgId'); - let ttd_id = ''; - if (adsrvrOrgId && utils.isStr(adsrvrOrgId.TDID)){ - ttd_id = adsrvrOrgId.TDID; - } else if(validBidRequests.userId && validBidRequests.userId.tdid){ - ttd_id = validBidRequests.userId.tdid; + if (validBidRequests[0] && validBidRequests[0].userId && validBidRequests[0].userId.tdid) { + ttdId = validBidRequests[0].userId.tdid; + } else if (adsrvrOrgId && utils.isStr(adsrvrOrgId.TDID)) { + ttdId = adsrvrOrgId.TDID; } - if (ttd_id) { + + if (ttdId !== null) { eids.push({ 'source': 'adserver.org', 'uids': [{ - 'id': ttd_id, + 'id': ttdId, 'atype': 1, 'ext': { 'rtiPartner': 'TDID' diff --git a/test/spec/modules/pubmaticBidAdapter_spec.js b/test/spec/modules/pubmaticBidAdapter_spec.js index bf008574027..75e8970cd79 100644 --- a/test/spec/modules/pubmaticBidAdapter_spec.js +++ b/test/spec/modules/pubmaticBidAdapter_spec.js @@ -1214,6 +1214,74 @@ describe('PubMatic adapter', function () { }); }); + describe('AdsrvrOrgId from userId module', function() { + let sandbox; + beforeEach(() => { + sandbox = sinon.sandbox.create(); + }); + + afterEach(() => { + sandbox.restore(); + }); + + it('Request should have AdsrvrOrgId config params', function() { + bidRequests[0].userId = {}; + bidRequests[0].userId.tdid = 'TTD_ID_FROM_USER_ID_MODULE'; + let request = spec.buildRequests(bidRequests, {}); + let data = JSON.parse(request.data); + expect(data.user.eids).to.deep.equal([{ + 'source': 'adserver.org', + 'uids': [{ + 'id': 'TTD_ID_FROM_USER_ID_MODULE', + 'atype': 1, + 'ext': { + 'rtiPartner': 'TDID' + } + }] + }]); + }); + + it('Request should have adsrvrOrgId from UserId Module if config and userId module both have TTD ID', function() { + sandbox.stub(config, 'getConfig').callsFake((key) => { + var config = { + adsrvrOrgId: { + 'TDID': 'TTD_ID_FROM_CONFIG', + 'TDID_LOOKUP': 'TRUE', + 'TDID_CREATED_AT': '2018-10-01T07:05:40' + } + }; + return config[key]; + }); + bidRequests[0].userId = {}; + bidRequests[0].userId.tdid = 'TTD_ID_FROM_USER_ID_MODULE'; + let request = spec.buildRequests(bidRequests, {}); + let data = JSON.parse(request.data); + expect(data.user.eids).to.deep.equal([{ + 'source': 'adserver.org', + 'uids': [{ + 'id': 'TTD_ID_FROM_USER_ID_MODULE', + 'atype': 1, + 'ext': { + 'rtiPartner': 'TDID' + } + }] + }]); + }); + + it('Request should NOT have adsrvrOrgId config params if userId is NOT object', function() { + let request = spec.buildRequests(bidRequests, {}); + let data = JSON.parse(request.data); + expect(data.user.eids).to.deep.equal(undefined); + }); + + it('Request should NOT have adsrvrOrgId config params if userId.tdid is NOT object', function() { + bidRequests[0].userId = {}; + let request = spec.buildRequests(bidRequests, {}); + let data = JSON.parse(request.data); + expect(data.user.eids).to.deep.equal(undefined); + }); + }); + describe('AdsrvrOrgId and Digitrust', function() { // here we are considering cases only of accepting DigiTrustId from config let sandbox; From b9d9a4bfe96741fd22cb42d052a5acc779ddf09f Mon Sep 17 00:00:00 2001 From: Harshad Mane Date: Mon, 29 Apr 2019 23:29:30 -0700 Subject: [PATCH 3/4] adding isStr check on userId.tdid --- modules/pubmaticBidAdapter.js | 2 +- test/spec/modules/pubmaticBidAdapter_spec.js | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/modules/pubmaticBidAdapter.js b/modules/pubmaticBidAdapter.js index 82d932df918..7b481e9e9b8 100644 --- a/modules/pubmaticBidAdapter.js +++ b/modules/pubmaticBidAdapter.js @@ -604,7 +604,7 @@ function _handleDigitrustId(eids) { function _handleTTDId(eids, validBidRequests) { let ttdId = null; let adsrvrOrgId = config.getConfig('adsrvrOrgId'); - if (validBidRequests[0] && validBidRequests[0].userId && validBidRequests[0].userId.tdid) { + if (validBidRequests[0] && validBidRequests[0].userId && utils.isStr(validBidRequests[0].userId.tdid)) { ttdId = validBidRequests[0].userId.tdid; } else if (adsrvrOrgId && utils.isStr(adsrvrOrgId.TDID)) { ttdId = adsrvrOrgId.TDID; diff --git a/test/spec/modules/pubmaticBidAdapter_spec.js b/test/spec/modules/pubmaticBidAdapter_spec.js index 75e8970cd79..3caa756652b 100644 --- a/test/spec/modules/pubmaticBidAdapter_spec.js +++ b/test/spec/modules/pubmaticBidAdapter_spec.js @@ -1268,14 +1268,16 @@ describe('PubMatic adapter', function () { }]); }); - it('Request should NOT have adsrvrOrgId config params if userId is NOT object', function() { + it('Request should NOT have adsrvrOrgId params if userId is NOT object', function() { let request = spec.buildRequests(bidRequests, {}); let data = JSON.parse(request.data); expect(data.user.eids).to.deep.equal(undefined); }); - it('Request should NOT have adsrvrOrgId config params if userId.tdid is NOT object', function() { - bidRequests[0].userId = {}; + it('Request should NOT have adsrvrOrgId params if userId.tdid is NOT string', function() { + bidRequests[0].userId = { + tdid: 1234 + }; let request = spec.buildRequests(bidRequests, {}); let data = JSON.parse(request.data); expect(data.user.eids).to.deep.equal(undefined); From 4a0748b78b6fc7e05e8ebe399dd74f52ce135f32 Mon Sep 17 00:00:00 2001 From: Harshad Mane Date: Sun, 19 May 2019 07:21:34 -0700 Subject: [PATCH 4/4] review suggestion --- modules/pubmaticBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/pubmaticBidAdapter.js b/modules/pubmaticBidAdapter.js index b0f994aa072..1f9ea06cad2 100644 --- a/modules/pubmaticBidAdapter.js +++ b/modules/pubmaticBidAdapter.js @@ -604,7 +604,7 @@ function _handleDigitrustId(eids) { function _handleTTDId(eids, validBidRequests) { let ttdId = null; let adsrvrOrgId = config.getConfig('adsrvrOrgId'); - if (validBidRequests[0] && validBidRequests[0].userId && utils.isStr(validBidRequests[0].userId.tdid)) { + if (utils.isStr(utils.deepAccess(validBidRequests, '0.userId.tdid'))) { ttdId = validBidRequests[0].userId.tdid; } else if (adsrvrOrgId && utils.isStr(adsrvrOrgId.TDID)) { ttdId = adsrvrOrgId.TDID;