UserId + Formatting
This commit is contained in:
parent
f45d73e297
commit
aa59d955cb
2 changed files with 60 additions and 4 deletions
|
|
@ -5,6 +5,8 @@ import {
|
||||||
getSessionIdValue,
|
getSessionIdValue,
|
||||||
setCookieProperties,
|
setCookieProperties,
|
||||||
regenerateDeviceId,
|
regenerateDeviceId,
|
||||||
|
getUserIdValue,
|
||||||
|
regenerateUserId,
|
||||||
} from "@/helpers/heritage-integration/cookie-helper.js";
|
} from "@/helpers/heritage-integration/cookie-helper.js";
|
||||||
import { cookieNames } from "@/constants/cookie-names";
|
import { cookieNames } from "@/constants/cookie-names";
|
||||||
import { removeAllTestCookies, setupCookies, setupCrypto } from "@/helpers/unit-test-helper";
|
import { removeAllTestCookies, setupCookies, setupCrypto } from "@/helpers/unit-test-helper";
|
||||||
|
|
@ -139,9 +141,13 @@ describe("cookies", () => {
|
||||||
|
|
||||||
test("Should return id even if cookie contains other data", () => {
|
test("Should return id even if cookie contains other data", () => {
|
||||||
//Arrange
|
//Arrange
|
||||||
setCookieProperties({
|
setCookieProperties(
|
||||||
[cookieNames.DXDEV]: "did=f4a1a9e8-b3f3-4936-8c30-2f06a98644af&tz=-300&tzd=1",
|
{
|
||||||
}, {});
|
[cookieNames.DXDEV]:
|
||||||
|
"did=f4a1a9e8-b3f3-4936-8c30-2f06a98644af&tz=-300&tzd=1",
|
||||||
|
},
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
const result = getDeviceIdValue();
|
const result = getDeviceIdValue();
|
||||||
|
|
@ -178,6 +184,56 @@ describe("cookies", () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("User Id", () => {
|
||||||
|
describe("getUserIdValue", () => {
|
||||||
|
test("Should return GUID", () => {
|
||||||
|
// Arrange
|
||||||
|
setupCookies({});
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const result = getUserIdValue();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
expect(result).toBe("11aec5e8-92ba-4dc9-a8b6-179a916d8d7a");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("Should return 0s if unset", () => {
|
||||||
|
//Arrange
|
||||||
|
//Act
|
||||||
|
const result = getUserIdValue();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
expect(result).toBe("00000000-0000-0000-0000-000000000000");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("regenerateUserId", () => {
|
||||||
|
test("Generates a new id if unset", () => {
|
||||||
|
// Arrange
|
||||||
|
// Act
|
||||||
|
regenerateUserId();
|
||||||
|
const result = getUserIdValue();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(result).not.toBe("00000000-0000-0000-0000-000000000000");
|
||||||
|
expect(global.crypto.randomUUID).toBeCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("Does not create a new id if already set", () => {
|
||||||
|
// Arrange
|
||||||
|
setupCookies({});
|
||||||
|
|
||||||
|
// Act
|
||||||
|
regenerateUserId();
|
||||||
|
const result = getUserIdValue();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(result).toBe("11aec5e8-92ba-4dc9-a8b6-179a916d8d7a");
|
||||||
|
expect(global.crypto.randomUUID).not.toBeCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test("getSessionKeyValue, should return session key int", () => {
|
test("getSessionKeyValue, should return session key int", () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
setupCookies({});
|
setupCookies({});
|
||||||
|
|
|
||||||
|
|
@ -141,7 +141,7 @@ export function setupCookies({ funnelCookieValue = "", includeHeritageCookie = t
|
||||||
|
|
||||||
export function setupCrypto(mockValue) {
|
export function setupCrypto(mockValue) {
|
||||||
global.crypto = {
|
global.crypto = {
|
||||||
randomUUID: jest.fn()
|
randomUUID: jest.fn(),
|
||||||
};
|
};
|
||||||
|
|
||||||
global.crypto.randomUUID.mockImplementation(() => mockValue);
|
global.crypto.randomUUID.mockImplementation(() => mockValue);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue