Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZeopTapId: Fix broken unit tests #5758

Merged
merged 1 commit into from
Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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