Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
johnwier committed Aug 31, 2021
1 parent bdc0043 commit e6812c7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
24 changes: 13 additions & 11 deletions modules/publinkIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,13 @@ function getlocalValue() {
}

if (typeof value === 'string') {
const obj = JSON.parse(value);
if (obj && obj.exp > Date.now()) {
return obj.publink;
try {
const obj = JSON.parse(value);
if (obj && obj.exp && obj.exp > Date.now()) {
return obj.publink;
}
} catch (e) {
utils.logError(e);
}
}
}
Expand Down Expand Up @@ -101,21 +105,19 @@ export const publinkIdSubmodule = {

/**
* performs action to obtain id
* Use a publink cookie first if it is present, otherwise use prebids copy, if neither are available callout to get a new id
* @function
* @param {SubmoduleConfig} [config] Config object with params and storage properties
* @returns {IdResponse}
*/
getId: function(config, consentData, storedId) {
let result = {};
const storedValue = getlocalValue();
if (storedValue) {
result.id = storedValue;
const localValue = getlocalValue();
if (localValue) {
return {id: localValue};
}
if (storedId) {
result.id = storedId;
if (!storedId) {
return {callback: makeCallback(config, consentData)};
}
result.callback = makeCallback(config, consentData);
return result;
}
};
submodule('userId', publinkIdSubmodule);
6 changes: 2 additions & 4 deletions test/spec/modules/publinkIdSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,9 @@ describe('PublinkIdSystem', () => {
expect(result).to.exist;
expect(result.callback).to.be.a('function');
});
it('Use local id', () => {
it('Use local copy', () => {
const result = publinkIdSubmodule.getId({}, undefined, TEST_COOKIE_VALUE);
expect(result).to.exist;
expect(result.id).to.equal(TEST_COOKIE_VALUE);
expect(result.callback).to.be.a('function');
expect(result).to.be.undefined;
});

describe('callout for id', () => {
Expand Down

0 comments on commit e6812c7

Please sign in to comment.