diff --git a/src/helpers/heritage-integration/cookie-helper.spec.js b/src/helpers/heritage-integration/cookie-helper.spec.js index 8abd265e5..349b2206a 100644 --- a/src/helpers/heritage-integration/cookie-helper.spec.js +++ b/src/helpers/heritage-integration/cookie-helper.spec.js @@ -5,6 +5,8 @@ import { getSessionIdValue, setCookieProperties, regenerateDeviceId, + getUserIdValue, + regenerateUserId, } from "@/helpers/heritage-integration/cookie-helper.js"; import { cookieNames } from "@/constants/cookie-names"; 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", () => { //Arrange - setCookieProperties({ - [cookieNames.DXDEV]: "did=f4a1a9e8-b3f3-4936-8c30-2f06a98644af&tz=-300&tzd=1", - }, {}); + setCookieProperties( + { + [cookieNames.DXDEV]: + "did=f4a1a9e8-b3f3-4936-8c30-2f06a98644af&tz=-300&tzd=1", + }, + {} + ); //Act 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", () => { // Arrange setupCookies({}); diff --git a/src/helpers/unit-test-helper.js b/src/helpers/unit-test-helper.js index 457dd47fb..2cd580df0 100644 --- a/src/helpers/unit-test-helper.js +++ b/src/helpers/unit-test-helper.js @@ -141,7 +141,7 @@ export function setupCookies({ funnelCookieValue = "", includeHeritageCookie = t export function setupCrypto(mockValue) { global.crypto = { - randomUUID: jest.fn() + randomUUID: jest.fn(), }; global.crypto.randomUUID.mockImplementation(() => mockValue);