Merge remote-tracking branch 'origin/feature/CSR-98' into feature/CSR-99
This commit is contained in:
commit
d4db5e00f3
4 changed files with 89 additions and 65 deletions
|
|
@ -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 { storeActions } from "@/constants/store-actions.js";
|
||||||
import { cookieNames } from "@/constants/cookie-names";
|
import { cookieNames } from "@/constants/cookie-names";
|
||||||
import { queryStrings } from "@/constants/query-strings";
|
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
|
This will also set Referral information in the store after saving, and then
|
||||||
update the cookie.
|
update the cookie.
|
||||||
*/
|
*/
|
||||||
export async function saveOrder() {
|
async function saveOrder() {
|
||||||
console.log("saving order...");
|
console.log("saving order...");
|
||||||
const savedOrderInfo = await baseMixin.methods.dispatchNonBlockingStoreAction(storeActions.SAVE_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.
|
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....");
|
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.
|
// Do nothing if there is no cookie or no correlation id.
|
||||||
if (conceptCookie === null || conceptCookie.ReferralCorrelationId === null) {
|
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
|
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.
|
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 the user is coming in via the Safelite.Com CTA
|
||||||
if (toRoute.query[queryStrings.START_TYPE] === 'fmg') {
|
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.
|
Will update the cookie if present, or create a new one if not.
|
||||||
*/
|
*/
|
||||||
export function updateOrCreateConceptCookie() {
|
function updateOrCreateConceptCookie() {
|
||||||
console.log("Updating cookie...", {
|
console.log("Updating cookie...", {
|
||||||
LastTouched: new Date().toUTCString(),
|
LastTouched: new Date().toUTCString(),
|
||||||
SavedQuoteTimeoutDate: store.getters.applicationUser.savedSessionTimeout,
|
SavedQuoteTimeoutDate: store.getters.applicationUser.savedSessionTimeout,
|
||||||
|
|
@ -141,7 +144,7 @@ export function updateOrCreateConceptCookie() {
|
||||||
Method to determine if our analytics session has timed out or not.
|
Method to determine if our analytics session has timed out or not.
|
||||||
Amount used for timeout is configurable in application-config.js
|
Amount used for timeout is configurable in application-config.js
|
||||||
*/
|
*/
|
||||||
export function isAnalyticsSessionStillActive() {
|
function isAnalyticsSessionStillActive() {
|
||||||
if (getConceptCookie() !== null) {
|
if (getConceptCookie() !== null) {
|
||||||
const lastTouchedValue = getConceptCookie().LastTouched;
|
const lastTouchedValue = getConceptCookie().LastTouched;
|
||||||
const timeoutAmount = applicationConfig.ANALYTICS_SESSION_TIMEOUT;
|
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
|
Note: That time for saved session timeout is configurable in application-config.js
|
||||||
*/
|
*/
|
||||||
export function isSavedSessionStillActive() {
|
function isSavedSessionStillActive() {
|
||||||
if (getConceptCookie() !== null) {
|
if (getConceptCookie() !== null) {
|
||||||
const savedSessionTimeStamp = new Date(getConceptCookie().SavedQuoteTimeoutDate);
|
const savedSessionTimeStamp = new Date(getConceptCookie().SavedQuoteTimeoutDate);
|
||||||
const isSavedSessionTimedOut = (new Date(new Date().toUTCString()) > savedSessionTimeStamp);
|
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.
|
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.
|
// Create the order (or save existing order) when navigating to Heritage Funnel.
|
||||||
// console.log(exports)
|
// console.log(exports)
|
||||||
await self.saveOrder();
|
// await self.saveOrder();
|
||||||
|
await exportFunctions.saveOrder();
|
||||||
|
|
||||||
router.navigateToExternalUrl(
|
router.navigateToExternalUrl(
|
||||||
externalUrls.HERITAGE_FUNNEL,
|
externalUrls.HERITAGE_FUNNEL,
|
||||||
{
|
{
|
||||||
corid: store.getters.order.referralCorrelationId,
|
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.
|
Gets the current instance of the concept funnel cookie.
|
||||||
Returns null if cookie isn't valid JSON.
|
Returns null if cookie isn't valid JSON.
|
||||||
*/
|
*/
|
||||||
export function getConceptCookie() {
|
function getConceptCookie() {
|
||||||
const cookieJson = document.cookie
|
const cookieJson = document.cookie
|
||||||
?.split("; ")
|
?.split("; ")
|
||||||
?.find(row => row.startsWith(`${cookieNames.CONCEPT_SESSION_INFO}=`))
|
?.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.
|
Function to get the date for the saved session timeout.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function getDateForSavedSessionTimeout() {
|
function getDateForSavedSessionTimeout() {
|
||||||
const currentDate = new Date(new Date().toUTCString())
|
const currentDate = new Date(new Date().toUTCString())
|
||||||
currentDate.setDate(currentDate.getDate() + applicationConfig.SAVED_SESSION_TIMEOUT)
|
currentDate.setDate(currentDate.getDate() + applicationConfig.SAVED_SESSION_TIMEOUT)
|
||||||
return currentDate.toUTCString();
|
return currentDate.toUTCString();
|
||||||
|
|
@ -270,4 +277,16 @@ function deleteConceptCookie() {
|
||||||
document.cookie = `${cookieNames.CONCEPT_SESSION_INFO}=; Max-Age=0; path=/; domain=${location.hostname}`;
|
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;
|
||||||
|
|
@ -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 { cookieNames } from "@/constants/cookie-names";
|
||||||
import { setupMocksForJsFiles } from "@/helpers/unit-test-helper.js";
|
import { setupMocksForJsFiles } from "@/helpers/unit-test-helper.js";
|
||||||
import { storeActions } from "@/constants/store-actions";
|
import { storeActions } from "@/constants/store-actions";
|
||||||
|
|
@ -37,8 +37,9 @@ describe("loadOrderIfPresent", () => {
|
||||||
|
|
||||||
test("ShouldResetState == true => reset store", () => {
|
test("ShouldResetState == true => reset store", () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const getConceptCookieMethod = jest.spyOn(helper, "getConceptCookie")
|
// helper.getConceptCookie = jest.fn().mockReturnValueOnce({ ShouldResetState: true, DidHeritageFunnelUpdateLast: false });
|
||||||
getConceptCookieMethod.mockImplementation(() => { return { 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 = {
|
const mockData = {
|
||||||
actionList: [{
|
actionList: [{
|
||||||
|
|
@ -46,47 +47,49 @@ describe("loadOrderIfPresent", () => {
|
||||||
}],
|
}],
|
||||||
}
|
}
|
||||||
|
|
||||||
setupMocksForJsFiles(mockData);
|
var mocks = 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);
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
helper.loadOrderIfPresent();
|
helper.loadOrderIfPresent();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
expect(helper.getConceptCookie).toHaveBeenCalled();
|
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", () => {
|
describe("saveOrder", () => {
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
removeAllTestCookies();
|
removeAllTestCookies();
|
||||||
|
// jest.resetAllMocks();
|
||||||
|
// jest.unmock("@/helpers/heritage-integration-helper");
|
||||||
|
// // helper.getConceptCookie = jest.fn().mockImplementation(arg => arg)
|
||||||
});
|
});
|
||||||
|
|
||||||
test("saveOrder => should set state order values", async () => {
|
test("saveOrder => should set state order values", async () => {
|
||||||
|
|
@ -137,7 +140,7 @@ describe("saveOrder", () => {
|
||||||
data: mockOrderInfo,
|
data: mockOrderInfo,
|
||||||
}],
|
}],
|
||||||
router: router
|
router: router
|
||||||
}
|
};
|
||||||
|
|
||||||
setupMocksForJsFiles(mockData);
|
setupMocksForJsFiles(mockData);
|
||||||
|
|
||||||
|
|
@ -154,6 +157,10 @@ describe("saveOrder", () => {
|
||||||
// Act
|
// Act
|
||||||
await helper.saveOrder();
|
await helper.saveOrder();
|
||||||
|
|
||||||
|
console.log(document.cookie)
|
||||||
|
console.log(helper.getConceptCookie)
|
||||||
|
console.log(helper.getConceptCookie())
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
expect(helper.getConceptCookie().DidHeritageFunnelUpdateLast).toEqual(false);
|
expect(helper.getConceptCookie().DidHeritageFunnelUpdateLast).toEqual(false);
|
||||||
});
|
});
|
||||||
|
|
@ -334,7 +341,7 @@ describe("getPageToRouteExistingOrderTo", () => {
|
||||||
|
|
||||||
// Mock out the lazy load calls for all components.
|
// Mock out the lazy load calls for all components.
|
||||||
lazyLoadComponent
|
lazyLoadComponent
|
||||||
.mockReturnValueOnce(() => {
|
.mockReturnValueOnce(() => {
|
||||||
return {
|
return {
|
||||||
default: {
|
default: {
|
||||||
methods: {
|
methods: {
|
||||||
|
|
@ -342,8 +349,8 @@ describe("getPageToRouteExistingOrderTo", () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.mockReturnValueOnce(() => {
|
.mockReturnValueOnce(() => {
|
||||||
return {
|
return {
|
||||||
default: {
|
default: {
|
||||||
methods: {
|
methods: {
|
||||||
|
|
@ -351,8 +358,8 @@ describe("getPageToRouteExistingOrderTo", () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.mockReturnValueOnce(() => {
|
.mockReturnValueOnce(() => {
|
||||||
return {
|
return {
|
||||||
default: {
|
default: {
|
||||||
methods: {
|
methods: {
|
||||||
|
|
@ -360,8 +367,8 @@ describe("getPageToRouteExistingOrderTo", () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.mockReturnValueOnce(() => {
|
.mockReturnValueOnce(() => {
|
||||||
return {
|
return {
|
||||||
default: {
|
default: {
|
||||||
methods: {
|
methods: {
|
||||||
|
|
@ -369,7 +376,7 @@ describe("getPageToRouteExistingOrderTo", () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
const result = await helper.getPageToRouteExistingOrderTo(toRoute, false);
|
const result = await helper.getPageToRouteExistingOrderTo(toRoute, false);
|
||||||
|
|
@ -386,7 +393,7 @@ describe("getPageToRouteExistingOrderTo", () => {
|
||||||
|
|
||||||
// Mock out the lazy load calls for all components.
|
// Mock out the lazy load calls for all components.
|
||||||
lazyLoadComponent
|
lazyLoadComponent
|
||||||
.mockReturnValueOnce(() => {
|
.mockReturnValueOnce(() => {
|
||||||
return {
|
return {
|
||||||
default: {
|
default: {
|
||||||
methods: {
|
methods: {
|
||||||
|
|
@ -394,8 +401,8 @@ describe("getPageToRouteExistingOrderTo", () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.mockReturnValueOnce(() => {
|
.mockReturnValueOnce(() => {
|
||||||
return {
|
return {
|
||||||
default: {
|
default: {
|
||||||
methods: {
|
methods: {
|
||||||
|
|
@ -403,8 +410,8 @@ describe("getPageToRouteExistingOrderTo", () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.mockReturnValueOnce(() => {
|
.mockReturnValueOnce(() => {
|
||||||
return {
|
return {
|
||||||
default: {
|
default: {
|
||||||
methods: {
|
methods: {
|
||||||
|
|
@ -412,8 +419,8 @@ describe("getPageToRouteExistingOrderTo", () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.mockReturnValueOnce(() => {
|
.mockReturnValueOnce(() => {
|
||||||
return {
|
return {
|
||||||
default: {
|
default: {
|
||||||
methods: {
|
methods: {
|
||||||
|
|
@ -421,7 +428,7 @@ describe("getPageToRouteExistingOrderTo", () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
store.getters.damage.isRepair = false;
|
store.getters.damage.isRepair = false;
|
||||||
store.getters.vehicle.carId = 'C00000';
|
store.getters.vehicle.carId = 'C00000';
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import { storeActions } from "@/constants/store-actions";
|
||||||
import { lazyLoadComponent } from "@/router/dynamic-routing/component-loader.js";
|
import { lazyLoadComponent } from "@/router/dynamic-routing/component-loader.js";
|
||||||
import { routingTable } from "@/router/router-constants/routing-table.js";
|
import { routingTable } from "@/router/router-constants/routing-table.js";
|
||||||
import { globalEvents, globalEventTypes } from "@/constants/events";
|
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 baseMixin from "@/mixins/base-mixin";
|
||||||
import eventBus from "@/helpers/event-bus/event-bus";
|
import eventBus from "@/helpers/event-bus/event-bus";
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,6 @@ import { getDateForSavedSessionTimeout } from "@/helpers/heritage-integration-he
|
||||||
import createPersistedState from "vuex-persistedstate";
|
import createPersistedState from "vuex-persistedstate";
|
||||||
import globalMethods from "@/global-methods";
|
import globalMethods from "@/global-methods";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Export State
|
// Export State
|
||||||
const getDefaultState = () => {
|
const getDefaultState = () => {
|
||||||
return {
|
return {
|
||||||
|
|
@ -55,7 +53,7 @@ const getDefaultState = () => {
|
||||||
applicationUser: {
|
applicationUser: {
|
||||||
eventBus: [],
|
eventBus: [],
|
||||||
pageData: {},
|
pageData: {},
|
||||||
savedSessionTimeout: getDateForSavedSessionTimeout()
|
// savedSessionTimeout: getDateForSavedSessionTimeout() TODO CSR-98
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue