From 75edabed07eb0386da3f1f14a2c78d6188f69549 Mon Sep 17 00:00:00 2001 From: Harshad Mane Date: Tue, 27 Nov 2018 11:46:31 +0530 Subject: [PATCH] PubMatic adapter to support TTD (#3311) * first commit * added unit test cases for TTD id --- modules/pubmaticBidAdapter.js | 19 ++ test/spec/modules/pubmaticBidAdapter_spec.js | 233 +++++++++++++++++++ 2 files changed, 252 insertions(+) diff --git a/modules/pubmaticBidAdapter.js b/modules/pubmaticBidAdapter.js index a4331b57c76..f66fd6e6f8f 100644 --- a/modules/pubmaticBidAdapter.js +++ b/modules/pubmaticBidAdapter.js @@ -346,9 +346,28 @@ function _handleDigitrustId(eids) { } } +function _handleTTDId(eids) { + let adsrvrOrgId = config.getConfig('adsrvrOrgId'); + if (adsrvrOrgId && utils.isStr(adsrvrOrgId.TDID)) { + eids.push({ + 'source': 'adserver.org', + 'uids': [ + { + 'id': adsrvrOrgId.TDID, + 'atype': 1, + 'ext': { + 'rtiPartner': 'TDID' + } + } + ] + }); + } +} + function _handleEids(payload) { let eids = []; _handleDigitrustId(eids); + _handleTTDId(eids); if (eids.length > 0) { payload.user.eids = eids; } diff --git a/test/spec/modules/pubmaticBidAdapter_spec.js b/test/spec/modules/pubmaticBidAdapter_spec.js index 4fca6656e46..05aaa191207 100644 --- a/test/spec/modules/pubmaticBidAdapter_spec.js +++ b/test/spec/modules/pubmaticBidAdapter_spec.js @@ -640,6 +640,239 @@ describe('PubMatic adapter', function () { }); }); + describe('AdsrvrOrgId from config', function() { + let sandbox; + beforeEach(() => { + sandbox = sinon.sandbox.create(); + }); + + afterEach(() => { + sandbox.restore(); + }); + + it('Request should have adsrvrOrgId config params', function() { + sandbox.stub(config, 'getConfig').callsFake((key) => { + var config = { + adsrvrOrgId: { + 'TDID': '5e740345-c25e-436d-b466-5f2f9fa95c17', + 'TDID_LOOKUP': 'TRUE', + 'TDID_CREATED_AT': '2018-10-01T07:05:40' + } + }; + return config[key]; + }); + + let request = spec.buildRequests(bidRequests, {}); + let data = JSON.parse(request.data); + expect(data.user.eids).to.deep.equal([{ + 'source': 'adserver.org', + 'uids': [{ + 'id': '5e740345-c25e-436d-b466-5f2f9fa95c17', + 'atype': 1, + 'ext': { + 'rtiPartner': 'TDID' + } + }] + }]); + }); + + it('Request should NOT have adsrvrOrgId config params if id in adsrvrOrgId is NOT string', function() { + sandbox.stub(config, 'getConfig').callsFake((key) => { + var config = { + adsrvrOrgId: { + 'TDID': 1, + 'TDID_LOOKUP': 'TRUE', + 'TDID_CREATED_AT': '2018-10-01T07:05:40' + } + }; + return config[key]; + }); + + 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 adsrvrOrgId is NOT object', function() { + sandbox.stub(config, 'getConfig').callsFake((key) => { + var config = { + adsrvrOrgId: null + }; + return config[key]; + }); + + 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 id in adsrvrOrgId is NOT set', function() { + sandbox.stub(config, 'getConfig').callsFake((key) => { + var config = { + adsrvrOrgId: { + 'TDID_LOOKUP': 'TRUE', + 'TDID_CREATED_AT': '2018-10-01T07:05:40' + } + }; + return config[key]; + }); + + 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; + beforeEach(() => { + sandbox = sinon.sandbox.create(); + window.DigiTrust = { + getUser: sandbox.spy() + }; + }); + + afterEach(() => { + sandbox.restore(); + delete window.DigiTrust; + }); + + it('Request should have id of both AdsrvrOrgId and Digitrust if both have returned valid ids', function() { + sandbox.stub(config, 'getConfig').callsFake((key) => { + var config = { + adsrvrOrgId: { + 'TDID': '5e740345-c25e-436d-b466-5f2f9fa95c17', + 'TDID_LOOKUP': 'TRUE', + 'TDID_CREATED_AT': '2018-10-01T07:05:40' + }, + digiTrustId: { + success: true, + identity: { + privacy: {optout: false}, + id: 'testId', + keyv: 4 + } + } + }; + return config[key]; + }); + + let request = spec.buildRequests(bidRequests, {}); + let data = JSON.parse(request.data); + expect(data.user.eids).to.deep.equal([{ + 'source': 'digitru.st', + 'uids': [{ + 'id': 'testId', + 'atype': 1, + 'ext': { + 'keyv': 4 + } + }] + }, { + 'source': 'adserver.org', + 'uids': [{ + 'id': '5e740345-c25e-436d-b466-5f2f9fa95c17', + 'atype': 1, + 'ext': { + 'rtiPartner': 'TDID' + } + }] + }]); + }); + + it('Request should have id of only AdsrvrOrgId and NOT Digitrust if only AdsrvrOrgId have returned valid id', function() { + sandbox.stub(config, 'getConfig').callsFake((key) => { + var config = { + adsrvrOrgId: { + 'TDID': '5e740345-c25e-436d-b466-5f2f9fa95c17', + 'TDID_LOOKUP': 'TRUE', + 'TDID_CREATED_AT': '2018-10-01T07:05:40' + }, + digiTrustId: { + success: true, + identity: { + privacy: {optout: true}, + id: 'testId', + keyv: 4 + } + } + }; + return config[key]; + }); + + let request = spec.buildRequests(bidRequests, {}); + let data = JSON.parse(request.data); + expect(data.user.eids).to.deep.equal([{ + 'source': 'adserver.org', + 'uids': [{ + 'id': '5e740345-c25e-436d-b466-5f2f9fa95c17', + 'atype': 1, + 'ext': { + 'rtiPartner': 'TDID' + } + }] + }]); + }); + + it('Request should have id of only Digitrust and NOT AdsrvrOrgId if only Digitrust have returned valid id', function() { + sandbox.stub(config, 'getConfig').callsFake((key) => { + var config = { + adsrvrOrgId: { + 'TDID_LOOKUP': 'TRUE', + 'TDID_CREATED_AT': '2018-10-01T07:05:40' + }, + digiTrustId: { + success: true, + identity: { + privacy: {optout: false}, + id: 'testId', + keyv: 4 + } + } + }; + return config[key]; + }); + + let request = spec.buildRequests(bidRequests, {}); + let data = JSON.parse(request.data); + expect(data.user.eids).to.deep.equal([{ + 'source': 'digitru.st', + 'uids': [{ + 'id': 'testId', + 'atype': 1, + 'ext': { + 'keyv': 4 + } + }] + }]); + }); + + it('Request should NOT have id of Digitrust and NOT AdsrvrOrgId if only both have NOT returned valid ids', function() { + sandbox.stub(config, 'getConfig').callsFake((key) => { + var config = { + adsrvrOrgId: { + 'TDID_LOOKUP': 'TRUE', + 'TDID_CREATED_AT': '2018-10-01T07:05:40' + }, + digiTrustId: { + success: true, + identity: { + privacy: {optout: true}, + id: 'testId', + keyv: 4 + } + } + }; + return config[key]; + }); + + let request = spec.buildRequests(bidRequests, {}); + let data = JSON.parse(request.data); + expect(data.user.eids).to.deep.equal(undefined); + }); + }); + it('Request params check for video ad', function () { let request = spec.buildRequests(videoBidRequests); let data = JSON.parse(request.data);