Skip to content

Commit

Permalink
FTRACK UserId Submodule: adding more tests for the get ID methods in …
Browse files Browse the repository at this point in the history
…pbjs (prebid#8737)

* FTRACK: adding more tests for the get ID methods in pbjs

* FTRACK: making the tests a little DRYer

* FTRACK: cleaning up the tests

* FTRACK: cleaning up some comments

Co-authored-by: Jason Lydon <jason.lydon@flashtalking.com>
  • Loading branch information
2 people authored and JacobKlein26 committed Feb 8, 2023
1 parent d4f204c commit a421062
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 86 deletions.
6 changes: 3 additions & 3 deletions modules/userId/eids.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,11 +372,11 @@ export function createEidsArray(bidRequestUserId) {
// ftrack has multiple IDs so we add each one that exists
let eid = {
'atype': 1,
'id': (bidRequestUserId[subModuleKey]['DeviceID'] || []).join('|'),
'id': (bidRequestUserId.ftrackId.DeviceID || []).join('|'),
'ext': {}
}
for (let id in bidRequestUserId[subModuleKey]) {
eid.ext[id] = (bidRequestUserId[subModuleKey][id] || []).join('|');
for (let id in bidRequestUserId.ftrackId) {
eid.ext[id] = (bidRequestUserId.ftrackId[id] || []).join('|');
}

eids.push(eid);
Expand Down
30 changes: 30 additions & 0 deletions test/spec/modules/eids_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ describe('eids array generation for known sub-modules', function() {
}]
});
});

it('uid2', function() {
const userId = {
uid2: {'id': 'Sample_AD_Token'}
Expand All @@ -316,6 +317,7 @@ describe('eids array generation for known sub-modules', function() {
}]
});
});

it('kpuid', function() {
const userId = {
kpuid: 'Sample_Token'
Expand All @@ -330,6 +332,7 @@ describe('eids array generation for known sub-modules', function() {
}]
});
});

it('tncid', function() {
const userId = {
tncid: 'TEST_TNCID'
Expand All @@ -344,6 +347,7 @@ describe('eids array generation for known sub-modules', function() {
}]
});
});

it('pubProvidedId', function() {
const userId = {
pubProvidedId: [{
Expand Down Expand Up @@ -437,6 +441,32 @@ describe('eids array generation for known sub-modules', function() {
uids: [{ id: 'some-random-id-value', atype: 1 }]
});
});

describe('ftrackId', () => {
it('should return the correct EID schema', () => {
expect(createEidsArray({
ftrackId: {
DeviceID: ['aaa', 'bbb'],
SingleDeviceID: ['ccc', 'ddd'],
HHID: ['eee', 'fff']
},
foo: {
bar: 'baz'
},
lorem: {
ipsum: ''
}
})).to.deep.equal([{
atype: 1,
id: 'aaa|bbb',
ext: {
DeviceID: 'aaa|bbb',
SingleDeviceID: 'ccc|ddd',
HHID: 'eee|fff'
}
}]);
});
});
});

describe('Negative case', function () {
Expand Down
192 changes: 109 additions & 83 deletions test/spec/modules/ftrackIdSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,107 +308,133 @@ describe('FTRACK ID System', () => {
});
});

describe('Uses ftrack getUserIdsAsEids() method', () => {
it('getUserIdsAsEids using the ftrack submodule and gets three ids (HHID, DeviceId, SingleDeviceId)', () => {
describe('pbjs "get id" methods', () => {
// The full set of ftrack IDs to test against
let expectedIds = {
HHID: ['household_test_id'],
DeviceID: ['device_test_id'],
SingleDeviceID: ['single_device_test_id']
};
// The full config mock
let userSyncConfigMock = {
userSync: {
auctionDelay: 10,
userIds: [{
name: 'ftrack',
value: {
ftrackId: expectedIds
}
}]
}
};
// The full eids response
let expectedEids = [{
id: 'device_test_id',
atype: 1,
ext: {
HHID: expectedIds.HHID.join('|'),
DeviceID: expectedIds.DeviceID.join('|'),
SingleDeviceID: expectedIds.SingleDeviceID.join('|')
}
}];

beforeEach(() => {
init(config);
setSubmoduleRegistry([ftrackIdSubmodule]);
});

const ids = {
ftrackId: {
HHID: ['household_test_id'],
DeviceID: ['device_test_id'],
SingleDeviceID: ['single_device_test_id']
}
afterEach(() => {
// Reset expectedIds to the default values because some tests overwrite them
expectedIds = {
HHID: ['household_test_id'],
DeviceID: ['device_test_id'],
SingleDeviceID: ['single_device_test_id']
};
config.setConfig({
userSync: {
auctionDelay: 10,
userIds: [{
name: 'ftrack', value: ids,
}]
}
});

getGlobal().getUserIdsAsync().then((ids) => {
expect(getGlobal().getUserIdsAsEids()).to.deep.equal([{
id: 'device_test_id',
atype: 1,
ext: {
HHID: 'household_test_id',
DeviceID: 'device_test_id',
SingleDeviceID: 'single_device_test_id',
}
}]);
});
});

it('gets only the deviceId', () => {
init(config);
setSubmoduleRegistry([ftrackIdSubmodule]);
describe('pbjs.getUserIdsAsync()', () => {
it('should return the IDs in the correct schema', () => {
config.setConfig(userSyncConfigMock);

const ids = { ftrackId: { DeviceID: ['device_test_id'] } };
config.setConfig({
userSync: {
auctionDelay: 10,
userIds: [{
name: 'ftrack', value: ids,
}]
}
getGlobal().getUserIdsAsync().then(ids => {
expect(ids).to.deep.equal({
ftrackId: expectedIds
});
});
});
});

describe('pbjs.getUserIds()', () => {
it('should return the IDs in the correct schema', () => {
config.setConfig(userSyncConfigMock);

getGlobal().getUserIdsAsync().then((ids) => {
expect(getGlobal().getUserIdsAsEids()).to.deep.equal([{
id: 'device_test_id',
atype: 1,
ext: { DeviceID: 'device_test_id' }
}]);
expect(getGlobal().getUserIds()).to.deep.equal({
'ftrackId': expectedIds
});
});
});

it('gets only the user household id', () => {
init(config);
setSubmoduleRegistry([ftrackIdSubmodule]);
describe('pbjs.getUserIdsAsEids()', () => {
it('should return the correct EIDs schema', () => {
let userSyncConfig = Object.assign({}, userSyncConfigMock);

const ids = { ftrackId: { HHID: ['household_test_id'], } };
config.setConfig({
userSync: {
auctionDelay: 10,
userIds: [{
name: 'ftrack', value: ids,
}]
}
});
config.setConfig(userSyncConfig);

getGlobal().getUserIdsAsync().then((ids) => {
expect(getGlobal().getUserIdsAsEids()).to.deep.equal([{
id: '',
atype: 1,
ext: { HHID: 'household_test_id' }
}]);
expect(getGlobal().getUserIdsAsEids()).to.deep.equal(expectedEids);
});
});

it('gets only the deviceId', () => {
init(config);
setSubmoduleRegistry([ftrackIdSubmodule]);
describe('by ID type:', () => {
it('- DeviceID', () => {
let userSyncConfig = Object.assign({}, userSyncConfigMock);

const ids = { ftrackId: { SingleDeviceID: ['single_device_test_id'] } };
config.setConfig({
userSync: {
auctionDelay: 10,
userIds: [{
name: 'ftrack', value: ids,
}]
}
});
userSyncConfig.userSync.userIds[0].value.ftrackId = {
DeviceID: ['device_test_id']
};

let expectedEidsClone = expectedEids.slice();
expectedEidsClone[0].ext = {
DeviceID: expectedIds.DeviceID.join('|')
};

config.setConfig(userSyncConfig);

expect(getGlobal().getUserIdsAsEids()).to.deep.equal(expectedEidsClone);
});

it('- HHID', () => {
let userSyncConfig = Object.assign({}, userSyncConfigMock);
userSyncConfig.userSync.userIds[0].value.ftrackId = {
HHID: ['household_test_id']
};

getGlobal().getUserIdsAsync().then((ids) => {
expect(getGlobal().getUserIdsAsEids()).to.deep.equal([{
id: '',
atype: 1,
ext: { SingleDeviceID: 'single_device_test_id' }
}]);
let expectedEidsClone = expectedEids.slice();
expectedEidsClone[0].id = '';
expectedEidsClone[0].ext = {
HHID: expectedIds.HHID.join('|')
};

config.setConfig(userSyncConfig);

expect(getGlobal().getUserIdsAsEids()).to.deep.equal(expectedEidsClone);
});

it('- SingleDeviceID', () => {
let userSyncConfig = Object.assign({}, userSyncConfigMock);
userSyncConfig.userSync.userIds[0].value.ftrackId = {
SingleDeviceID: ['single_device_test_id']
};

let expectedEidsClone = expectedEids.slice();
expectedEidsClone[0].id = '';
expectedEidsClone[0].ext = {
SingleDeviceID: expectedIds.SingleDeviceID.join('|')
};

config.setConfig(userSyncConfig);

expect(getGlobal().getUserIdsAsEids()).to.deep.equal(expectedEidsClone);
});
});
});
});
})
});

0 comments on commit a421062

Please sign in to comment.