From 7635599d717723c648543e6e199402540745a459 Mon Sep 17 00:00:00 2001 From: Anthony Lauzon Date: Tue, 20 Apr 2021 10:41:08 -0500 Subject: [PATCH] use sinon local storage stubs for haloid module (#6619) --- modules/haloIdSystem.js | 4 ++++ test/spec/modules/haloIdSystem_spec.js | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) 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);