Skip to content

Commit

Permalink
fix broken unit tests for zeotap (#5758)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertrmartinez authored Sep 16, 2020
1 parent 9452050 commit bfb182a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 33 deletions.
2 changes: 1 addition & 1 deletion modules/zeotapIdPlusIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {submodule} from '../src/hook.js';
import { getStorageManager } from '../src/storageManager.js';

const ZEOTAP_COOKIE_NAME = 'IDP';
const storage = getStorageManager();
export const storage = getStorageManager();

function readCookie() {
return storage.cookiesAreEnabled ? storage.getCookie(ZEOTAP_COOKIE_NAME) : null;
Expand Down
51 changes: 19 additions & 32 deletions test/spec/modules/zeotapIdPlusIdSystem_spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { expect } from 'chai';
import find from 'core-js-pure/features/array/find.js';
import { config } from 'src/config.js';
import { newStorageManager } from 'src/storageManager.js';
import { init, requestBidsHook, setSubmoduleRegistry } from 'modules/userId/index.js';
import { zeotapIdPlusSubmodule } from 'modules/zeotapIdPlusIdSystem.js';

const storage = newStorageManager();
import { storage, zeotapIdPlusSubmodule } from 'modules/zeotapIdPlusIdSystem.js';

const ZEOTAP_COOKIE_NAME = 'IDP';
const ZEOTAP_COOKIE = 'THIS-IS-A-DUMMY-COOKIE';
Expand Down Expand Up @@ -37,35 +34,34 @@ function getAdUnitMock(code = 'adUnit-code') {
};
}

function unsetCookie() {
storage.setCookie(ZEOTAP_COOKIE_NAME, '');
}
describe('Zeotap ID System', function() {
let getDataFromLocalStorageStub, localStorageIsEnabledStub;
let getCookieStub, cookiesAreEnabledStub;
beforeEach(function () {
getDataFromLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage');
localStorageIsEnabledStub = sinon.stub(storage, 'localStorageIsEnabled');
getCookieStub = sinon.stub(storage, 'getCookie');
cookiesAreEnabledStub = sinon.stub(storage, 'cookiesAreEnabled');
});

function unsetLocalStorage() {
storage.setDataInLocalStorage(ZEOTAP_COOKIE_NAME, '');
}
afterEach(function () {
getDataFromLocalStorageStub.restore();
localStorageIsEnabledStub.restore();
getCookieStub.restore();
cookiesAreEnabledStub.restore();
});

describe('Zeotap ID System', function() {
describe('test method: getId', function() {
afterEach(() => {
unsetCookie();
unsetLocalStorage();
})

it('provides the stored Zeotap id if a cookie exists', function() {
storage.setCookie(
ZEOTAP_COOKIE_NAME,
ENCODED_ZEOTAP_COOKIE,
(new Date(Date.now() + 5000).toUTCString()),
);
getCookieStub.withArgs(ZEOTAP_COOKIE_NAME).returns(ENCODED_ZEOTAP_COOKIE);
let id = zeotapIdPlusSubmodule.getId();
expect(id).to.deep.equal({
id: ENCODED_ZEOTAP_COOKIE
});
});

it('provides the stored Zeotap id if cookie is absent but present in local storage', function() {
storage.setDataInLocalStorage(ZEOTAP_COOKIE_NAME, ENCODED_ZEOTAP_COOKIE);
getDataFromLocalStorageStub.withArgs(ZEOTAP_COOKIE_NAME).returns(ENCODED_ZEOTAP_COOKIE);
let id = zeotapIdPlusSubmodule.getId();
expect(id).to.deep.equal({
id: ENCODED_ZEOTAP_COOKIE
Expand Down Expand Up @@ -103,19 +99,10 @@ describe('Zeotap ID System', function() {

beforeEach(function() {
adUnits = [getAdUnitMock()];
storage.setCookie(
ZEOTAP_COOKIE_NAME,
ENCODED_ZEOTAP_COOKIE,
(new Date(Date.now() + 5000).toUTCString()),
);
setSubmoduleRegistry([zeotapIdPlusSubmodule]);
init(config);
config.setConfig(getConfigMock());
});

afterEach(function() {
unsetCookie();
unsetLocalStorage();
getCookieStub.withArgs(ZEOTAP_COOKIE_NAME).returns(ENCODED_ZEOTAP_COOKIE);
});

it('when a stored Zeotap ID exists it is added to bids', function(done) {
Expand Down

0 comments on commit bfb182a

Please sign in to comment.