diff --git a/src/constants/application-config.js b/src/constants/application-config.js index f2aff2951..489776e66 100644 --- a/src/constants/application-config.js +++ b/src/constants/application-config.js @@ -1,3 +1,4 @@ + const applicationConfig = { CONSUMER_APIGATEWAY_URL: process.env.VUE_APP_CONSUMER_API_GATEWAY, GOOGLE_PLACES_API_KEY: process.env.VUE_APP_GOOGLE_PLACES_API_KEY, @@ -5,5 +6,4 @@ const applicationConfig = { SAVED_SESSION_TIMEOUT_DAYS: 45 }; - -export { applicationConfig }; +export { applicationConfig }; \ No newline at end of file diff --git a/src/helpers/heritage-integration/cookie-helper.js b/src/helpers/heritage-integration/cookie-helper.js index 096d03a04..cee400e0c 100644 --- a/src/helpers/heritage-integration/cookie-helper.js +++ b/src/helpers/heritage-integration/cookie-helper.js @@ -1,13 +1,12 @@ import { cookieNames } from "@/constants/cookie-names"; import store from "@/store"; - /* Will update the cookie if present, or create a new one if not. */ export function updateOrCreateFunnelCookie() { // Create the cookie - document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}={}; path=/`; + document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}={}; path=/; ${getCookieDomainValue()};`; // Set up cookie with all the props. setFunnelCookieProperties({ @@ -25,13 +24,13 @@ export function updateOrCreateFunnelCookie() { /* Gets the current instance of the funnel cookie. Returns null if cookie isn't valid JSON. -*/ +*/ export function getFunnelCookie() { const cookieJson = document.cookie ?.split("; ") ?.find(row => row.startsWith(`${cookieNames.FUNNEL_SESSION_INFO}=`)) ?.split("=")[1]; - + try { return JSON.parse(cookieJson); } catch (error) { @@ -43,7 +42,8 @@ export function getFunnelCookie() { Removes cookie from browser. */ export function deleteFunnelCookie() { - document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}=; Max-Age=0; path=/; domain=${location.hostname}`; + console.log("hi there") + document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}=; Max-Age=0; path=/; ${getCookieDomainValue()}`; } /* @@ -61,8 +61,25 @@ function setFunnelCookieProperties(properties) { const cookieValueJson = JSON.stringify(cookie); - document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}=${cookieValueJson}; 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.includes("localhost")) { + return "localhost"; + } + + const urlParts = url.split('.'); + + return `.${urlParts + .slice(0) + .slice(-(urlParts.length === 4 ? 3 : 2)) + .join('.')}`; +} diff --git a/src/helpers/heritage-integration/navigation-helper.js b/src/helpers/heritage-integration/navigation-helper.js index 19e036561..12207acf4 100644 --- a/src/helpers/heritage-integration/navigation-helper.js +++ b/src/helpers/heritage-integration/navigation-helper.js @@ -1,7 +1,7 @@ import { queryStrings } from "@/constants/query-strings"; import { externalUrls } from "@/router/router-constants/externalUrl-values"; import { lazyLoadComponent } from "@/router/dynamic-routing/component-loader.js"; -import {saveOrder} from "@/helpers/heritage-integration/order-helper.js"; +import { saveOrder } from "@/helpers/heritage-integration/order-helper.js"; import store from "@/store"; import router from "@/router"; diff --git a/src/helpers/heritage-integration/order-helper.js b/src/helpers/heritage-integration/order-helper.js index aaf0db740..8dddb5436 100644 --- a/src/helpers/heritage-integration/order-helper.js +++ b/src/helpers/heritage-integration/order-helper.js @@ -10,6 +10,7 @@ import baseMixin from "@/mixins/base-mixin"; */ export async function loadOrderIfPresent() { const funnelCookie = getFunnelCookie(); + console.log(funnelCookie) // Do nothing if there is no cookie or no correlation id. if (funnelCookie == null || funnelCookie.ReferralCorrelationId == null) { @@ -20,6 +21,7 @@ export async function loadOrderIfPresent() { if (funnelCookie.ShouldResetState) { baseMixin.methods.dispatchNonBlockingStoreAction(storeActions.RESET_STATE); deleteFunnelCookie(); + console.log("sup") return null; } diff --git a/src/helpers/heritage-integration/order-helper.spec.js b/src/helpers/heritage-integration/order-helper.spec.js index 2e68867e9..cbe54ba25 100644 --- a/src/helpers/heritage-integration/order-helper.spec.js +++ b/src/helpers/heritage-integration/order-helper.spec.js @@ -13,18 +13,21 @@ describe("loadOrderIfPresent", () => { test("ShouldResetState == true => funnel cookie is deleted", () => { // Arrange + cookieHelper.deleteFunnelCookie = jest.spyOn(cookieHelper, "deleteFunnelCookie"); const testShouldResetState = true; const testCookieValue = { - ShouldResetState: testShouldResetState + ShouldResetState: testShouldResetState, + ReferralCorrelationId: "xxx" } - document.cookie = `${cookieNames.ORDER_INFO}=${JSON.stringify(testCookieValue)}; path=/; domain=${location.hostname}`; + document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}=${JSON.stringify(testCookieValue)}; path=/; ${cookieHelper.getCookieDomainValue()}`; // Act loadOrderIfPresent(); // Assert + expect(cookieHelper.deleteFunnelCookie).toHaveBeenCalled(); expect(document.cookie).toBe(""); }); @@ -94,7 +97,6 @@ describe("loadOrderIfPresent", () => { }); describe("saveOrder", () => { - afterEach(() => { removeAllTestCookies(); }); diff --git a/src/helpers/unit-test-helper.js b/src/helpers/unit-test-helper.js index 62fcc4ae4..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) { @@ -63,7 +64,7 @@ export const cookies = { export function removeAllTestCookies() { Object.keys(cookies).forEach(key => { document.cookie = `${key}=;Max-Age=0;`; - document.cookie = `${key}=;Max-Age=0;path=/`; + document.cookie = `${key}=;Max-Age=0;path=/;${getCookieDomainValue()}`; }); } @@ -78,9 +79,8 @@ export function getMockOrderInfo(mockReferralNumber, mockCorrelationId, mockRefe export function setupCookies({ funnelCookieValue = "", includeHeritageCookie = true }) { 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}; path=/;`; + document.cookie = `${key}=${cookieValue}; path=/; ${getCookieDomainValue()}`; }); } diff --git a/vue.config.js b/vue.config.js index 7bca415e3..c3cf92368 100644 --- a/vue.config.js +++ b/vue.config.js @@ -2,7 +2,6 @@ process.env.VUE_APP_CONSUMER_API_GATEWAY = "https://consumerapidev.safelite.com"; process.env.VUE_APP_HERITAGE_FUNNEL = "http://localhost:38000/default.aspx"; - process.env.VUE_APP_GOOGLE_PLACES_API_KEY = "AIzaSyDptGCkOPgN2uWJOy4ou4M33phRD4MAoJo"