diff --git a/src/helpers/heritage-integration/cookie-helper.spec.js b/src/helpers/heritage-integration/cookie-helper.spec.js index 73b3bd9bc..a20af9300 100644 --- a/src/helpers/heritage-integration/cookie-helper.spec.js +++ b/src/helpers/heritage-integration/cookie-helper.spec.js @@ -1,5 +1,5 @@ import {getConceptCookie} from "@/helpers/heritage-integration/cookie-helper.js"; -import { cookieNames } from "@/constants/cookie-names"; +import { removeAllTestCookies, setupCookies } from "@/helpers/unit-test-helper"; describe("cookies", () => { @@ -101,28 +101,4 @@ describe("cookies", () => { }); }) }) - - // document.cookie is not just a string, needs to be added individually -const cookies = { - [cookieNames.CONCEPT_SESSION_INFO]: `{"ReferralNumber":"1566818","ReferralDate":"2022-03-15T10:56:24.597","ReferralCorrelationId":"404d2b04-f86e-45c3-b373-127b6217b060","ShouldResetState":false,"DidHeritageFunnelUpdateLast":true}`, - "UNIQUE_SESSION_ID": "33756020-b58e-4ec7-b8b8-3f1576719c40", - "anotherCookie": "{}", - "someOtherCookie": "{}" - }; - - function setupCookies({ conceptCookieValue = "", includeHeritageCookie = true }) { - Object.keys(cookies).forEach(key => { - const cookieValue = key == cookieNames.CONCEPT_SESSION_INFO ? conceptCookieValue : cookies[key]; - - if (includeHeritageCookie || key != cookieNames.CONCEPT_SESSION_INFO) - document.cookie = `${key}=${cookieValue}; path=/;`; - }); - } - - function removeAllTestCookies() { - Object.keys(cookies).forEach(key => { - document.cookie = `${key}=;Max-Age=0;`; - document.cookie = `${key}=;Max-Age=0;path=/`; - }); - } \ No newline at end of file diff --git a/src/helpers/heritage-integration/navigation-helper.spec.js b/src/helpers/heritage-integration/navigation-helper.spec.js index 2c586a76f..78f91162b 100644 --- a/src/helpers/heritage-integration/navigation-helper.spec.js +++ b/src/helpers/heritage-integration/navigation-helper.spec.js @@ -2,7 +2,7 @@ import { getPageToRouteExistingOrderTo, navigateToHeritageFunnel } from "@/helpe import * as orderHelper from "@/helpers/heritage-integration/order-helper"; import { lazyLoadComponent } from "@/router/dynamic-routing/component-loader.js"; import { storeActions } from "@/constants/store-actions"; -import { setupMocksForJsFiles } from "@/helpers/unit-test-helper.js"; +import { setupMocksForJsFiles, getMockOrderInfo } from "@/helpers/unit-test-helper.js"; import { externalUrls } from "@/router/router-constants/externalUrl-values"; import store from "@/store"; @@ -300,11 +300,3 @@ describe("navigateToHeritageFunnel", () => { ); }); }); - -function getMockOrderInfo(mockReferralNumber, mockCorrelationId, mockReferralDate) { - return { - referralNumber: mockReferralNumber, - referralCorrelationId: mockCorrelationId, - referralDate: mockReferralDate - } -} diff --git a/src/helpers/heritage-integration/order-helper.spec.js b/src/helpers/heritage-integration/order-helper.spec.js index 1fa223466..1826b6da6 100644 --- a/src/helpers/heritage-integration/order-helper.spec.js +++ b/src/helpers/heritage-integration/order-helper.spec.js @@ -1,7 +1,7 @@ import * as cookieHelper from "@/helpers/heritage-integration/cookie-helper"; import { loadOrderIfPresent, saveOrder } from "@/helpers/heritage-integration/order-helper"; import { cookieNames } from "@/constants/cookie-names"; -import { setupMocksForJsFiles } from "@/helpers/unit-test-helper.js"; +import { setupMocksForJsFiles, removeAllTestCookies, getMockOrderInfo, setupCookies } from "@/helpers/unit-test-helper.js"; import { storeActions } from "@/constants/store-actions"; import router from "@/router"; @@ -153,35 +153,3 @@ describe("saveOrder", () => { expect(cookieHelper.getConceptCookie().DidHeritageFunnelUpdateLast).toEqual(false); }); }); - -// document.cookie is not just a string, needs to be added individually -const cookies = { - [cookieNames.CONCEPT_SESSION_INFO]: `{"ReferralNumber":"1566818","ReferralDate":"2022-03-15T10:56:24.597","ReferralCorrelationId":"404d2b04-f86e-45c3-b373-127b6217b060","ShouldResetState":false,"DidHeritageFunnelUpdateLast":true}`, - "UNIQUE_SESSION_ID": "33756020-b58e-4ec7-b8b8-3f1576719c40", - "anotherCookie": "{}", - "someOtherCookie": "{}" - }; - -function removeAllTestCookies() { - Object.keys(cookies).forEach(key => { - document.cookie = `${key}=;Max-Age=0;`; - document.cookie = `${key}=;Max-Age=0;path=/`; - }); -} - -function getMockOrderInfo(mockReferralNumber, mockCorrelationId, mockReferralDate) { - return { - referralNumber: mockReferralNumber, - referralCorrelationId: mockCorrelationId, - referralDate: mockReferralDate - } -} - -function setupCookies({ conceptCookieValue = "", includeHeritageCookie = true }) { - Object.keys(cookies).forEach(key => { - const cookieValue = key == cookieNames.CONCEPT_SESSION_INFO ? conceptCookieValue : cookies[key]; - - if (includeHeritageCookie || key != cookieNames.CONCEPT_SESSION_INFO) - document.cookie = `${key}=${cookieValue}; path=/;`; - }); - } \ No newline at end of file diff --git a/src/helpers/unit-test-helper.js b/src/helpers/unit-test-helper.js index 00fa5f675..699c4f8e9 100644 --- a/src/helpers/unit-test-helper.js +++ b/src/helpers/unit-test-helper.js @@ -3,15 +3,17 @@ import { storeMutations } from "@/constants/store-mutations.js"; import { navigationScenarios } from "@/router/router-constants/navigation-scenarios.js"; 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"; +// Common methods export function getMountOptions(mockData) { // Define our mocks to attached to the 'global' object for Vue/Jest. const mocks = {}; //this is mocking if you use the mixin directly(baseMixin.methods.dispatchNonBlockingStoreAction) vs this.dispatchNonBlockingStoreAction setupBaseMixinDispatchNonBlockingStoreAction(mockData); - + mocks.dispatchNonBlockingStoreAction = jest.fn(); mocks.dispatchNonBlockingStoreAction.mockImplementation((actionName) => { let actionFilterResult = mockData.actionList.filter( @@ -44,6 +46,45 @@ export function getMountOptions(mockData) { return { global }; } +export function setupMocksForJsFiles(mockData = {}) { + setupBaseMixinDispatchNonBlockingStoreAction(mockData); + + return { baseMixin }; +} + +// Heritage integration common methods +export const cookies = { + [cookieNames.CONCEPT_SESSION_INFO]: `{"ReferralNumber":"1566818","ReferralDate":"2022-03-15T10:56:24.597","ReferralCorrelationId":"404d2b04-f86e-45c3-b373-127b6217b060","ShouldResetState":false,"DidHeritageFunnelUpdateLast":true}`, + "UNIQUE_SESSION_ID": "33756020-b58e-4ec7-b8b8-3f1576719c40", + "anotherCookie": "{}", + "someOtherCookie": "{}" +}; + +export function removeAllTestCookies() { + Object.keys(cookies).forEach(key => { + document.cookie = `${key}=;Max-Age=0;`; + document.cookie = `${key}=;Max-Age=0;path=/`; + }); +} + +export function getMockOrderInfo(mockReferralNumber, mockCorrelationId, mockReferralDate) { + return { + referralNumber: mockReferralNumber, + referralCorrelationId: mockCorrelationId, + referralDate: mockReferralDate + } +} + +export function setupCookies({ conceptCookieValue = "", includeHeritageCookie = true }) { + Object.keys(cookies).forEach(key => { + const cookieValue = key == cookieNames.CONCEPT_SESSION_INFO ? conceptCookieValue : cookies[key]; + + if (includeHeritageCookie || key != cookieNames.CONCEPT_SESSION_INFO) + document.cookie = `${key}=${cookieValue}; path=/;`; + }); +} + +// Private methods function setupBaseMixinDispatchNonBlockingStoreAction(mockData) { if (mockData.actionList !== undefined) { baseMixin.methods.dispatchNonBlockingStoreAction = jest.fn(); @@ -51,7 +92,7 @@ function setupBaseMixinDispatchNonBlockingStoreAction(mockData) { let actionFilterResult = mockData.actionList.filter( (x) => x.actionName == actionName ); - + if (actionFilterResult.length > 0 && actionFilterResult.length === 1) { return Promise.resolve({ data: actionFilterResult[0].data, @@ -59,10 +100,4 @@ function setupBaseMixinDispatchNonBlockingStoreAction(mockData) { } }); } -} - -export function setupMocksForJsFiles(mockData = {}) { - setupBaseMixinDispatchNonBlockingStoreAction(mockData); - - return { baseMixin }; } \ No newline at end of file