common method refactor

This commit is contained in:
FrankRua 2022-03-29 09:21:17 -04:00
parent c50e21a2a7
commit 7e51f4be92
4 changed files with 46 additions and 75 deletions

View file

@ -1,5 +1,5 @@
import {getConceptCookie} from "@/helpers/heritage-integration/cookie-helper.js"; 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", () => { describe("cookies", () => {
@ -102,27 +102,3 @@ 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=/`;
});
}

View file

@ -2,7 +2,7 @@ import { getPageToRouteExistingOrderTo, navigateToHeritageFunnel } from "@/helpe
import * as orderHelper from "@/helpers/heritage-integration/order-helper"; import * as orderHelper from "@/helpers/heritage-integration/order-helper";
import { lazyLoadComponent } from "@/router/dynamic-routing/component-loader.js"; import { lazyLoadComponent } from "@/router/dynamic-routing/component-loader.js";
import { storeActions } from "@/constants/store-actions"; 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 { externalUrls } from "@/router/router-constants/externalUrl-values";
import store from "@/store"; import store from "@/store";
@ -300,11 +300,3 @@ describe("navigateToHeritageFunnel", () => {
); );
}); });
}); });
function getMockOrderInfo(mockReferralNumber, mockCorrelationId, mockReferralDate) {
return {
referralNumber: mockReferralNumber,
referralCorrelationId: mockCorrelationId,
referralDate: mockReferralDate
}
}

View file

@ -1,7 +1,7 @@
import * as cookieHelper from "@/helpers/heritage-integration/cookie-helper"; import * as cookieHelper from "@/helpers/heritage-integration/cookie-helper";
import { loadOrderIfPresent, saveOrder } from "@/helpers/heritage-integration/order-helper"; import { loadOrderIfPresent, saveOrder } from "@/helpers/heritage-integration/order-helper";
import { cookieNames } from "@/constants/cookie-names"; 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 { storeActions } from "@/constants/store-actions";
import router from "@/router"; import router from "@/router";
@ -153,35 +153,3 @@ describe("saveOrder", () => {
expect(cookieHelper.getConceptCookie().DidHeritageFunnelUpdateLast).toEqual(false); 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=/;`;
});
}

View file

@ -3,8 +3,10 @@ import { storeMutations } from "@/constants/store-mutations.js";
import { navigationScenarios } from "@/router/router-constants/navigation-scenarios.js"; import { navigationScenarios } from "@/router/router-constants/navigation-scenarios.js";
import { vehicleCategories } from "@/constants/vehicle-categories.js"; import { vehicleCategories } from "@/constants/vehicle-categories.js";
import { fmgPageValues } from "@/router/router-constants/fmgPage-values"; import { fmgPageValues } from "@/router/router-constants/fmgPage-values";
import { cookieNames } from "@/constants/cookie-names";
import baseMixin from "@/mixins/base-mixin"; import baseMixin from "@/mixins/base-mixin";
// Common methods
export function getMountOptions(mockData) { export function getMountOptions(mockData) {
// Define our mocks to attached to the 'global' object for Vue/Jest. // Define our mocks to attached to the 'global' object for Vue/Jest.
const mocks = {}; const mocks = {};
@ -44,6 +46,45 @@ export function getMountOptions(mockData) {
return { global }; 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) { function setupBaseMixinDispatchNonBlockingStoreAction(mockData) {
if (mockData.actionList !== undefined) { if (mockData.actionList !== undefined) {
baseMixin.methods.dispatchNonBlockingStoreAction = jest.fn(); baseMixin.methods.dispatchNonBlockingStoreAction = jest.fn();
@ -60,9 +101,3 @@ function setupBaseMixinDispatchNonBlockingStoreAction(mockData) {
}); });
} }
} }
export function setupMocksForJsFiles(mockData = {}) {
setupBaseMixinDispatchNonBlockingStoreAction(mockData);
return { baseMixin };
}