diff --git a/src/helpers/heritage-integration-helper.js b/src/helpers/heritage-integration-helper.js index 2eedb001e..f4ae1c1a2 100644 --- a/src/helpers/heritage-integration-helper.js +++ b/src/helpers/heritage-integration-helper.js @@ -1,4 +1,4 @@ -import * as self from "./heritage-integration-helper"; +// import * as self from "./heritage-integration-helper"; import { storeActions } from "@/constants/store-actions.js"; import { cookieNames } from "@/constants/cookie-names"; import { queryStrings } from "@/constants/query-strings"; @@ -14,7 +14,7 @@ import baseMixin from "../mixins/base-mixin"; This will also set Referral information in the store after saving, and then update the cookie. */ -export async function saveOrder() { +async function saveOrder() { console.log("saving order..."); const savedOrderInfo = await baseMixin.methods.dispatchNonBlockingStoreAction(storeActions.SAVE_ORDER); @@ -35,9 +35,12 @@ export async function saveOrder() { it will reset the state and go back to the start of the funnel. */ -export async function loadOrderIfPresent() { +async function loadOrderIfPresent() { console.log("attempting to load referral...."); - const conceptCookie = self.getConceptCookie(); + // const conceptCookie = self.getConceptCookie(); + const conceptCookie = exportFunctions.getConceptCookie(); + + console.log(conceptCookie) // Do nothing if there is no cookie or no correlation id. if (conceptCookie === null || conceptCookie.ReferralCorrelationId === null) { @@ -64,7 +67,7 @@ export async function loadOrderIfPresent() { drop them so they don't start at the beginning again. This method will return 'heritage' if the user has an existing order and they come back in from the Safelite.com CTA. */ -export async function getPageToRouteExistingOrderTo(toRoute = {}, existingHeritageOrder = false) { +async function getPageToRouteExistingOrderTo(toRoute = {}, existingHeritageOrder = false) { // If the user is coming in via the Safelite.Com CTA if (toRoute.query[queryStrings.START_TYPE] === 'fmg') { @@ -110,7 +113,7 @@ export async function getPageToRouteExistingOrderTo(toRoute = {}, existingHerita /* Will update the cookie if present, or create a new one if not. */ -export function updateOrCreateConceptCookie() { +function updateOrCreateConceptCookie() { console.log("Updating cookie...", { LastTouched: new Date().toUTCString(), SavedQuoteTimeoutDate: store.getters.applicationUser.savedSessionTimeout, @@ -141,7 +144,7 @@ export function updateOrCreateConceptCookie() { Method to determine if our analytics session has timed out or not. Amount used for timeout is configurable in application-config.js */ -export function isAnalyticsSessionStillActive() { +function isAnalyticsSessionStillActive() { if (getConceptCookie() !== null) { const lastTouchedValue = getConceptCookie().LastTouched; const timeoutAmount = applicationConfig.ANALYTICS_SESSION_TIMEOUT; @@ -162,7 +165,7 @@ export function isAnalyticsSessionStillActive() { Note: That time for saved session timeout is configurable in application-config.js */ -export function isSavedSessionStillActive() { +function isSavedSessionStillActive() { if (getConceptCookie() !== null) { const savedSessionTimeStamp = new Date(getConceptCookie().SavedQuoteTimeoutDate); const isSavedSessionTimedOut = (new Date(new Date().toUTCString()) > savedSessionTimeStamp); @@ -181,17 +184,21 @@ export function isSavedSessionStillActive() { Used to navigate to the heritage funnel with the correct query string and url. */ -export async function navigateToHeritageFunnel() { +async function navigateToHeritageFunnel() { // Create the order (or save existing order) when navigating to Heritage Funnel. // console.log(exports) - await self.saveOrder(); + // await self.saveOrder(); + await exportFunctions.saveOrder(); router.navigateToExternalUrl( externalUrls.HERITAGE_FUNNEL, { corid: store.getters.order.referralCorrelationId, - src: "concept-funnel" + src: "concept-funnel", + // TODO CSR-28, remove this + cns: "all", + experiments: "RemoveServiceAreaPage=ServAreaRemoval_V7=ServAreaNoRemove_V7_TEST=true,ConceptFunnel=ConceptFunnel_V1=ConceptFunnel_TEST=true" } ); } @@ -200,7 +207,7 @@ export async function navigateToHeritageFunnel() { Gets the current instance of the concept funnel cookie. Returns null if cookie isn't valid JSON. */ -export function getConceptCookie() { +function getConceptCookie() { const cookieJson = document.cookie ?.split("; ") ?.find(row => row.startsWith(`${cookieNames.CONCEPT_SESSION_INFO}=`)) @@ -217,7 +224,7 @@ export function getConceptCookie() { Function to get the date for the saved session timeout. */ -export function getDateForSavedSessionTimeout() { +function getDateForSavedSessionTimeout() { const currentDate = new Date(new Date().toUTCString()) currentDate.setDate(currentDate.getDate() + applicationConfig.SAVED_SESSION_TIMEOUT) return currentDate.toUTCString(); @@ -270,4 +277,16 @@ function deleteConceptCookie() { document.cookie = `${cookieNames.CONCEPT_SESSION_INFO}=; Max-Age=0; path=/; domain=${location.hostname}`; } +const exportFunctions = { + saveOrder, + loadOrderIfPresent, + getPageToRouteExistingOrderTo, + updateOrCreateConceptCookie, + isAnalyticsSessionStillActive, + isSavedSessionStillActive, + navigateToHeritageFunnel, + getConceptCookie, + getDateForSavedSessionTimeout +}; +export default exportFunctions; \ No newline at end of file diff --git a/src/helpers/heritage-integration-helper.spec.js b/src/helpers/heritage-integration-helper.spec.js index 58ea971bb..7d6de90c2 100644 --- a/src/helpers/heritage-integration-helper.spec.js +++ b/src/helpers/heritage-integration-helper.spec.js @@ -1,4 +1,4 @@ -import * as helper from "@/helpers/heritage-integration-helper"; +import helper from "@/helpers/heritage-integration-helper"; import { cookieNames } from "@/constants/cookie-names"; import { setupMocksForJsFiles } from "@/helpers/unit-test-helper.js"; import { storeActions } from "@/constants/store-actions"; @@ -37,8 +37,9 @@ describe("loadOrderIfPresent", () => { test("ShouldResetState == true => reset store", () => { // Arrange - const getConceptCookieMethod = jest.spyOn(helper, "getConceptCookie") - getConceptCookieMethod.mockImplementation(() => { return { ShouldResetState: true, DidHeritageFunnelUpdateLast: false } }); + // helper.getConceptCookie = jest.fn().mockReturnValueOnce({ ShouldResetState: true, DidHeritageFunnelUpdateLast: false }); + helper.getConceptCookie = jest.spyOn(helper, "getConceptCookie").mockReturnValueOnce({ ShouldResetState: true, ReferralCorrelationId: "xxx-xxx-xxx"}); + // store.dispatch = jest.spyOn(store, "dispatch"); const mockData = { actionList: [{ @@ -46,47 +47,49 @@ describe("loadOrderIfPresent", () => { }], } - setupMocksForJsFiles(mockData); - - // Act - helper.loadOrderIfPresent(); - - // Assert - expect(getConceptCookieMethod).toHaveBeenCalled(); - expect(baseMixin.methods.dispatchNonBlockingStoreAction).toHaveBeenCalledWith(storeActions.RESET_STATE); - - getConceptCookieMethod.mockRestore(); - }); - - test("Concept cookie is null => store is unchanged", () => { - // Arrange - const getConceptCookieMethod = jest.spyOn(helper, "getConceptCookie") - getConceptCookieMethod.mockImplementation(() => null); - - store.dispatch = jest.spyOn(store, "dispatch"); - - const mockData = { - actionList: [{ - actionName: storeActions.RESET_STATE - }], - } - - setupMocksForJsFiles(mockData); + var mocks = setupMocksForJsFiles(mockData); // Act helper.loadOrderIfPresent(); // Assert expect(helper.getConceptCookie).toHaveBeenCalled(); - expect(store.dispatch).not.toHaveBeenCalledWith(storeActions.RESET_STATE); + expect(mocks.baseMixin.methods.dispatchNonBlockingStoreAction).toHaveBeenCalledWith(storeActions.RESET_STATE); - getConceptCookieMethod.mockRestore(); + helper.getConceptCookie.mockRestore(); + // store.dispatch.mockRestore(); + }); + + test("Concept cookie is null => store is unchanged", () => { + // Arrange + helper.getConceptCookie = jest.spyOn(helper, "getConceptCookie").mockReturnValueOnce(null); + // store.dispatch = jest.spyOn(store, "dispatch"); + + const mockData = { + actionList: [{ + actionName: storeActions.RESET_STATE + }], + } + + var mocks = setupMocksForJsFiles(mockData); + + // Act + helper.loadOrderIfPresent(); + + // Assert + expect(helper.getConceptCookie).toHaveBeenCalled(); + expect(mocks.baseMixin.methods.dispatchNonBlockingStoreAction).not.toHaveBeenCalledWith(storeActions.RESET_STATE); + + helper.getConceptCookie.mockRestore(); }); }); describe("saveOrder", () => { afterEach(() => { removeAllTestCookies(); + // jest.resetAllMocks(); + // jest.unmock("@/helpers/heritage-integration-helper"); + // // helper.getConceptCookie = jest.fn().mockImplementation(arg => arg) }); test("saveOrder => should set state order values", async () => { @@ -137,7 +140,7 @@ describe("saveOrder", () => { data: mockOrderInfo, }], router: router - } + }; setupMocksForJsFiles(mockData); @@ -154,6 +157,10 @@ describe("saveOrder", () => { // Act await helper.saveOrder(); + console.log(document.cookie) + console.log(helper.getConceptCookie) + console.log(helper.getConceptCookie()) + // Assert expect(helper.getConceptCookie().DidHeritageFunnelUpdateLast).toEqual(false); }); @@ -334,7 +341,7 @@ describe("getPageToRouteExistingOrderTo", () => { // Mock out the lazy load calls for all components. lazyLoadComponent - .mockReturnValueOnce(() => { + .mockReturnValueOnce(() => { return { default: { methods: { @@ -342,8 +349,8 @@ describe("getPageToRouteExistingOrderTo", () => { } } } - }) - .mockReturnValueOnce(() => { + }) + .mockReturnValueOnce(() => { return { default: { methods: { @@ -351,8 +358,8 @@ describe("getPageToRouteExistingOrderTo", () => { } } } - }) - .mockReturnValueOnce(() => { + }) + .mockReturnValueOnce(() => { return { default: { methods: { @@ -360,8 +367,8 @@ describe("getPageToRouteExistingOrderTo", () => { } } } - }) - .mockReturnValueOnce(() => { + }) + .mockReturnValueOnce(() => { return { default: { methods: { @@ -369,7 +376,7 @@ describe("getPageToRouteExistingOrderTo", () => { } } } - }); + }); // Act const result = await helper.getPageToRouteExistingOrderTo(toRoute, false); @@ -386,7 +393,7 @@ describe("getPageToRouteExistingOrderTo", () => { // Mock out the lazy load calls for all components. lazyLoadComponent - .mockReturnValueOnce(() => { + .mockReturnValueOnce(() => { return { default: { methods: { @@ -394,8 +401,8 @@ describe("getPageToRouteExistingOrderTo", () => { } } } - }) - .mockReturnValueOnce(() => { + }) + .mockReturnValueOnce(() => { return { default: { methods: { @@ -403,8 +410,8 @@ describe("getPageToRouteExistingOrderTo", () => { } } } - }) - .mockReturnValueOnce(() => { + }) + .mockReturnValueOnce(() => { return { default: { methods: { @@ -412,8 +419,8 @@ describe("getPageToRouteExistingOrderTo", () => { } } } - }) - .mockReturnValueOnce(() => { + }) + .mockReturnValueOnce(() => { return { default: { methods: { @@ -421,7 +428,7 @@ describe("getPageToRouteExistingOrderTo", () => { } } } - }); + }); store.getters.damage.isRepair = false; store.getters.vehicle.carId = 'C00000'; diff --git a/src/router/index.js b/src/router/index.js index e0701d095..51e010980 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -4,7 +4,7 @@ import { storeActions } from "@/constants/store-actions"; import { lazyLoadComponent } from "@/router/dynamic-routing/component-loader.js"; import { routingTable } from "@/router/router-constants/routing-table.js"; import { globalEvents, globalEventTypes } from "@/constants/events"; -import * as heritageIntegrationHelper from "@/helpers/heritage-integration-helper"; +import heritageIntegrationHelper from "@/helpers/heritage-integration-helper"; import baseMixin from "@/mixins/base-mixin"; import eventBus from "@/helpers/event-bus/event-bus"; diff --git a/src/store/index.js b/src/store/index.js index 27c252995..5d2a0a422 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -5,8 +5,6 @@ import { getDateForSavedSessionTimeout } from "@/helpers/heritage-integration-he import createPersistedState from "vuex-persistedstate"; import globalMethods from "@/global-methods"; - - // Export State const getDefaultState = () => { return { @@ -55,7 +53,7 @@ const getDefaultState = () => { applicationUser: { eventBus: [], pageData: {}, - savedSessionTimeout: getDateForSavedSessionTimeout() + // savedSessionTimeout: getDateForSavedSessionTimeout() TODO CSR-98 }, } };