Skip to content

Commit

Permalink
PubMatic adapter to support TTD (#3311)
Browse files Browse the repository at this point in the history
* first commit

* added unit test cases for TTD id
  • Loading branch information
pm-harshad-mane authored and mike-chowla committed Nov 27, 2018
1 parent e90b5d5 commit 7990f92
Show file tree
Hide file tree
Showing 2 changed files with 252 additions and 0 deletions.
19 changes: 19 additions & 0 deletions modules/pubmaticBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,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;
}
Expand Down
233 changes: 233 additions & 0 deletions test/spec/modules/pubmaticBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 7990f92

Please sign in to comment.