CSR-98 Use correct domain in cookie

This commit is contained in:
Katie 2022-03-30 11:36:23 -04:00
parent 87820950ae
commit e24f61e5f1
6 changed files with 58 additions and 18 deletions

View file

@ -1,9 +1,10 @@
const applicationConfig = {
CONSUMER_APIGATEWAY_URL: process.env.VUE_APP_CONSUMER_API_GATEWAY,
GOOGLE_PLACES_API_KEY: process.env.VUE_APP_GOOGLE_PLACES_API_KEY,
ANALYTICS_SESSION_TIMEOUT: 30,
SAVED_SESSION_TIMEOUT: 45
ANALYTICS_SESSION_TIMEOUT: 30, SAVED_SESSION_TIMEOUT: 45,
};
export { applicationConfig };

View file

@ -1,7 +1,6 @@
import { cookieNames } from "@/constants/cookie-names";
import store from "@/store";
/*
Will update the cookie if present, or create a new one if not.
*/
@ -17,7 +16,7 @@ export function updateOrCreateConceptCookie() {
});
// Create the cookie
document.cookie = `${cookieNames.CONCEPT_SESSION_INFO}={}; path=/`;
document.cookie = `${cookieNames.CONCEPT_SESSION_INFO}={}; domain=${getDomainWithoutSubdomain()}; path=/;`;
// Set up cookie with all the props.
setConceptCookieProperties({
@ -37,11 +36,15 @@ export function updateOrCreateConceptCookie() {
Returns null if cookie isn't valid JSON.
*/
export function getConceptCookie() {
console.log("getConceptCookie")
console.log(document.cookie)
console.log(location.hostname)
console.log(getDomainWithoutSubdomain())
const cookieJson = document.cookie
?.split("; ")
?.find(row => row.startsWith(`${cookieNames.CONCEPT_SESSION_INFO}=`))
?.split("=")[1];
console.log(cookieJson)
try {
return JSON.parse(cookieJson);
} catch (error) {
@ -53,7 +56,7 @@ export function getConceptCookie() {
Removes concept cookie from browser.
*/
export function deleteConceptCookie() {
document.cookie = `${cookieNames.CONCEPT_SESSION_INFO}=; Max-Age=0; path=/; domain=${location.hostname}`;
document.cookie = `${cookieNames.CONCEPT_SESSION_INFO}=; Max-Age=0; domain=${getDomainWithoutSubdomain()}; path=/`;
}
/*
@ -71,8 +74,21 @@ function setConceptCookieProperties(properties) {
const cookieValueJson = JSON.stringify(cookie);
document.cookie = `${cookieNames.CONCEPT_SESSION_INFO}=${cookieValueJson}; path=/`;
document.cookie = `${cookieNames.CONCEPT_SESSION_INFO}=${cookieValueJson}; domain=${getDomainWithoutSubdomain()}; path=/`;
}
}
}
function getDomainWithoutSubdomain() {
let url = location.hostname;
if (url == "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";
@ -45,9 +45,11 @@ export async function getPageToRouteExistingOrderTo(toRoute = {}, existingHerita
return 'vehicle-damage'
} else {
if (store.getters.vehicle.vin) {
return "vin-lookup";
return "vehicle-damage";
// return "vin-lookup";
} else {
return "estimate"
return "vehicle-damage";
// return "estimate"
}
}
@ -67,6 +69,9 @@ export async function navigateToHeritageFunnel() {
{
corid: store.getters.order.referralCorrelationId,
src: "concept-funnel",
// TODO CSR-28, remove this
cns: "all",
experiments: "RemoveServiceAreaPage=ServAreaRemoval_V7=ServAreaNoRemove_V7_TEST=true,ConceptFunnel=ConceptFunnel_V1=ConceptFunnel_TEST=true"
}
);
}

View file

@ -19,7 +19,7 @@ describe("loadOrderIfPresent", () => {
ShouldResetState: testShouldResetState
}
document.cookie = `${cookieNames.ORDER_INFO}=${JSON.stringify(testCookieValue)}; path=/; domain=${location.hostname}`;
document.cookie = `${cookieNames.ORDER_INFO}=${JSON.stringify(testCookieValue)}; path=/; domain=.safelite.com`;
// Act
loadOrderIfPresent();
@ -74,7 +74,6 @@ describe("loadOrderIfPresent", () => {
});
describe("saveOrder", () => {
afterEach(() => {
removeAllTestCookies();
});
@ -113,7 +112,7 @@ describe("saveOrder", () => {
}, false);
});
test("saveOrder => should update DidHeritageFunnelUpdateLast cookie value to false", async () => {
test.only("saveOrder => should update DidHeritageFunnelUpdateLast cookie value to false", async () => {
// Arrange
const testReferralNumber = 1566818;
const testReferralDate = "2022-03-15T10:56:24.597";
@ -139,8 +138,12 @@ describe("saveOrder", () => {
DidHeritageFunnelUpdateLast: true
}
console.log("A")
console.log(location.hostname)
setupCookies({ conceptCookieValue: JSON.stringify(testCookieValue) });
console.log(document.cookie)
// Act
await saveOrder();

View file

@ -62,8 +62,8 @@ 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;domain=${getDomainWithoutSubdomain()};`;
document.cookie = `${key}=;Max-Age=0;domain=${getDomainWithoutSubdomain()};path=/`;
});
}
@ -78,10 +78,11 @@ export function getMockOrderInfo(mockReferralNumber, mockCorrelationId, mockRefe
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=/;`;
document.cookie = `${key}=${cookieValue}; domain=${getDomainWithoutSubdomain()}; path=/;`;
});
console.log(document.cookie)
}
// Private methods
@ -100,4 +101,19 @@ function setupBaseMixinDispatchNonBlockingStoreAction(mockData) {
}
});
}
}
function getDomainWithoutSubdomain() {
let url = location.hostname;
if (url == "localhost") {
return "localhost";
}
const urlParts = url.split('.');
return `.${urlParts
.slice(0)
.slice(-(urlParts.length === 4 ? 3 : 2))
.join('.')}`;
}

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"