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

Pair Id System: less noisy errors #9998

Merged
merged 2 commits into from
May 26, 2023
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
12 changes: 6 additions & 6 deletions modules/pairIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { submodule } from '../src/hook.js';
import {getStorageManager} from '../src/storageManager.js'
import { logError } from '../src/utils.js';
import { logInfo } from '../src/utils.js';
import {MODULE_TYPE_UID} from '../src/activities/modules.js';

const MODULE_NAME = 'pairId';
Expand All @@ -17,11 +17,11 @@ const DEFAULT_LIVERAMP_PAIR_ID_KEY = '_lr_pairId';
export const storage = getStorageManager({moduleType: MODULE_TYPE_UID, moduleName: MODULE_NAME});

function pairIdFromLocalStorage(key) {
return storage.localStorageIsEnabled ? storage.getDataFromLocalStorage(key) : null;
return storage.localStorageIsEnabled() ? storage.getDataFromLocalStorage(key) : null;
}

function pairIdFromCookie(key) {
return storage.cookiesAreEnabled ? storage.getCookie(key) : null;
return storage.cookiesAreEnabled() ? storage.getCookie(key) : null;
}

/** @type {Submodule} */
Expand Down Expand Up @@ -52,7 +52,7 @@ export const pairIdSubmodule = {
try {
ids = ids.concat(JSON.parse(atob(pairIdsString)))
} catch (error) {
logError(error)
logInfo(error)
}
}

Expand All @@ -64,12 +64,12 @@ export const pairIdSubmodule = {
const obj = JSON.parse(atob(liverampValue));
ids = ids.concat(obj.envelope);
} catch (error) {
logError(error)
logInfo(error)
}
}

if (ids.length == 0) {
logError('PairId not found.')
logInfo('PairId not found.')
return undefined;
}
return {'id': ids};
Expand Down
19 changes: 16 additions & 3 deletions test/spec/modules/pairIdSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import * as utils from 'src/utils.js';

describe('pairId', function () {
let sandbox;
let logErrorStub;
let logInfoStub;

beforeEach(() => {
sandbox = sinon.sandbox.create();
logErrorStub = sandbox.stub(utils, 'logError');
logInfoStub = sandbox.stub(utils, 'logInfo');
});
afterEach(() => {
sandbox.restore();
});

it('should log an error if no ID is found when getId', function() {
pairIdSubmodule.getId({ params: {} });
expect(logErrorStub.calledOnce).to.be.true;
expect(logInfoStub.calledOnce).to.be.true;
});

it('should read pairId from local storage if exists', function() {
Expand Down Expand Up @@ -65,4 +65,17 @@ describe('pairId', function () {
}})
expect(id).to.be.deep.equal({id: pairIds})
})

it('should not get data from storage if local storage and cookies are disabled', function () {
sandbox.stub(storage, 'localStorageIsEnabled').returns(false);
sandbox.stub(storage, 'cookiesAreEnabled').returns(false);
let id = pairIdSubmodule.getId({
params: {
liveramp: {
storageKey: 'lr_pairId_custom'
}
}
})
expect(id).to.equal(undefined)
})
});