CSR-98 Fix tests

This commit is contained in:
Katie 2022-03-30 13:11:42 -04:00
parent d6e935a2d8
commit 1e40e0e1f8
3 changed files with 12 additions and 26 deletions

View file

@ -6,7 +6,7 @@ import store from "@/store";
*/
export function updateOrCreateFunnelCookie() {
// Create the cookie
document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}={}; domain=${getDomainWithoutSubdomain()}; path=/;`;
document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}={}; path=/; ${getCookieDomainValue()};`;
// Set up cookie with all the props.
setFunnelCookieProperties({
@ -46,7 +46,7 @@ export function getFunnelCookie() {
Removes cookie from browser.
*/
export function deleteFunnelCookie() {
document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}=; Max-Age=0; domain=${getDomainWithoutSubdomain()}; path=/`;
document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}=; Max-Age=0; path=/; ${getCookieDomainValue()}`;
}
/*
@ -64,11 +64,15 @@ function setFunnelCookieProperties(properties) {
const cookieValueJson = JSON.stringify(cookie);
document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}=${cookieValueJson}; domain=${getDomainWithoutSubdomain()}; 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 == "localhost") {

View file

@ -132,7 +132,7 @@ describe("saveOrder", () => {
}, false);
});
test.only("saveOrder => should update DidHeritageFunnelUpdateLast cookie value to false", async () => {
test("saveOrder => should update DidHeritageFunnelUpdateLast cookie value to false", async () => {
// Arrange
const testReferralNumber = 1566818;
const testReferralDate = "2022-03-15T10:56:24.597";
@ -160,8 +160,6 @@ describe("saveOrder", () => {
setupCookies({ funnelCookieValue: JSON.stringify(testCookieValue) });
console.log(document.cookie)
// Act
await saveOrder();

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) {
@ -62,8 +63,8 @@ export const cookies = {
export function removeAllTestCookies() {
Object.keys(cookies).forEach(key => {
document.cookie = `${key}=;Max-Age=0;domain=${getDomainWithoutSubdomain()};`;
document.cookie = `${key}=;Max-Age=0;domain=${getDomainWithoutSubdomain()};path=/`;
document.cookie = `${key}=;Max-Age=0;`;
document.cookie = `${key}=;Max-Age=0;path=/;${getCookieDomainValue()}`;
});
}
@ -79,10 +80,8 @@ export function setupCookies({ funnelCookieValue = "", includeHeritageCookie = t
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}; domain=${getDomainWithoutSubdomain()}; path=/;`;
document.cookie = `${key}=${cookieValue}; path=/; ${getCookieDomainValue()}`;
});
console.log(document.cookie)
}
// Private methods
@ -101,19 +100,4 @@ 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('.')}`;
}