Skip to content

Commit b866140

Browse files
removing use of COOKIE NAME in our code
1 parent 2cf7c20 commit b866140

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

src/integrationTests/euidSdk.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,19 @@ jest.spyOn(document, 'URL', 'get').mockImplementation(() => mockUrl);
2626

2727
const makeIdentity = mocks.makeIdentityV2;
2828

29+
const productDetails: ProductDetails = {
30+
name: 'EUID',
31+
defaultBaseUrl: 'https://prod.euid.eu',
32+
localStorageKey: 'EUID-sdk-identity',
33+
cookieName: '__euid',
34+
};
35+
2936
const getConfigCookie = () => {
3037
const docCookie = document.cookie;
3138
if (docCookie) {
3239
const payload = docCookie
3340
.split('; ')
34-
.find((row) => row.startsWith(EUID.COOKIE_NAME + '_config' + '='));
41+
.find((row) => row.startsWith(productDetails.cookieName + '_config' + '='));
3542
if (payload) {
3643
return JSON.parse(decodeURIComponent(payload.split('=')[1]));
3744
}
@@ -150,13 +157,6 @@ describe('Store config EUID', () => {
150157
useCookie: false,
151158
};
152159

153-
const productDetails: ProductDetails = {
154-
cookieName: '__euid',
155-
defaultBaseUrl: 'http://test-host',
156-
localStorageKey: 'EUID-sdk-identity',
157-
name: 'EUID',
158-
};
159-
160160
beforeEach(() => {
161161
sdkWindow.__euid = new EUID();
162162
document.cookie =

src/integrationTests/options.test.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -515,12 +515,7 @@ describe('Store config UID2', () => {
515515
refreshRetryPeriod: 1000,
516516
useCookie: false,
517517
};
518-
const productDetails: ProductDetails = {
519-
cookieName: '__uid2',
520-
defaultBaseUrl: 'http://test-host',
521-
localStorageKey: 'UID2-sdk-identity',
522-
name: 'UID2',
523-
};
518+
524519
const previousOptions: SdkOptions = options;
525520

526521
beforeEach(() => {

src/mocks.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,18 @@ import { UID2 } from './uid2Sdk';
44
import { Identity } from './Identity';
55
import { base64ToBytes, bytesToBase64 } from './encoding/base64';
66
import * as crypto from 'crypto';
7+
import { ProductDetails } from './product';
78

89
const uid2LocalStorageKeyName = 'UID2-sdk-identity';
910
const euidLocalStorageKeyName = 'EUID-sdk-identity';
1011

12+
const uid2ProductDetails: ProductDetails = {
13+
name: 'UID2',
14+
defaultBaseUrl: 'https://prod.uidapi.com',
15+
localStorageKey: 'UID2-sdk-identity',
16+
cookieName: '__uid_2',
17+
};
18+
1119
export class CookieMock {
1220
jar: jsdom.CookieJar;
1321
url: string;
@@ -281,7 +289,7 @@ export function setCookieMock(document: Document) {
281289
}
282290

283291
export function setUid2Cookie(value: any) {
284-
document.cookie = UID2.COOKIE_NAME + '=' + encodeURIComponent(JSON.stringify(value));
292+
document.cookie = uid2ProductDetails.cookieName + '=' + encodeURIComponent(JSON.stringify(value));
285293
}
286294

287295
export function removeUid2Cookie() {
@@ -304,7 +312,9 @@ export function setUid2(value: any, useCookie?: boolean) {
304312
export function getUid2Cookie() {
305313
const docCookie = document.cookie;
306314
if (docCookie) {
307-
const payload = docCookie.split('; ').find((row) => row.startsWith(UID2.COOKIE_NAME + '='));
315+
const payload = docCookie
316+
.split('; ')
317+
.find((row) => row.startsWith(uid2ProductDetails.cookieName + '='));
308318
if (payload) {
309319
return JSON.parse(decodeURIComponent(payload.split('=')[1]));
310320
}

0 commit comments

Comments
 (0)