Skip to content

Commit

Permalink
use sinon local storage stubs for haloid module (#6619)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony Lauzon authored Apr 20, 2021
1 parent 1696773 commit 7635599
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions modules/haloIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
/**
Expand Down
13 changes: 12 additions & 1 deletion test/spec/modules/haloIdSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}
Expand All @@ -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);
Expand Down

0 comments on commit 7635599

Please sign in to comment.