Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PubMatic adapter to support TTD #3311

Merged
merged 3 commits into from
Nov 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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