CSR-98 Save only when user is moving to or has visited heritage
This commit is contained in:
parent
442125ed65
commit
2b6d22fd71
5 changed files with 306 additions and 28 deletions
|
|
@ -8,9 +8,13 @@ import baseMixin from "../mixins/base-mixin";
|
|||
|
||||
// Read info from heritage funnel and reset state or load referral
|
||||
export function handleInfoFromHeritageFunnel() {
|
||||
var orderInfo = getHeritageCookieValue();
|
||||
const orderInfo = getHeritageCookieValue();
|
||||
console.log("A")
|
||||
console.log(orderInfo)
|
||||
console.log(document.cookie)
|
||||
|
||||
if (orderInfo?.ShouldResetState) {
|
||||
console.log("B")
|
||||
store.dispatch(storeActions.RESET_STATE);
|
||||
deleteHeritageCookie();
|
||||
}
|
||||
|
|
@ -21,10 +25,13 @@ export function handleInfoFromHeritageFunnel() {
|
|||
// ShouldResetState: false
|
||||
// })
|
||||
}
|
||||
|
||||
console.log("D")
|
||||
}
|
||||
|
||||
export function navigateToHeritageFunnel() {
|
||||
var referralCorrelationId = store.getters.referralCorrelationId;
|
||||
export async function navigateToHeritageFunnel() {
|
||||
await saveOrder();
|
||||
const referralCorrelationId = store.getters.referralCorrelationId;
|
||||
|
||||
router.navigate(
|
||||
navigationScenarios.MOVE_TO_HERITAGE_FUNNEL,
|
||||
|
|
@ -40,7 +47,8 @@ export function navigateToHeritageFunnel() {
|
|||
}
|
||||
|
||||
export async function saveOrder() {
|
||||
var savedOrderInfo = (await baseMixin.methods.dispatchNonBlockingStoreAction(storeActions.SAVE_ORDER)).data;
|
||||
console.log("HI")
|
||||
const savedOrderInfo = (await baseMixin.methods.dispatchNonBlockingStoreAction(storeActions.SAVE_ORDER)).data;
|
||||
store.commit(storeMutations.UPDATE_REFERRAL_NUMBER, savedOrderInfo.referralNumber);
|
||||
store.commit(storeMutations.UPDATE_REFERRAL_DATE, savedOrderInfo.referralDate);
|
||||
store.commit(storeMutations.UPDATE_REFERRAL_CORRELATION_ID, savedOrderInfo.referralCorrelationId);
|
||||
|
|
@ -51,16 +59,23 @@ export async function saveOrder() {
|
|||
}
|
||||
|
||||
/* Start cookie related functions */
|
||||
function getHeritageCookieValue() {
|
||||
var cookieJson = document.cookie
|
||||
export function getHeritageCookieValue() {
|
||||
console.log("A")
|
||||
const cookieJson = document.cookie
|
||||
?.split("; ")
|
||||
?.find(row => row.startsWith(`${cookieNames.ORDER_INFO}=`))
|
||||
?.split("=")[1];
|
||||
|
||||
return cookieJson == null ? null : JSON.parse(cookieJson);
|
||||
|
||||
try {
|
||||
return JSON.parse(cookieJson);
|
||||
} catch(error) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function deleteHeritageCookie() {
|
||||
// If this cookie is ever created from the concept funnel, will need to add another
|
||||
// line with the path=/fmg/
|
||||
document.cookie = `${cookieNames.ORDER_INFO}=; Max-Age=0; path=/; domain=${location.hostname}`;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,245 @@
|
|||
import * as 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";
|
||||
import { storeMutations } from "@/constants/store-mutations";
|
||||
import store from "@/store";
|
||||
|
||||
describe("saveOrder", () => {
|
||||
|
||||
// afterEach(() => {
|
||||
// removeAllTestCookies();
|
||||
// });
|
||||
|
||||
function getMockOrderInfo(mockReferralNumber, mockCorrelationId, mockReferralDate ) {
|
||||
return {
|
||||
referralNumber: mockReferralNumber,
|
||||
referralCorrelationId: mockCorrelationId,
|
||||
referralDate: mockReferralDate
|
||||
}
|
||||
}
|
||||
|
||||
describe("handleInfoFromHeritageFunnel", () => {
|
||||
// test("ShouldResetState == true => heritage cookie is deleted", () => {
|
||||
// // Arrange
|
||||
// // TODO CSR-98 Can we not mock this??
|
||||
// const testShouldResetState = true;
|
||||
|
||||
// const testCookieValue = {
|
||||
// ShouldResetState: testShouldResetState
|
||||
// }
|
||||
|
||||
// console.log(cookieNames.ORDER_INFO);
|
||||
// console.log(testCookieValue)
|
||||
// console.log(JSON.stringify(testCookieValue));
|
||||
// console.log(location.hostname)
|
||||
// let myString = `${cookieNames.ORDER_INFO}=${JSON.stringify(testCookieValue)};domain=${location.hostname};path=/;`;
|
||||
// console.log(myString)
|
||||
// document.cookie = 'OrderInfo={"Hahahah":true};domain=localhost;path=/;';
|
||||
// console.log(document.cookie)
|
||||
// document.cookie = "Ahhh=AHHH;"
|
||||
// document.cookie = `${cookieNames.ORDER_INFO}=; Max-Age=0; domain=${location.hostname};`;
|
||||
// console.log(document.cookie)
|
||||
|
||||
// // Act
|
||||
// helper.handleInfoFromHeritageFunnel();
|
||||
|
||||
// // Assert
|
||||
// console.log(document.cookie)
|
||||
// // expect(document.cookie).toBe();
|
||||
// });
|
||||
|
||||
// test("ShouldResetState == true => reset store", () => {
|
||||
// // Arrange
|
||||
// helper.getHeritageCookieValue = jest.fn(x => x.ShouldResetState = false);
|
||||
|
||||
// // Act
|
||||
// helper.handleInfoFromHeritageFunnel();
|
||||
|
||||
// // Assert
|
||||
// expect(helper.getHeritageCookieValue).toHaveBeenCalled();
|
||||
// });
|
||||
|
||||
// test("Heritage cookie is null => store is unchanged", () => {
|
||||
// // Arrange
|
||||
// helper.getHeritageCookieValue = jest.fn(x => x.ShouldResetState = true);
|
||||
|
||||
// // Act
|
||||
// helper.handleInfoFromHeritageFunnel();
|
||||
|
||||
// // Assert
|
||||
// expect(helper.getHeritageCookieValue).toHaveBeenCalled();
|
||||
// });
|
||||
});
|
||||
|
||||
test("saveOrder => should set state order values", async () => {
|
||||
// Arrange
|
||||
const mockReferralNumber = 2;
|
||||
const mockCorrelationId = "55";
|
||||
const mockReferralDate = "2022";
|
||||
|
||||
const mockOrderInfo = getMockOrderInfo(mockReferralNumber, mockCorrelationId, mockReferralDate);
|
||||
|
||||
const mockData = {
|
||||
actionList: [{
|
||||
actionName: storeActions.SAVE_ORDER,
|
||||
data: mockOrderInfo,
|
||||
}],
|
||||
}
|
||||
|
||||
setupMocksForJsFiles(mockData);
|
||||
|
||||
// Act
|
||||
await helper.saveOrder();
|
||||
|
||||
// Assert
|
||||
expect(store.commit).toHaveBeenCalledTimes(3);
|
||||
expect(store.commit).toHaveBeenCalledWith(storeMutations.UPDATE_REFERRAL_NUMBER, mockReferralNumber);
|
||||
expect(store.commit).toHaveBeenCalledWith(storeMutations.UPDATE_REFERRAL_CORRELATION_ID, mockCorrelationId);
|
||||
expect(store.commit).toHaveBeenCalledWith(storeMutations.UPDATE_REFERRAL_DATE, mockReferralDate);
|
||||
});
|
||||
|
||||
// test("saveOrder => should update DidHeritageFunnelUpdateLast cookie value", async () => {
|
||||
// // Arrange
|
||||
// const mockReferralNumber = 2;
|
||||
// const mockCorrelationId = "55";
|
||||
// const mockReferralDate = "2022";
|
||||
|
||||
// const mockOrderInfo = getMockOrderInfo(mockReferralNumber, mockCorrelationId, mockReferralDate);
|
||||
|
||||
// const mockData = {
|
||||
// actionList: [{
|
||||
// actionName: storeActions.SAVE_ORDER,
|
||||
// data: mockOrderInfo,
|
||||
// }],
|
||||
// }
|
||||
|
||||
// setupMocksForJsFiles(mockData);
|
||||
|
||||
// // Act
|
||||
// await helper.saveOrder();
|
||||
|
||||
// // Assert
|
||||
|
||||
// });
|
||||
});
|
||||
|
||||
describe("navigateToHeritageFunnel", () => {
|
||||
test("should go to external link", () => {
|
||||
// Arrange
|
||||
|
||||
// Act
|
||||
helper.navigateToHeritageFunnel();
|
||||
|
||||
// Assert
|
||||
expect(router.navigate).toHaveBeenCalled();
|
||||
expect(window.location.assign).toHaveBeenCalled();
|
||||
})
|
||||
});
|
||||
|
||||
// TODO CSR-98 Remove skip
|
||||
describe.skip("cookies", () => {
|
||||
afterEach(() => {
|
||||
removeAllTestCookies();
|
||||
})
|
||||
|
||||
describe("getHeritageCookieValue method", () => {
|
||||
test("gets correct value when cookie is present", () => {
|
||||
// Arrange
|
||||
const testReferralNumber = 1566818;
|
||||
const testReferralDate = "2022-03-15T10:56:24.597";
|
||||
const testReferralCorrelationId = "404d2b04-f86e-45c3-b373-127b6217b060";
|
||||
const testShouldResetState = false;
|
||||
const testDidHeritageFunnelUpdateLast = true;
|
||||
|
||||
const testCookieValue = {
|
||||
ReferralNumber: testReferralNumber,
|
||||
ReferralDate: testReferralDate,
|
||||
ReferralCorrelationId: testReferralCorrelationId,
|
||||
ShouldResetState: testShouldResetState,
|
||||
DidHeritageFunnelUpdateLast: testDidHeritageFunnelUpdateLast
|
||||
}
|
||||
setupCookies({ heritageCookieValue: JSON.stringify(testCookieValue) });
|
||||
|
||||
// Act
|
||||
var result = helper.getHeritageCookieValue();
|
||||
|
||||
// Assert
|
||||
expect(result).toEqual(testCookieValue);
|
||||
expect(typeof result).toEqual("object");
|
||||
expect(result.ReferralNumber).toEqual(testReferralNumber);
|
||||
expect(result.ReferralDate).toEqual(testReferralDate);
|
||||
expect(result.ReferralCorrelationId).toEqual(testReferralCorrelationId);
|
||||
expect(result.ShouldResetState).toEqual(testShouldResetState);
|
||||
expect(result.DidHeritageFunnelUpdateLast).toEqual(testDidHeritageFunnelUpdateLast);
|
||||
})
|
||||
|
||||
test("returns empty object when value is empty object", () => {
|
||||
// Arrange
|
||||
const testCookieValue = {};
|
||||
setupCookies({ heritageCookieValue: JSON.stringify(testCookieValue) });
|
||||
|
||||
// Act
|
||||
var result = helper.getHeritageCookieValue();
|
||||
|
||||
// Assert
|
||||
expect(result).toEqual(testCookieValue);
|
||||
expect(typeof result).toEqual("object");
|
||||
expect(Object.keys(result)).toHaveLength(0);
|
||||
})
|
||||
|
||||
test("returns null when value is empty string", () => {
|
||||
// Arrange
|
||||
const testCookieValue = "";
|
||||
setupCookies({ heritageCookieValue: testCookieValue });
|
||||
|
||||
// Act
|
||||
var result = helper.getHeritageCookieValue();
|
||||
|
||||
// Assert
|
||||
expect(result).toEqual(null);
|
||||
})
|
||||
|
||||
test("returns null when heritage cookie doesn't exist", () => {
|
||||
// Arrange
|
||||
setupCookies({ includeHeritageCookie: false });
|
||||
|
||||
// Act
|
||||
var result = helper.getHeritageCookieValue();
|
||||
|
||||
// Assert
|
||||
expect(result).toEqual(null);
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
// document.cookie is not just a string, needs to be added individually
|
||||
const cookies = {
|
||||
"orderconfirmation": 1565980,
|
||||
"optimizelyEndUserId": "oeu1610051865958r0.07937134272718804",
|
||||
[cookieNames.ORDER_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",
|
||||
"_ga": "GA1.1.1631274579.1622658999",
|
||||
"da_lid": "B10847599A73EA95861EBB99009A283E27|0|0|0 clientTag=null",
|
||||
"addshoppers.com": "2%7C1%3A0%7C10%3A1646681050%7C15%3Aaddshoppers.com%7C44%3AODM1OTczNWI0MmFjNGNmMmExNDY3OWRlNTQ1NmM5MGY%3D%7Cef2a50fafe40fc5abf641a14ee5541c70bef2950666f59d3a809fd9352c7b963"
|
||||
};
|
||||
|
||||
function setupCookies({ heritageCookieValue = "", includeHeritageCookie = true }) {
|
||||
console.log(heritageCookieValue)
|
||||
Object.keys(cookies).forEach(key => {
|
||||
const cookieValue = key == cookieNames.ORDER_INFO ? heritageCookieValue : cookies[key];
|
||||
|
||||
if (includeHeritageCookie || key != cookieNames.ORDER_INFO)
|
||||
document.cookie = `${key}=${cookieValue}`;
|
||||
});
|
||||
}
|
||||
|
||||
function removeAllTestCookies() {
|
||||
Object.keys(cookies).forEach(key => {
|
||||
document.cookie = `${key}=;Max-Age=0;`;
|
||||
});
|
||||
}
|
||||
|
||||
// test("getCookieValue: Gets correct cookie value", () => {
|
||||
// // Arrange
|
||||
// const mixIn = getMixInInstance({});
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { navigationScenarios } from "@/router/router-constants/navigation-scenar
|
|||
import { vehicleCategories } from "@/constants/vehicle-categories.js";
|
||||
import { fmgPageValues } from "@/router/router-constants/fmgPage-values";
|
||||
import baseMixin from "@/mixins/base-mixin";
|
||||
import store from "@/store";
|
||||
|
||||
export function getMountOptions(mockData) {
|
||||
// Define our mocks to attached to the 'global' object for Vue/Jest.
|
||||
|
|
@ -11,18 +12,20 @@ export function getMountOptions(mockData) {
|
|||
|
||||
//this is mocking if you use the mixin directly(baseMixin.methods.dispatchNonBlockingStoreAction) vs this.dispatchNonBlockingStoreAction
|
||||
if (mockData.actionList !== undefined) {
|
||||
baseMixin.methods.dispatchNonBlockingStoreAction = jest.fn();
|
||||
baseMixin.methods.dispatchNonBlockingStoreAction.mockImplementation((actionName) => {
|
||||
let actionFilterResult = mockData.actionList.filter(
|
||||
(x) => x.actionName == actionName
|
||||
);
|
||||
// baseMixin.methods.dispatchNonBlockingStoreAction = jest.fn();
|
||||
// baseMixin.methods.dispatchNonBlockingStoreAction.mockImplementation((actionName) => {
|
||||
// let actionFilterResult = mockData.actionList.filter(
|
||||
// (x) => x.actionName == actionName
|
||||
// );
|
||||
|
||||
if (actionFilterResult.length > 0 && actionFilterResult.length === 1) {
|
||||
return Promise.resolve({
|
||||
data: actionFilterResult[0].data,
|
||||
});
|
||||
}
|
||||
});
|
||||
// if (actionFilterResult.length > 0 && actionFilterResult.length === 1) {
|
||||
// return Promise.resolve({
|
||||
// data: actionFilterResult[0].data,
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
|
||||
setupDispatchNonBlockingStoreAction(mockData);
|
||||
}
|
||||
mocks.dispatchNonBlockingStoreAction = jest.fn();
|
||||
mocks.dispatchNonBlockingStoreAction.mockImplementation((actionName) => {
|
||||
|
|
@ -55,3 +58,24 @@ export function getMountOptions(mockData) {
|
|||
|
||||
return { global };
|
||||
}
|
||||
|
||||
function setupDispatchNonBlockingStoreAction(mockData) {
|
||||
baseMixin.methods.dispatchNonBlockingStoreAction = jest.fn();
|
||||
baseMixin.methods.dispatchNonBlockingStoreAction.mockImplementation((actionName) => {
|
||||
let actionFilterResult = mockData.actionList.filter(
|
||||
(x) => x.actionName == actionName
|
||||
);
|
||||
|
||||
if (actionFilterResult.length > 0 && actionFilterResult.length === 1) {
|
||||
return Promise.resolve({
|
||||
data: actionFilterResult[0].data,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function setupMocksForJsFiles(mockData) {
|
||||
setupDispatchNonBlockingStoreAction(mockData);
|
||||
store.commit = jest.fn();
|
||||
router.navigate = jest.fn();
|
||||
}
|
||||
|
|
@ -8,7 +8,7 @@ import { routerParameterKeys } from '@/router/router-constants/router-parameter-
|
|||
import baseMixin from "@/mixins/base-mixin";
|
||||
import eventBus from "@/helpers/event-bus/event-bus";
|
||||
import store from "@/store";
|
||||
import { handleInfoFromHeritageFunnel, saveOrder, } from "@/helpers/heritage-integration-helper";
|
||||
import { handleInfoFromHeritageFunnel, saveOrder, getHeritageCookieValue } from "@/helpers/heritage-integration-helper";
|
||||
|
||||
// Components
|
||||
import ComponentTest from "@/layouts/component-test/component-test.vue";
|
||||
|
|
@ -139,8 +139,8 @@ async function navigate(scenario, currentRoute, invalidateOnSave, optionalQuery
|
|||
return;
|
||||
}
|
||||
|
||||
// // here?? CSR-98
|
||||
// baseMixin.methods.saveOrder();
|
||||
console.log(scenario)
|
||||
console.log(currentRoute)
|
||||
|
||||
// Match our maps up and navigate if we have a destination.
|
||||
const matchingScenarioMap = getNavigationMap(scenario, currentRoute);
|
||||
|
|
@ -159,7 +159,9 @@ async function navigate(scenario, currentRoute, invalidateOnSave, optionalQuery
|
|||
// Append page data to the store for the NEXT page, if any. It will be an empty object if none is provided.
|
||||
baseMixin.methods.savePageDataToStore(destinationFmgPageValue, optionalPageData);
|
||||
|
||||
saveOrder();
|
||||
// if cookie and referralNumber exists
|
||||
if (getHeritageCookieValue()?.ReferralNumber)
|
||||
saveOrder();
|
||||
|
||||
router.push({
|
||||
name: "root",
|
||||
|
|
@ -169,16 +171,13 @@ async function navigate(scenario, currentRoute, invalidateOnSave, optionalQuery
|
|||
params: Object.assign(optionalParams, {[routerParameterKeys.FROM_ROUTER_NAVIGATE]: true})
|
||||
});
|
||||
} else if (matchingScenarioMap.destinationUrl !== undefined) {
|
||||
if (matchingScenarioMap.shouldNavigateToHeritageFunnel) {
|
||||
await saveOrder();
|
||||
}
|
||||
|
||||
navigateToUrl(matchingScenarioMap.destinationUrl, optionalQuery);
|
||||
}
|
||||
}
|
||||
|
||||
// Get navigation map depending on the scenario and the current 'page' you're on.
|
||||
function getNavigationMap(scenario, currentRoute) {
|
||||
console.log("A")
|
||||
const fmgPageValue = currentRoute.query.fmgPage;
|
||||
const matchedQueryValue = routingTable
|
||||
.filter(
|
||||
|
|
|
|||
|
|
@ -61,7 +61,6 @@ const routingTable = [
|
|||
{
|
||||
scenario: navigationScenarios.MOVE_TO_HERITAGE_FUNNEL,
|
||||
destinationUrl: externalUrls.HERITAGE_FUNNEL,
|
||||
shouldNavigateToHeritageFunnel: true
|
||||
},
|
||||
{
|
||||
scenario: navigationScenarios.SELECTED_DAMAGE_WITH_SINGLE_PART,
|
||||
|
|
|
|||
Loading…
Reference in a new issue