diff --git a/src/helpers/heritage-integration-helper.js b/src/helpers/heritage-integration-helper.js index 64a42d0a5..14dacb8eb 100644 --- a/src/helpers/heritage-integration-helper.js +++ b/src/helpers/heritage-integration-helper.js @@ -36,7 +36,7 @@ export async function saveOrder() { */ export async function loadOrderIfPresent() { console.log("attempting to load referral...."); - const conceptCookie = getConceptCookie(); + const conceptCookie = this.getConceptCookie(); // Do nothing if there is no cookie or no correlation id. if (conceptCookie === null || conceptCookie.ReferralCorrelationId === null) { @@ -180,7 +180,7 @@ export function isSavedSessionStillActive() { export async function navigateToHeritageFunnel() { // Create the order (or save existing order) when navigating to Heritage Funnel. - await saveOrder(); + await this.saveOrder(); router.navigateToExternalUrl( externalUrls.HERITAGE_FUNNEL, diff --git a/src/helpers/heritage-integration-helper.spec.js b/src/helpers/heritage-integration-helper.spec.js index 6e7f4f818..ff91d68c6 100644 --- a/src/helpers/heritage-integration-helper.spec.js +++ b/src/helpers/heritage-integration-helper.spec.js @@ -7,13 +7,14 @@ import store from "@/store"; import router from "@/router"; import { navigationScenarios } from "@/router/router-constants/navigation-scenarios"; import baseMixin from "@/mixins/base-mixin"; +import { externalUrls } from "@/router/router-constants/externalUrl-values"; -describe("loadReferralFromHeritageFunnelIfPresent", () => { +describe("loadOrderIfPresent", () => { afterEach(() => { removeAllTestCookies(); }); - test("ShouldResetState == true => heritage cookie is deleted", () => { + test("ShouldResetState == true => concept cookie is deleted", () => { // Arrange const testShouldResetState = true; @@ -24,7 +25,7 @@ describe("loadReferralFromHeritageFunnelIfPresent", () => { document.cookie = `${cookieNames.ORDER_INFO}=${JSON.stringify(testCookieValue)}; path=/; domain=${location.hostname}`; // Act - helper.loadReferralFromHeritageFunnelIfPresent(); + helper.loadOrderIfPresent(); // Assert expect(document.cookie).toBe(""); @@ -32,8 +33,8 @@ describe("loadReferralFromHeritageFunnelIfPresent", () => { test("ShouldResetState == true => reset store", () => { // Arrange - const getHeritageCookieValueMethod = jest.spyOn(helper, "getHeritageCookieValue") - getHeritageCookieValueMethod.mockImplementation(() => { return { ShouldResetState: true, DidHeritageFunnelUpdateLast: false } }); + const getConceptCookieMethod = jest.spyOn(helper, "getConceptCookie") + getConceptCookieMethod.mockImplementation(() => { return { ShouldResetState: true, DidHeritageFunnelUpdateLast: false } }); const mockData = { actionList: [{ @@ -44,20 +45,19 @@ describe("loadReferralFromHeritageFunnelIfPresent", () => { setupMocksForJsFiles(mockData); // Act - helper.loadReferralFromHeritageFunnelIfPresent(); + helper.loadOrderIfPresent(); // Assert - expect(getHeritageCookieValueMethod).toHaveBeenCalled(); + expect(getConceptCookieMethod).toHaveBeenCalled(); expect(baseMixin.methods.dispatchNonBlockingStoreAction).toHaveBeenCalledWith(storeActions.RESET_STATE); - getHeritageCookieValueMethod.mockRestore(); - // store.dispatch.mockRestore(); + getConceptCookieMethod.mockRestore(); }); - test("Heritage cookie is null => store is unchanged", () => { + test("Concept cookie is null => store is unchanged", () => { // Arrange - const getHeritageCookieValueMethod = jest.spyOn(helper, "getHeritageCookieValue") - getHeritageCookieValueMethod.mockImplementation(() => null); + const getConceptCookieMethod = jest.spyOn(helper, "getConceptCookie") + getConceptCookieMethod.mockImplementation(() => null); store.dispatch = jest.spyOn(store, "dispatch"); @@ -70,14 +70,13 @@ describe("loadReferralFromHeritageFunnelIfPresent", () => { setupMocksForJsFiles(mockData); // Act - helper.loadReferralFromHeritageFunnelIfPresent(); + helper.loadOrderIfPresent(); // Assert - expect(helper.getHeritageCookieValue).toHaveBeenCalled(); + expect(helper.getConceptCookie).toHaveBeenCalled(); expect(store.dispatch).not.toHaveBeenCalledWith(storeActions.RESET_STATE); - getHeritageCookieValueMethod.mockRestore(); - store.dispatch.mockRestore(); + getConceptCookieMethod.mockRestore(); }); }); @@ -113,11 +112,12 @@ describe("saveOrder", () => { await helper.saveOrder(); // Assert + expect(mocks.baseMixin.methods.dispatchNonBlockingStoreAction).toHaveBeenCalledWith(storeActions.SAVE_ORDER); expect(mocks.baseMixin.methods.dispatchNonBlockingStoreAction).toHaveBeenCalledWith(storeActions.SET_REFERRAL_INFORMATION, { referralNumber: mockReferralNumber, referralDate: mockReferralDate, referralCorrelationId: mockCorrelationId - }); + }, false); }); test("saveOrder => should update DidHeritageFunnelUpdateLast cookie value to false", async () => { @@ -146,13 +146,13 @@ describe("saveOrder", () => { DidHeritageFunnelUpdateLast: true } - setupCookies({ heritageCookieValue: JSON.stringify(testCookieValue) }); + setupCookies({ conceptCookieValue: JSON.stringify(testCookieValue) }); // Act await helper.saveOrder(); // Assert - expect(helper.getHeritageCookieValue().DidHeritageFunnelUpdateLast).toEqual(false); + expect(helper.getConceptCookie().DidHeritageFunnelUpdateLast).toEqual(false); }); }); @@ -169,12 +169,12 @@ describe("navigateToHeritageFunnel", () => { actionList: [{ actionName: storeActions.SAVE_ORDER, data: mockOrderInfo, - }], - router: router + }] } setupMocksForJsFiles(mockData); const saveOrderFunction = jest.spyOn(helper, "saveOrder"); + router.navigateToExternalUrl = jest.fn(); // Act await helper.navigateToHeritageFunnel(); @@ -184,7 +184,7 @@ describe("navigateToHeritageFunnel", () => { // Should alway save before we navigate to heritage const saveOrderFunctionCallOrder = saveOrderFunction.mock.invocationCallOrder[0]; - const routerNavigateFunctionCallOrder = router.navigate.mock.invocationCallOrder[0]; + const routerNavigateFunctionCallOrder = router.navigateToExternalUrl.mock.invocationCallOrder[0]; expect(saveOrderFunctionCallOrder).toBeLessThan(routerNavigateFunctionCallOrder); saveOrderFunction.mockRestore(); }); @@ -201,18 +201,21 @@ describe("navigateToHeritageFunnel", () => { actionList: [{ actionName: storeActions.SAVE_ORDER, data: mockOrderInfo, - }], - router: router + }] } - const mocks = setupMocksForJsFiles(mockData); + setupMocksForJsFiles(mockData); + + store.getters.order.referralCorrelationId = mockCorrelationId + + router.navigateToExternalUrl = jest.fn(); // Act await helper.navigateToHeritageFunnel(); // Assert - expect(router.navigate).toHaveBeenCalled(); - expect(router.navigate).toHaveBeenCalledWith(navigationScenarios.MOVE_TO_HERITAGE_FUNNEL, expect.anything(), + expect(router.navigateToExternalUrl).toHaveBeenCalled(); + expect(router.navigateToExternalUrl).toHaveBeenCalledWith(externalUrls.HERITAGE_FUNNEL, expect.objectContaining({ corid: mockCorrelationId }) @@ -225,7 +228,7 @@ describe("cookies", () => { removeAllTestCookies(); }) - describe("getHeritageCookieValue method", () => { + describe("getConceptCookie method", () => { test("gets correct value when cookie is present", () => { // Arrange const testReferralNumber = 1566818; @@ -241,10 +244,10 @@ describe("cookies", () => { ShouldResetState: testShouldResetState, DidHeritageFunnelUpdateLast: testDidHeritageFunnelUpdateLast } - setupCookies({ heritageCookieValue: JSON.stringify(testCookieValue) }); + setupCookies({ conceptCookieValue: JSON.stringify(testCookieValue) }); // Act - var result = helper.getHeritageCookieValue(); + var result = helper.getConceptCookie(); // Assert expect(result).toEqual(testCookieValue); @@ -259,10 +262,10 @@ describe("cookies", () => { test("returns empty object when value is empty object", () => { // Arrange const testCookieValue = {}; - setupCookies({ heritageCookieValue: JSON.stringify(testCookieValue) }); + setupCookies({ conceptCookieValue: JSON.stringify(testCookieValue) }); // Act - var result = helper.getHeritageCookieValue(); + var result = helper.getConceptCookie(); // Assert expect(result).toEqual(testCookieValue); @@ -273,21 +276,21 @@ describe("cookies", () => { test("returns null when value is empty string", () => { // Arrange const testCookieValue = ""; - setupCookies({ heritageCookieValue: testCookieValue }); + setupCookies({ conceptCookieValue: testCookieValue }); // Act - var result = helper.getHeritageCookieValue(); + var result = helper.getConceptCookie(); // Assert expect(result).toEqual(null); }); - test("returns null when heritage cookie doesn't exist", () => { + test("returns null when concept cookie doesn't exist", () => { // Arrange setupCookies({ includeHeritageCookie: false }); // Act - var result = helper.getHeritageCookieValue(); + var result = helper.getConceptCookie(); // Assert expect(result).toEqual(null); @@ -297,10 +300,10 @@ describe("cookies", () => { // Arrange const testCookieValue = { test: "testValue" }; - setupCookies({ heritageCookieValue: JSON.stringify(testCookieValue) }); + setupCookies({ conceptCookieValue: JSON.stringify(testCookieValue) }); // Act - const actualCookieValue = helper.getHeritageCookieValue(); + const actualCookieValue = helper.getConceptCookie(); // Assert expect(actualCookieValue).toEqual(testCookieValue); @@ -311,7 +314,7 @@ describe("cookies", () => { setupCookies({ includeHeritageCookie: false }); // Act - const actualCookieValue = helper.getHeritageCookieValue(); + const actualCookieValue = helper.getConceptCookie(); // Assert expect(actualCookieValue).toBeNull(); @@ -330,9 +333,9 @@ const cookies = { "addshoppers.com": "2%7C1%3A0%7C10%3A1646681050%7C15%3Aaddshoppers.com%7C44%3AODM1OTczNWI0MmFjNGNmMmExNDY3OWRlNTQ1NmM5MGY%3D%7Cef2a50fafe40fc5abf641a14ee5541c70bef2950666f59d3a809fd9352c7b963" }; -function setupCookies({ heritageCookieValue = "", includeHeritageCookie = true }) { +function setupCookies({ conceptCookieValue = "", includeHeritageCookie = true }) { Object.keys(cookies).forEach(key => { - const cookieValue = key == cookieNames.CONCEPT_SESSION_INFO ? heritageCookieValue : cookies[key]; + const cookieValue = key == cookieNames.CONCEPT_SESSION_INFO ? conceptCookieValue : cookies[key]; if (includeHeritageCookie || key != cookieNames.CONCEPT_SESSION_INFO) document.cookie = `${key}=${cookieValue}; path=/;`; diff --git a/src/helpers/unit-test-helper.js b/src/helpers/unit-test-helper.js index 046f9e435..20ee5990a 100644 --- a/src/helpers/unit-test-helper.js +++ b/src/helpers/unit-test-helper.js @@ -81,8 +81,5 @@ function setupBaseMixinDispatchNonBlockingStoreAction(mockData) { export function setupMocksForJsFiles(mockData = {}) { setupBaseMixinDispatchNonBlockingStoreAction(mockData); - if (mockData.router) - mockData.router.navigate = jest.fn(); - return { baseMixin }; } \ No newline at end of file diff --git a/src/store/index.js b/src/store/index.js index b4deed056..27c252995 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -173,7 +173,7 @@ export const mutations = { // Misc Mutations setLoadOrderInformation(state, orderInformation) { state.order.referralNumber = orderInformation.referralNumber; - state.order.referralDate = orderInformation.referralDate; + state.order.referralDate = orderInformation.referralDate; state.order.referralCorrelationId = orderInformation.referralCorrelationId; state.order.vehicle = { year: orderInformation.vehicle?.year, @@ -383,7 +383,7 @@ export const actions = { }); }, - loadOrder(context, {referralNumber, referralDate, referralCorrelationId}) { + loadOrder(context, { referralNumber, referralDate, referralCorrelationId }) { return globalMethods.callHttpClient({ method: endpoints.LoadOrder.method, endpoint: endpoints.LoadOrder.url,