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

Zeotap id plus gvlid #6260

Merged
merged 4 commits into from
Feb 4, 2021
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
20 changes: 16 additions & 4 deletions modules/zeotapIdPlusIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,35 @@ import {submodule} from '../src/hook.js';
import { getStorageManager } from '../src/storageManager.js';

const ZEOTAP_COOKIE_NAME = 'IDP';
export const storage = getStorageManager();
const ZEOTAP_VENDOR_ID = 301;
const ZEOTAP_MODULE_NAME = 'zeotapIdPlus';

function readCookie() {
return storage.cookiesAreEnabled ? storage.getCookie(ZEOTAP_COOKIE_NAME) : null;
return storage.cookiesAreEnabled() ? storage.getCookie(ZEOTAP_COOKIE_NAME) : null;
}

function readFromLocalStorage() {
return storage.localStorageIsEnabled ? storage.getDataFromLocalStorage(ZEOTAP_COOKIE_NAME) : null;
return storage.localStorageIsEnabled() ? storage.getDataFromLocalStorage(ZEOTAP_COOKIE_NAME) : null;
}

export function getStorage() {
return getStorageManager(ZEOTAP_VENDOR_ID, ZEOTAP_MODULE_NAME);
}

export const storage = getStorage();

/** @type {Submodule} */
export const zeotapIdPlusSubmodule = {
/**
* used to link submodule with config
* @type {string}
*/
name: 'zeotapIdPlus',
name: ZEOTAP_MODULE_NAME,
/**
* Vendor ID of Zeotap
* @type {Number}
*/
gvlid: ZEOTAP_VENDOR_ID,
/**
* decode the stored id value for passing to bid requests
* @function
Expand Down
64 changes: 63 additions & 1 deletion test/spec/modules/zeotapIdPlusIdSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { expect } from 'chai';
import find from 'core-js-pure/features/array/find.js';
import { config } from 'src/config.js';
import { init, requestBidsHook, setSubmoduleRegistry } from 'modules/userId/index.js';
import { storage, zeotapIdPlusSubmodule } from 'modules/zeotapIdPlusIdSystem.js';
import { storage, getStorage, zeotapIdPlusSubmodule } from 'modules/zeotapIdPlusIdSystem.js';
import * as storageManager from 'src/storageManager.js';

const ZEOTAP_COOKIE_NAME = 'IDP';
const ZEOTAP_COOKIE = 'THIS-IS-A-DUMMY-COOKIE';
Expand Down Expand Up @@ -43,6 +44,67 @@ function unsetLocalStorage() {
}

describe('Zeotap ID System', function() {
describe('Zeotap Module invokes StorageManager with appropriate arguments', function() {
let getStorageManagerSpy;

beforeEach(function() {
getStorageManagerSpy = sinon.spy(storageManager, 'getStorageManager');
});

it('when a stored Zeotap ID exists it is added to bids', function() {
let store = getStorage();
expect(getStorageManagerSpy.calledOnce).to.be.true;
sinon.assert.calledWith(getStorageManagerSpy, 301, 'zeotapIdPlus');
});
});

describe('test method: getId calls storage methods to fetch ID', function() {
let cookiesAreEnabledStub;
let getCookieStub;
let localStorageIsEnabledStub;
let getDataFromLocalStorageStub;

beforeEach(() => {
cookiesAreEnabledStub = sinon.stub(storage, 'cookiesAreEnabled');
getCookieStub = sinon.stub(storage, 'getCookie');
localStorageIsEnabledStub = sinon.stub(storage, 'localStorageIsEnabled');
getDataFromLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage');
});

afterEach(() => {
storage.cookiesAreEnabled.restore();
storage.getCookie.restore();
storage.localStorageIsEnabled.restore();
storage.getDataFromLocalStorage.restore();
unsetCookie();
unsetLocalStorage();
});

it('should check if cookies are enabled', function() {
let id = zeotapIdPlusSubmodule.getId();
expect(cookiesAreEnabledStub.calledOnce).to.be.true;
});

it('should call getCookie if cookies are enabled', function() {
cookiesAreEnabledStub.returns(true);
let id = zeotapIdPlusSubmodule.getId();
expect(cookiesAreEnabledStub.calledOnce).to.be.true;
expect(getCookieStub.calledOnce).to.be.true;
sinon.assert.calledWith(getCookieStub, 'IDP');
});

it('should check for localStorage if cookies are disabled', function() {
cookiesAreEnabledStub.returns(false);
localStorageIsEnabledStub.returns(true)
let id = zeotapIdPlusSubmodule.getId();
expect(cookiesAreEnabledStub.calledOnce).to.be.true;
expect(getCookieStub.called).to.be.false;
expect(localStorageIsEnabledStub.calledOnce).to.be.true;
expect(getDataFromLocalStorageStub.calledOnce).to.be.true;
sinon.assert.calledWith(getDataFromLocalStorageStub, 'IDP');
});
});

describe('test method: getId', function() {
afterEach(() => {
unsetCookie();
Expand Down