Skip to content

Commit

Permalink
fixing where product details is defined
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleysmithTTD committed Dec 13, 2024
1 parent a1f736a commit e4b6fb5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/euidSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class EUID extends SdkBase {
);
return EUID.cookieName;
}
static get EuidDetails(): ProductDetails {
private static get EuidDetails(): ProductDetails {
return productDetails;
}

Expand Down
11 changes: 5 additions & 6 deletions src/integrationTests/euidSdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import { sdkWindow, EUID, __euidInternalHandleScriptLoad, SdkOptions } from '../
import { EventType, CallbackHandler } from '../callbackManager';
import { __euidSSProviderScriptLoad } from '../secureSignalEuid';
import { UidSecureSignalProvider } from '../secureSignal_shared';
import { ProductDetails } from '../product';
import { removeConfig } from '../configManager';
import { ProductDetails } from '../product';

let callback: any;
let asyncCallback: jest.Mock<CallbackHandler>;
let euid: EUID;
let xhrMock: any;
let uid2ESP: UidSecureSignalProvider;
let secureSignalProvidersPushMock: jest.Mock<(p: any) => Promise<void>>;
Expand All @@ -26,7 +25,7 @@ jest.spyOn(document, 'URL', 'get').mockImplementation(() => mockUrl);

const makeIdentity = mocks.makeIdentityV2;

const productDetails: ProductDetails = {
const euidProductDetails: ProductDetails = {
name: 'EUID',
defaultBaseUrl: 'https://prod.euid.eu',
localStorageKey: 'EUID-sdk-identity',
Expand All @@ -38,7 +37,7 @@ const getConfigCookie = () => {
if (docCookie) {
const payload = docCookie
.split('; ')
.find((row) => row.startsWith(productDetails.cookieName + '_config' + '='));
.find((row) => row.startsWith(euidProductDetails.cookieName + '_config' + '='));
if (payload) {
return JSON.parse(decodeURIComponent(payload.split('=')[1]));
}
Expand Down Expand Up @@ -160,7 +159,7 @@ describe('Store config EUID', () => {
beforeEach(() => {
sdkWindow.__euid = new EUID();
document.cookie =
productDetails.cookieName + '_config' + '=;expires=Tue, 1 Jan 1980 23:59:59 GMT;path=/';
euidProductDetails.cookieName + '_config' + '=;expires=Tue, 1 Jan 1980 23:59:59 GMT;path=/';
});

afterEach(() => {
Expand Down Expand Up @@ -190,7 +189,7 @@ describe('Store config EUID', () => {
});
let cookie = getConfigCookie();
expect(cookie).toBeInstanceOf(Object);
removeConfig({ ...options, useCookie: true }, productDetails);
removeConfig({ ...options, useCookie: true }, euidProductDetails);
cookie = getConfigCookie();
expect(cookie).toBeNull();
});
Expand Down
27 changes: 14 additions & 13 deletions src/integrationTests/options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mocks.setupFakeTime();
const mockDomain = 'www.uidapi.com';
const mockUrl = `http://${mockDomain}/test/index.html`;

const productDetails: ProductDetails = {
const uid2ProductDetails: ProductDetails = {
name: 'UID2',
defaultBaseUrl: 'https://prod.uidapi.com',
localStorageKey: 'UID2-sdk-identity',
Expand All @@ -41,13 +41,14 @@ const getUid2Cookie = mocks.getUid2Cookie;
const getUid2LocalStorage = mocks.getUid2LocalStorage;
const removeUid2Cookie = mocks.removeUid2Cookie;
const removeUid2LocalStorage = mocks.removeUid2LocalStorage;
const getUid2 = mocks.getUid2;

const getConfigCookie = () => {
const docCookie = document.cookie;
if (docCookie) {
const payload = docCookie
.split('; ')
.find((row) => row.startsWith(productDetails.cookieName + '_config' + '='));
.find((row) => row.startsWith(uid2ProductDetails.cookieName + '_config' + '='));
if (payload) {
return JSON.parse(decodeURIComponent(payload.split('=')[1]));
}
Expand Down Expand Up @@ -75,7 +76,7 @@ describe('cookieDomain option', () => {
});

test('should not mention domain in the cookie string', () => {
const cookie = cookieMock.getSetCookieString(productDetails.cookieName);
const cookie = cookieMock.getSetCookieString(uid2ProductDetails.cookieName);
expect(cookie).not.toBe('');
expect(cookie).not.toContain('Domain=');
});
Expand All @@ -94,7 +95,7 @@ describe('cookieDomain option', () => {
});

test('should use domain in the cookie string', () => {
const cookie = cookieMock.getSetCookieString(productDetails.cookieName);
const cookie = cookieMock.getSetCookieString(uid2ProductDetails.cookieName);
expect(cookie).toContain(`Domain=${domain};`);
});
});
Expand All @@ -111,7 +112,7 @@ describe('cookiePath option', () => {
});

test('should use the default path in the cookie string', () => {
const cookie = cookieMock.getSetCookieString(productDetails.cookieName) as string;
const cookie = cookieMock.getSetCookieString(uid2ProductDetails.cookieName) as string;
expect(cookie + ';').toContain('Path=/;');
});
});
Expand All @@ -129,7 +130,7 @@ describe('cookiePath option', () => {
});

test('should use custom path in the cookie string', () => {
const cookie = cookieMock.getSetCookieString(productDetails.cookieName) as string;
const cookie = cookieMock.getSetCookieString(uid2ProductDetails.cookieName) as string;
expect(cookie + ';').toContain(`Path=${path};`);
});
});
Expand Down Expand Up @@ -357,7 +358,7 @@ describe('multiple init calls', () => {
});

test('should update cookie manager', () => {
const cookie = cookieMock.getSetCookieString(productDetails.cookieName);
const cookie = cookieMock.getSetCookieString(UID2.COOKIE_NAME);
expect(cookie).toContain(`Domain=${cookieDomain};`);
expect(cookie + ';').toContain(`Path=${newCookiePath};`);
const configCookie = getConfigCookie();
Expand Down Expand Up @@ -520,7 +521,7 @@ describe('Store config UID2', () => {
beforeEach(() => {
localStorage.removeItem('UID2-sdk-identity_config');
document.cookie =
productDetails.cookieName + '_config' + '=;expires=Tue, 1 Jan 1980 23:59:59 GMT;path=/';
uid2ProductDetails.cookieName + '_config' + '=;expires=Tue, 1 Jan 1980 23:59:59 GMT;path=/';
});

describe('when useCookie is true', () => {
Expand All @@ -529,14 +530,14 @@ describe('Store config UID2', () => {
const cookie = getConfigCookie();
expect(cookie).toBeInstanceOf(Object);
expect(cookie).toHaveProperty('cookieDomain');
const storageConfig = loadConfig(productDetails);
const storageConfig = getConfigStorage();
expect(storageConfig).toBeNull();
});
});
describe('when useCookie is false', () => {
test('should store config in local storage', () => {
uid2.init({ callback: callback, identity: identity, ...options });
const storageConfig = loadConfig(productDetails);
const storageConfig = getConfigStorage();
expect(storageConfig).toBeInstanceOf(Object);
expect(storageConfig).toHaveProperty('cookieDomain');
const cookie = getConfigCookie();
Expand All @@ -546,11 +547,11 @@ describe('Store config UID2', () => {
describe('when useCookie is false', () => {
test('can successfully clear the config in storage', () => {
uid2.init({ callback: callback, identity: identity, ...options });
let storageConfig = loadConfig(productDetails);
let storageConfig = loadConfig(uid2ProductDetails);
expect(storageConfig).toBeInstanceOf(Object);
expect(storageConfig).toHaveProperty('cookieDomain');
removeConfig(previousOptions, productDetails);
storageConfig = loadConfig(productDetails);
removeConfig(previousOptions, uid2ProductDetails);
storageConfig = loadConfig(uid2ProductDetails);
expect(storageConfig).toBeNull();
});
});
Expand Down
1 change: 0 additions & 1 deletion src/mocks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as jsdom from 'jsdom';
import { Cookie } from 'tough-cookie';
import { UID2 } from './uid2Sdk';
import { Identity } from './Identity';
import { base64ToBytes, bytesToBase64 } from './encoding/base64';
import * as crypto from 'crypto';
Expand Down

0 comments on commit e4b6fb5

Please sign in to comment.