Merge pull request #312 from Safelite/feature/CSR-98

Feature/csr 98
This commit is contained in:
katieoh-safelite 2022-03-30 13:42:09 -04:00 committed by GitHub
commit e0a2647c30
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 36 additions and 16 deletions

View file

@ -1,3 +1,4 @@
const applicationConfig = {
CONSUMER_APIGATEWAY_URL: process.env.VUE_APP_CONSUMER_API_GATEWAY,
GOOGLE_PLACES_API_KEY: process.env.VUE_APP_GOOGLE_PLACES_API_KEY,
@ -5,5 +6,4 @@ const applicationConfig = {
SAVED_SESSION_TIMEOUT_DAYS: 45
};
export { applicationConfig };
export { applicationConfig };

View file

@ -1,13 +1,12 @@
import { cookieNames } from "@/constants/cookie-names";
import store from "@/store";
/*
Will update the cookie if present, or create a new one if not.
*/
export function updateOrCreateFunnelCookie() {
// Create the cookie
document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}={}; path=/`;
document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}={}; path=/; ${getCookieDomainValue()};`;
// Set up cookie with all the props.
setFunnelCookieProperties({
@ -25,13 +24,13 @@ export function updateOrCreateFunnelCookie() {
/*
Gets the current instance of the funnel cookie.
Returns null if cookie isn't valid JSON.
*/
*/
export function getFunnelCookie() {
const cookieJson = document.cookie
?.split("; ")
?.find(row => row.startsWith(`${cookieNames.FUNNEL_SESSION_INFO}=`))
?.split("=")[1];
try {
return JSON.parse(cookieJson);
} catch (error) {
@ -43,7 +42,8 @@ export function getFunnelCookie() {
Removes cookie from browser.
*/
export function deleteFunnelCookie() {
document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}=; Max-Age=0; path=/; domain=${location.hostname}`;
console.log("hi there")
document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}=; Max-Age=0; path=/; ${getCookieDomainValue()}`;
}
/*
@ -61,8 +61,25 @@ function setFunnelCookieProperties(properties) {
const cookieValueJson = JSON.stringify(cookie);
document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}=${cookieValueJson}; path=/`;
document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}=${cookieValueJson}; path=/; ${getCookieDomainValue()}`;
}
}
}
export function getCookieDomainValue() {
return location.hostname.includes("localhost") ? "" : `domain=${getDomainWithoutSubdomain()};`;
}
function getDomainWithoutSubdomain() {
let url = location.hostname;
if (url.includes("localhost")) {
return "localhost";
}
const urlParts = url.split('.');
return `.${urlParts
.slice(0)
.slice(-(urlParts.length === 4 ? 3 : 2))
.join('.')}`;
}

View file

@ -1,7 +1,7 @@
import { queryStrings } from "@/constants/query-strings";
import { externalUrls } from "@/router/router-constants/externalUrl-values";
import { lazyLoadComponent } from "@/router/dynamic-routing/component-loader.js";
import {saveOrder} from "@/helpers/heritage-integration/order-helper.js";
import { saveOrder } from "@/helpers/heritage-integration/order-helper.js";
import store from "@/store";
import router from "@/router";

View file

@ -10,6 +10,7 @@ import baseMixin from "@/mixins/base-mixin";
*/
export async function loadOrderIfPresent() {
const funnelCookie = getFunnelCookie();
console.log(funnelCookie)
// Do nothing if there is no cookie or no correlation id.
if (funnelCookie == null || funnelCookie.ReferralCorrelationId == null) {
@ -20,6 +21,7 @@ export async function loadOrderIfPresent() {
if (funnelCookie.ShouldResetState) {
baseMixin.methods.dispatchNonBlockingStoreAction(storeActions.RESET_STATE);
deleteFunnelCookie();
console.log("sup")
return null;
}

View file

@ -13,18 +13,21 @@ describe("loadOrderIfPresent", () => {
test("ShouldResetState == true => funnel cookie is deleted", () => {
// Arrange
cookieHelper.deleteFunnelCookie = jest.spyOn(cookieHelper, "deleteFunnelCookie");
const testShouldResetState = true;
const testCookieValue = {
ShouldResetState: testShouldResetState
ShouldResetState: testShouldResetState,
ReferralCorrelationId: "xxx"
}
document.cookie = `${cookieNames.ORDER_INFO}=${JSON.stringify(testCookieValue)}; path=/; domain=${location.hostname}`;
document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}=${JSON.stringify(testCookieValue)}; path=/; ${cookieHelper.getCookieDomainValue()}`;
// Act
loadOrderIfPresent();
// Assert
expect(cookieHelper.deleteFunnelCookie).toHaveBeenCalled();
expect(document.cookie).toBe("");
});
@ -94,7 +97,6 @@ describe("loadOrderIfPresent", () => {
});
describe("saveOrder", () => {
afterEach(() => {
removeAllTestCookies();
});

View file

@ -5,6 +5,7 @@ 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";
import { getCookieDomainValue } from "@/helpers/heritage-integration/cookie-helper";
// Common methods
export function getMountOptions(mockData) {
@ -63,7 +64,7 @@ export const cookies = {
export function removeAllTestCookies() {
Object.keys(cookies).forEach(key => {
document.cookie = `${key}=;Max-Age=0;`;
document.cookie = `${key}=;Max-Age=0;path=/`;
document.cookie = `${key}=;Max-Age=0;path=/;${getCookieDomainValue()}`;
});
}
@ -78,9 +79,8 @@ export function getMockOrderInfo(mockReferralNumber, mockCorrelationId, mockRefe
export function setupCookies({ funnelCookieValue = "", includeHeritageCookie = true }) {
Object.keys(cookies).forEach(key => {
const cookieValue = key == cookieNames.FUNNEL_SESSION_INFO ? funnelCookieValue : cookies[key];
if (includeHeritageCookie || key != cookieNames.FUNNEL_SESSION_INFO)
document.cookie = `${key}=${cookieValue}; path=/;`;
document.cookie = `${key}=${cookieValue}; path=/; ${getCookieDomainValue()}`;
});
}

View file

@ -2,7 +2,6 @@ process.env.VUE_APP_CONSUMER_API_GATEWAY =
"https://consumerapidev.safelite.com";
process.env.VUE_APP_HERITAGE_FUNNEL =
"http://localhost:38000/default.aspx";
process.env.VUE_APP_GOOGLE_PLACES_API_KEY =
"AIzaSyDptGCkOPgN2uWJOy4ou4M33phRD4MAoJo"