From 1e40e0e1f8e2582255d88e990d5a0c13a34e8347 Mon Sep 17 00:00:00 2001 From: Katie Date: Wed, 30 Mar 2022 13:11:42 -0400 Subject: [PATCH] CSR-98 Fix tests --- .../heritage-integration/cookie-helper.js | 10 +++++--- .../heritage-integration/order-helper.spec.js | 4 +--- src/helpers/unit-test-helper.js | 24 ++++--------------- 3 files changed, 12 insertions(+), 26 deletions(-) diff --git a/src/helpers/heritage-integration/cookie-helper.js b/src/helpers/heritage-integration/cookie-helper.js index d8cda8a67..18632fc51 100644 --- a/src/helpers/heritage-integration/cookie-helper.js +++ b/src/helpers/heritage-integration/cookie-helper.js @@ -6,7 +6,7 @@ import store from "@/store"; */ export function updateOrCreateFunnelCookie() { // Create the cookie - document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}={}; domain=${getDomainWithoutSubdomain()}; path=/;`; + document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}={}; path=/; ${getCookieDomainValue()};`; // Set up cookie with all the props. setFunnelCookieProperties({ @@ -46,7 +46,7 @@ export function getFunnelCookie() { Removes cookie from browser. */ export function deleteFunnelCookie() { - document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}=; Max-Age=0; domain=${getDomainWithoutSubdomain()}; path=/`; + document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}=; Max-Age=0; path=/; ${getCookieDomainValue()}`; } /* @@ -64,11 +64,15 @@ function setFunnelCookieProperties(properties) { const cookieValueJson = JSON.stringify(cookie); - document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}=${cookieValueJson}; domain=${getDomainWithoutSubdomain()}; path=/`; + document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}=${cookieValueJson}; path=/; ${getCookieDomainValue()}`; } } } +export function getCookieDomainValue() { + return location.hostname.includes("localhost") ? "" : `domain=${getDomainWithoutSubdomain()};`; +} + function getDomainWithoutSubdomain() { let url = location.hostname; if (url == "localhost") { diff --git a/src/helpers/heritage-integration/order-helper.spec.js b/src/helpers/heritage-integration/order-helper.spec.js index 5de25b6c0..382132bbe 100644 --- a/src/helpers/heritage-integration/order-helper.spec.js +++ b/src/helpers/heritage-integration/order-helper.spec.js @@ -132,7 +132,7 @@ describe("saveOrder", () => { }, false); }); - test.only("saveOrder => should update DidHeritageFunnelUpdateLast cookie value to false", async () => { + test("saveOrder => should update DidHeritageFunnelUpdateLast cookie value to false", async () => { // Arrange const testReferralNumber = 1566818; const testReferralDate = "2022-03-15T10:56:24.597"; @@ -160,8 +160,6 @@ describe("saveOrder", () => { setupCookies({ funnelCookieValue: JSON.stringify(testCookieValue) }); - console.log(document.cookie) - // Act await saveOrder(); diff --git a/src/helpers/unit-test-helper.js b/src/helpers/unit-test-helper.js index 13ef9d632..7b81cca00 100644 --- a/src/helpers/unit-test-helper.js +++ b/src/helpers/unit-test-helper.js @@ -5,6 +5,7 @@ import { vehicleCategories } from "@/constants/vehicle-categories.js"; import { fmgPageValues } from "@/router/router-constants/fmgPage-values"; import { cookieNames } from "@/constants/cookie-names"; import baseMixin from "@/mixins/base-mixin"; +import { getCookieDomainValue } from "@/helpers/heritage-integration/cookie-helper"; // Common methods export function getMountOptions(mockData) { @@ -62,8 +63,8 @@ export const cookies = { export function removeAllTestCookies() { Object.keys(cookies).forEach(key => { - document.cookie = `${key}=;Max-Age=0;domain=${getDomainWithoutSubdomain()};`; - document.cookie = `${key}=;Max-Age=0;domain=${getDomainWithoutSubdomain()};path=/`; + document.cookie = `${key}=;Max-Age=0;`; + document.cookie = `${key}=;Max-Age=0;path=/;${getCookieDomainValue()}`; }); } @@ -79,10 +80,8 @@ export function setupCookies({ funnelCookieValue = "", includeHeritageCookie = t Object.keys(cookies).forEach(key => { const cookieValue = key == cookieNames.FUNNEL_SESSION_INFO ? funnelCookieValue : cookies[key]; if (includeHeritageCookie || key != cookieNames.FUNNEL_SESSION_INFO) - document.cookie = `${key}=${cookieValue}; domain=${getDomainWithoutSubdomain()}; path=/;`; + document.cookie = `${key}=${cookieValue}; path=/; ${getCookieDomainValue()}`; }); - - console.log(document.cookie) } // Private methods @@ -101,19 +100,4 @@ function setupBaseMixinDispatchNonBlockingStoreAction(mockData) { } }); } -} - - -function getDomainWithoutSubdomain() { - let url = location.hostname; - if (url == "localhost") { - return "localhost"; - } - - const urlParts = url.split('.'); - - return `.${urlParts - .slice(0) - .slice(-(urlParts.length === 4 ? 3 : 2)) - .join('.')}`; } \ No newline at end of file