Skip to content

Commit

Permalink
inline ttd and refactor test (prebid#11174)
Browse files Browse the repository at this point in the history
  • Loading branch information
wi101 authored and mefjush committed Mar 7, 2024
1 parent 787006a commit cbb3998
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 79 deletions.
16 changes: 16 additions & 0 deletions libraries/uid1Eids/uid1Eids.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export const UID1_EIDS = {
'tdid': {
source: 'adserver.org',
atype: 1,
getValue: function(data) {
if (data.id) {
return data.id;
} else {
return data;
}
},
getUidExt: function(data) {
return {...{rtiPartner: 'TDID'}, ...data.ext}
}
}
}
18 changes: 5 additions & 13 deletions modules/liveIntentIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { LiveConnect } from 'live-connect-js'; // eslint-disable-line prebid/val
import { gdprDataHandler, uspDataHandler, gppDataHandler } from '../src/adapterManager.js';
import {getStorageManager} from '../src/storageManager.js';
import {MODULE_TYPE_UID} from '../src/activities/modules.js';
import {UID1_EIDS} from '../libraries/uid1Eids/uid1Eids.js';
import {UID2_EIDS} from '../libraries/uid2Eids/uid2Eids.js';
import { getRefererInfo } from '../src/refererDetection.js';

Expand Down Expand Up @@ -236,7 +237,9 @@ export const liveIntentIdSubmodule = {
}

if (value.thetradedesk) {
result.thetradedesk = { 'id': value.thetradedesk, ext: { provider: getRefererInfo().domain || LI_PROVIDER_DOMAIN } }
result.lipb = {...result.lipb, tdid: value.thetradedesk}
result.tdid = { 'id': value.thetradedesk, ext: { rtiPartner: 'TDID', provider: getRefererInfo().domain || LI_PROVIDER_DOMAIN } }
delete result.lipb.thetradedesk
}

return result
Expand Down Expand Up @@ -278,6 +281,7 @@ export const liveIntentIdSubmodule = {
return { callback: result };
},
eids: {
...UID1_EIDS,
...UID2_EIDS,
'lipb': {
getValue: function(data) {
Expand Down Expand Up @@ -376,18 +380,6 @@ export const liveIntentIdSubmodule = {
return data.ext;
}
}
},
'thetradedesk': {
source: 'adserver.org',
atype: 3,
getValue: function(data) {
return data.id;
},
getUidExt: function(data) {
if (data.ext) {
return data.ext;
}
}
}
}
};
Expand Down
13 changes: 2 additions & 11 deletions modules/unifiedIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { logError } from '../src/utils.js';
import {ajax} from '../src/ajax.js';
import {submodule} from '../src/hook.js'
import {UID1_EIDS} from '../libraries/uid1Eids/uid1Eids.js';

/**
* @typedef {import('../modules/userId/index.js').Submodule} Submodule
Expand Down Expand Up @@ -74,17 +75,7 @@ export const unifiedIdSubmodule = {
};
return {callback: resp};
},
eids: {
'tdid': {
source: 'adserver.org',
atype: 1,
getUidExt: function() {
return {
rtiPartner: 'TDID'
};
}
},
}
eids: {...UID1_EIDS}
};

submodule('userId', unifiedIdSubmodule);
14 changes: 2 additions & 12 deletions modules/userId/eids.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ userIdAsEids = [
id: 'some-random-id-value',
atype: 1,
ext: {
rtiPartner: 'TDID'
rtiPartner: 'TDID',
provider: 'liveintent.com'
}
}]
},
Expand Down Expand Up @@ -173,17 +174,6 @@ userIdAsEids = [
}]
},
{
source: 'adserver.org',
uids: [{
id: 'some-random-id-value',
atype: 3,
ext: {
provider: 'liveintent.com'
}
}]
},
{
source: 'rubiconproject.com',
uids: [{
Expand Down
45 changes: 12 additions & 33 deletions test/spec/modules/eids_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ describe('eids array generation for known sub-modules', function() {
});
});

it('unifiedId: ext generation with provider', function() {
const userId = {
tdid: {'id': 'some-sample_id', 'ext': {'provider': 'some.provider.com'}}
};
const newEids = createEidsArray(userId);
expect(newEids.length).to.equal(1);
expect(newEids[0]).to.deep.equal({
source: 'adserver.org',
uids: [{id: 'some-sample_id', atype: 1, ext: { rtiPartner: 'TDID', provider: 'some.provider.com' }}]
});
});

describe('id5Id', function() {
it('does not include an ext if not provided', function() {
const userId = {
Expand Down Expand Up @@ -403,39 +415,6 @@ describe('eids array generation for known sub-modules', function() {
});
});

it('thetradedesk', function() {
const userId = {
thetradedesk: {'id': 'sample_id'}
};
const newEids = createEidsArray(userId);
expect(newEids.length).to.equal(1);
expect(newEids[0]).to.deep.equal({
source: 'adserver.org',
uids: [{
id: 'sample_id',
atype: 3
}]
});
});

it('thetradedesk with ext', function() {
const userId = {
thetradedesk: {'id': 'sample_id', 'ext': {'provider': 'some.provider.com'}}
};
const newEids = createEidsArray(userId);
expect(newEids.length).to.equal(1);
expect(newEids[0]).to.deep.equal({
source: 'adserver.org',
uids: [{
id: 'sample_id',
atype: 3,
ext: {
provider: 'some.provider.com'
}
}]
});
});

it('liveIntentId; getValue call and NO ext', function() {
const userId = {
lipb: {
Expand Down
2 changes: 1 addition & 1 deletion test/spec/modules/liveIntentIdMinimalSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ describe('LiveIntentMinimalId', function() {
const provider = 'liveintent.com'
refererInfoStub.returns({domain: provider})
const result = liveIntentIdSubmodule.decode({ nonId: 'foo', thetradedesk: 'bar' });
expect(result).to.eql({'lipb': {'lipbid': 'foo', 'nonId': 'foo', 'thetradedesk': 'bar'}, 'thetradedesk': {'id': 'bar', 'ext': {'provider': provider}}});
expect(result).to.eql({'lipb': {'lipbid': 'foo', 'nonId': 'foo', 'tdid': 'bar'}, 'tdid': {'id': 'bar', 'ext': {'rtiPartner': 'TDID', 'provider': provider}}});
});

it('should allow disabling nonId resolution', function() {
Expand Down
2 changes: 1 addition & 1 deletion test/spec/modules/liveIntentIdSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ describe('LiveIntentId', function() {
const provider = 'liveintent.com'
refererInfoStub.returns({domain: provider})
const result = liveIntentIdSubmodule.decode({ nonId: 'foo', thetradedesk: 'bar' });
expect(result).to.eql({'lipb': {'lipbid': 'foo', 'nonId': 'foo', 'thetradedesk': 'bar'}, 'thetradedesk': {'id': 'bar', 'ext': {'provider': provider}}});
expect(result).to.eql({'lipb': {'lipbid': 'foo', 'nonId': 'foo', 'tdid': 'bar'}, 'tdid': {'id': 'bar', 'ext': {'rtiPartner': 'TDID', 'provider': provider}}});
});

it('should allow disabling nonId resolution', function() {
Expand Down
73 changes: 65 additions & 8 deletions test/spec/modules/userId_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
setSubmoduleRegistry,
syncDelay,
} from 'modules/userId/index.js';
import {UID1_EIDS} from 'libraries/uid1Eids/uid1Eids.js';
import {createEidsArray, EID_CONFIG} from 'modules/userId/eids.js';
import {config} from 'src/config.js';
import * as utils from 'src/utils.js';
Expand Down Expand Up @@ -99,6 +100,25 @@ describe('User ID', function () {
}
}

function createMockEid(name, source) {
return {
[name]: {
source: source || `${name}Source`,
atype: 3,
getValue: function(data) {
if (data.id) {
return data.id;
} else {
return data;
}
},
getUidExt: function(data) {
return data.ext
}
}
}
}

function getAdUnitMock(code = 'adUnit-code') {
return {
code,
Expand Down Expand Up @@ -644,10 +664,10 @@ describe('User ID', function () {
it('pbjs.getUserIdsAsEids should prioritize user ids according to config available to core', () => {
init(config);
setSubmoduleRegistry([
createMockIdSubmodule('mockId1Module', {id: {uid2: {id: 'uid2_value'}}}),
createMockIdSubmodule('mockId2Module', {id: {pubcid: 'pubcid_value', lipb: {lipbid: 'lipbid_value_from_mockId2Module'}}}),
createMockIdSubmodule('mockId3Module', {id: {uid2: {id: 'uid2_value_from_mockId3Module'}, pubcid: 'pubcid_value_from_mockId3Module', lipb: {lipbid: 'lipbid_value'}, merkleId: {id: 'merkleId_value_from_mockId3Module'}}}),
createMockIdSubmodule('mockId4Module', {id: {merkleId: {id: 'merkleId_value'}}})
createMockIdSubmodule('mockId1Module', {id: {uid2: {id: 'uid2_value'}}}, null, createMockEid('uid2')),
createMockIdSubmodule('mockId2Module', {id: {pubcid: 'pubcid_value', lipb: {lipbid: 'lipbid_value_from_mockId2Module'}}}, null, createMockEid('pubcid')),
createMockIdSubmodule('mockId3Module', {id: {uid2: {id: 'uid2_value_from_mockId3Module'}, pubcid: 'pubcid_value_from_mockId3Module', lipb: {lipbid: 'lipbid_value'}, merkleId: {id: 'merkleId_value_from_mockId3Module'}}}, null, {...createMockEid('uid2'), ...createMockEid('merkleId'), ...createMockEid('lipb')}),
createMockIdSubmodule('mockId4Module', {id: {merkleId: {id: 'merkleId_value'}}}, null, createMockEid('merkleId'))
]);
config.setConfig({
userSync: {
Expand Down Expand Up @@ -679,6 +699,38 @@ describe('User ID', function () {
});
});

it('pbjs.getUserIdsAsEids should prioritize the uid1 according to config available to core', () => {
init(config);
setSubmoduleRegistry([
createMockIdSubmodule('mockId1Module', {id: {tdid: {id: 'uid1_value'}}}, null, UID1_EIDS),
createMockIdSubmodule('mockId2Module', {id: {tdid: {id: 'uid1Id_value_from_mockId2Module'}}}, null, UID1_EIDS),
createMockIdSubmodule('mockId3Module', {id: {tdid: {id: 'uid1Id_value_from_mockId3Module'}}}, null, UID1_EIDS)
]);
config.setConfig({
userSync: {
idPriority: {
tdid: ['mockId2Module', 'mockId3Module', 'mockId1Module']
},
auctionDelay: 10, // with auctionDelay > 0, no auction is needed to complete init
userIds: [
{ name: 'mockId1Module' },
{ name: 'mockId2Module' },
{ name: 'mockId3Module' }
]
}
});

const ids = {
'tdid': { id: 'uid1Id_value_from_mockId2Module' },
};

return getGlobal().getUserIdsAsync().then(() => {
const eids = getGlobal().getUserIdsAsEids();
const expected = createEidsArray(ids);
expect(eids).to.deep.equal(expected);
})
});

describe('EID updateConfig', () => {
function mockSubmod(name, eids) {
return createMockIdSubmodule(name, null, null, eids);
Expand Down Expand Up @@ -3554,11 +3606,16 @@ describe('User ID', function () {

it('pbjs.getUserIdsAsEidBySource with priority config available to core', () => {
init(config);
const uid2Eids = createMockEid('uid2', 'uidapi.com')
const pubcEids = createMockEid('pubcid', 'pubcid.org')
const liveIntentEids = createMockEid('lipb', 'liveintent.com')
const merkleEids = createMockEid('merkleId', 'merkleinc.com')

setSubmoduleRegistry([
createMockIdSubmodule('mockId1Module', {id: {uid2: {id: 'uid2_value'}}}),
createMockIdSubmodule('mockId2Module', {id: {pubcid: 'pubcid_value', lipb: {lipbid: 'lipbid_value_from_mockId2Module'}}}),
createMockIdSubmodule('mockId3Module', {id: {uid2: {id: 'uid2_value_from_mockId3Module'}, pubcid: 'pubcid_value_from_mockId3Module', lipb: {lipbid: 'lipbid_value'}, merkleId: {id: 'merkleId_value_from_mockId3Module'}}}),
createMockIdSubmodule('mockId4Module', {id: {merkleId: {id: 'merkleId_value'}}})
createMockIdSubmodule('mockId1Module', {id: {uid2: {id: 'uid2_value'}}}, null, uid2Eids),
createMockIdSubmodule('mockId2Module', {id: {pubcid: 'pubcid_value', lipb: {lipbid: 'lipbid_value_from_mockId2Module'}}}, null, {...pubcEids, ...liveIntentEids}),
createMockIdSubmodule('mockId3Module', {id: {uid2: {id: 'uid2_value_from_mockId3Module'}, pubcid: 'pubcid_value_from_mockId3Module', lipb: {lipbid: 'lipbid_value'}, merkleId: {id: 'merkleId_value_from_mockId3Module'}}}, null, {...uid2Eids, ...pubcEids, ...liveIntentEids}),
createMockIdSubmodule('mockId4Module', {id: {merkleId: {id: 'merkleId_value'}}}, null, merkleEids)
]);
config.setConfig({
userSync: {
Expand Down

0 comments on commit cbb3998

Please sign in to comment.