Skip to content

Commit

Permalink
DeepIntent Id Module : fix user ids not being passed on page reload d…
Browse files Browse the repository at this point in the history
…ue to getValue func miss (prebid#11383)

* fix user ids not being passed on page reload due to extendId func miss

* remove extendId and add function to read value for eids

* handle inconsistent localstorage values in deepintent id

* remove unused imports

* revert to getValue changes

* revert version in package-lock

* update test suite for deepintent id system
  • Loading branch information
parthshah51999 authored and f.caspar committed May 14, 2024
1 parent 3723712 commit 6dc34eb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 38 deletions.
9 changes: 8 additions & 1 deletion modules/deepintentDpesIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { submodule } from '../src/hook.js';
import {getStorageManager} from '../src/storageManager.js';
import {MODULE_TYPE_UID} from '../src/activities/modules.js';
import {isPlainObject} from '../src/utils.js';

/**
* @typedef {import('../modules/userId/index.js').Submodule} Submodule
Expand Down Expand Up @@ -49,7 +50,13 @@ export const deepintentDpesSubmodule = {
eids: {
'deepintentId': {
source: 'deepintent.com',
atype: 3
atype: 3,
getValue: (userIdData) => {
if (isPlainObject(userIdData) && userIdData?.id) {
return userIdData.id;
}
return userIdData;
}
},
},
};
Expand Down
60 changes: 23 additions & 37 deletions test/spec/modules/deepintentDpesIdsystem_spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { expect } from 'chai';
import {find} from 'src/polyfill.js';
import { storage, deepintentDpesSubmodule } from 'modules/deepintentDpesIdSystem.js';
import { init, requestBidsHook, setSubmoduleRegistry } from 'modules/userId/index.js';
import { config } from 'src/config.js';
import { deepintentDpesSubmodule } from 'modules/deepintentDpesIdSystem.js';

const DI_COOKIE_NAME = '_dpes_id';
const DI_COOKIE_STORED = '{"id":"2cf40748c4f7f60d343336e08f80dc99"}';
const DI_COOKIE_OBJECT = {id: '2cf40748c4f7f60d343336e08f80dc99'};
const DI_UPDATED_STORAGE = '2cf40748c4f7f60d343336e08f80dc99';

const cookieConfig = {
name: 'deepintentId',
Expand All @@ -27,50 +23,40 @@ const html5Config = {
}

describe('Deepintent DPES System', () => {
let getDataFromLocalStorageStub, localStorageIsEnabledStub;
let getCookieStub, cookiesAreEnabledStub;

beforeEach(() => {
getDataFromLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage');
localStorageIsEnabledStub = sinon.stub(storage, 'localStorageIsEnabled');
getCookieStub = sinon.stub(storage, 'getCookie');
cookiesAreEnabledStub = sinon.stub(storage, 'cookiesAreEnabled');
});

afterEach(() => {
getDataFromLocalStorageStub.restore();
localStorageIsEnabledStub.restore();
getCookieStub.restore();
cookiesAreEnabledStub.restore();
});

describe('Deepintent Dpes Sytsem: test "getId" method', () => {
it('Wrong config should fail the tests', () => {
// no config
expect(deepintentDpesSubmodule.getId()).to.be.eq(undefined);
expect(deepintentDpesSubmodule.getId({ })).to.be.eq(undefined);

expect(deepintentDpesSubmodule.getId({params: {}, storage: {}})).to.be.eq(undefined);
expect(deepintentDpesSubmodule.getId({params: {}, storage: {type: 'cookie'}})).to.be.eq(undefined);
expect(deepintentDpesSubmodule.getId({params: {}, storage: {name: '_dpes_id'}})).to.be.eq(undefined);
it('If nothing is found in cache, return undefined', () => {
let diId = deepintentDpesSubmodule.getId({}, undefined, undefined);
expect(diId).to.be.eq(undefined);
});

it('Get value stored in cookie for getId', () => {
getCookieStub.withArgs(DI_COOKIE_NAME).returns(DI_COOKIE_STORED);
let diId = deepintentDpesSubmodule.getId(cookieConfig, undefined, DI_COOKIE_OBJECT);
expect(diId).to.deep.equal(DI_COOKIE_OBJECT);
});

it('provides the stored deepintentId if cookie is absent but present in local storage', () => {
getDataFromLocalStorageStub.withArgs(DI_COOKIE_NAME).returns(DI_COOKIE_STORED);
let idx = deepintentDpesSubmodule.getId(html5Config, undefined, DI_COOKIE_OBJECT);
expect(idx).to.deep.equal(DI_COOKIE_OBJECT);
let idx = deepintentDpesSubmodule.getId(html5Config, undefined, DI_UPDATED_STORAGE);
expect(idx).to.be.eq(DI_UPDATED_STORAGE);
});
});

describe('Deepintent Dpes System : test "decode" method', () => {
it('Get the correct decoded value for dpes id', () => {
expect(deepintentDpesSubmodule.decode(DI_COOKIE_OBJECT, cookieConfig)).to.deep.equal({'deepintentId': {'id': '2cf40748c4f7f60d343336e08f80dc99'}});
it('Get the correct decoded value for dpes id, if an object is set return object', () => {
expect(deepintentDpesSubmodule.decode(DI_COOKIE_OBJECT, cookieConfig)).to.deep.equal({'deepintentId': DI_COOKIE_OBJECT});
});

it('Get the correct decoded value for dpes id, if a string is set return string', () => {
expect(deepintentDpesSubmodule.decode(DI_UPDATED_STORAGE, {})).to.deep.equal({'deepintentId': DI_UPDATED_STORAGE});
});
});

describe('Deepintent Dpes System : test "getValue" method in eids', () => {
it('Get the correct string value for dpes id, if an object is set in local storage', () => {
expect(deepintentDpesSubmodule.eids.deepintentId.getValue(DI_COOKIE_OBJECT)).to.be.equal(DI_UPDATED_STORAGE);
});

it('Get the correct string value for dpes id, if a string is set in local storage', () => {
expect(deepintentDpesSubmodule.eids.deepintentId.getValue(DI_UPDATED_STORAGE)).to.be.eq(DI_UPDATED_STORAGE);
});
});
});

0 comments on commit 6dc34eb

Please sign in to comment.