diff --git a/modules/haloIdSystem.js b/modules/haloIdSystem.js index 926e6945436..4a0330367f5 100644 --- a/modules/haloIdSystem.js +++ b/modules/haloIdSystem.js @@ -29,6 +29,10 @@ export const haloIdSubmodule = { * @returns {{haloId:Object}} */ decode(value) { + let haloId = storage.getDataFromLocalStorage('auHaloId'); + if (utils.isStr(haloId)) { + return {haloId: haloId}; + } return (value && typeof value['haloId'] === 'string') ? { 'haloId': value['haloId'] } : undefined; }, /** diff --git a/test/spec/modules/haloIdSystem_spec.js b/test/spec/modules/haloIdSystem_spec.js index 240a83c3c83..8b6a67adee1 100644 --- a/test/spec/modules/haloIdSystem_spec.js +++ b/test/spec/modules/haloIdSystem_spec.js @@ -4,6 +4,16 @@ import * as utils from 'src/utils.js'; describe('HaloIdSystem', function () { describe('getId', function() { + let getDataFromLocalStorageStub; + + beforeEach(function() { + getDataFromLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage'); + }); + + afterEach(function () { + getDataFromLocalStorageStub.restore(); + }); + it('gets a haloId', function() { const config = { params: {} @@ -21,7 +31,8 @@ describe('HaloIdSystem', function () { const config = { params: {} }; - storage.setDataInLocalStorage('auHaloId', 'tstCachedHaloId1'); + getDataFromLocalStorageStub.withArgs('auHaloId').returns('tstCachedHaloId1'); + const callbackSpy = sinon.spy(); const callback = haloIdSubmodule.getId(config).callback; callback(callbackSpy);