Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dgirardi committed Jul 15, 2024
1 parent 1e2e68d commit 8475c94
Showing 1 changed file with 27 additions and 28 deletions.
55 changes: 27 additions & 28 deletions test/spec/modules/connectIdSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -549,24 +549,28 @@ describe('Yahoo ConnectID Submodule', () => {
expect(result.callback).to.be.a('function');
});

function mockOptout(value) {
getLocalStorageStub.callsFake((key) => {
if (key === 'connectIdOptOut') return value;
})
}

it('returns an undefined if the Yahoo specific opt-out key is present in local storage', () => {
localStorage.setItem('connectIdOptOut', '1');
mockOptout('1');
expect(invokeGetIdAPI({
he: HASHED_EMAIL,
pixelId: PIXEL_ID
}, consentData)).to.be.undefined;
localStorage.removeItem('connectIdOptOut');
});

it('returns an object with the callback function if the correct params are passed and Yahoo opt-out value is not "1"', () => {
localStorage.setItem('connectIdOptOut', 'true');
mockOptout('true');
let result = invokeGetIdAPI({
he: HASHED_EMAIL,
pixelId: PIXEL_ID
}, consentData);
expect(result).to.be.an('object').that.has.all.keys('callback');
expect(result.callback).to.be.a('function');
localStorage.removeItem('connectIdOptOut');
});

it('Makes an ajax GET request to the production API endpoint with pixelId and he query params', () => {
Expand Down Expand Up @@ -804,6 +808,25 @@ describe('Yahoo ConnectID Submodule', () => {
});
});
});
describe('userHasOptedOut()', () => {
it('should return a function', () => {
expect(connectIdSubmodule.userHasOptedOut).to.be.a('function');
});

it('should return false when local storage key has not been set function', () => {
expect(connectIdSubmodule.userHasOptedOut()).to.be.false;
});

it('should return true when local storage key has been set to "1"', () => {
getLocalStorageStub.returns('1');
expect(connectIdSubmodule.userHasOptedOut()).to.be.true;
});

it('should return false when local storage key has not been set to "1"', () => {
getLocalStorageStub.returns('hello');
expect(connectIdSubmodule.userHasOptedOut()).to.be.false;
});
});
});

describe('decode()', () => {
Expand Down Expand Up @@ -884,28 +907,4 @@ describe('Yahoo ConnectID Submodule', () => {
})).to.be.true;
});
});

describe('userHasOptedOut()', () => {
afterEach(() => {
localStorage.removeItem('connectIdOptOut');
});

it('should return a function', () => {
expect(connectIdSubmodule.userHasOptedOut).to.be.a('function');
});

it('should return false when local storage key has not been set function', () => {
expect(connectIdSubmodule.userHasOptedOut()).to.be.false;
});

it('should return true when local storage key has been set to "1"', () => {
localStorage.setItem('connectIdOptOut', '1');
expect(connectIdSubmodule.userHasOptedOut()).to.be.true;
});

it('should return false when local storage key has not been set to "1"', () => {
localStorage.setItem('connectIdOptOut', 'hello');
expect(connectIdSubmodule.userHasOptedOut()).to.be.false;
});
});
});

0 comments on commit 8475c94

Please sign in to comment.