Skip to content

Commit

Permalink
Zeotap id plus gvlid (prebid#6260)
Browse files Browse the repository at this point in the history
* Add gvlid for ZeotapIdPlus module

* Pass gvlid and module name to storage manager

* add testcases to zeotapIdPlusIdSystem

* remove unwanted code
  • Loading branch information
shikharsharma-zeotap authored and icflournoy committed Feb 5, 2021
1 parent e5bcea4 commit f039c1f
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 5 deletions.
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

0 comments on commit f039c1f

Please sign in to comment.