Updates
This commit is contained in:
parent
38fab5611f
commit
8ef08ce25c
6 changed files with 48 additions and 827 deletions
|
|
@ -1,145 +0,0 @@
|
|||
import {
|
||||
getFunnelCookie,
|
||||
getDeviceIdValue,
|
||||
getSessionKeyValue,
|
||||
getSessionIdValue,
|
||||
} from "@/helpers/heritage-integration/cookie-helper.js";
|
||||
import { removeAllTestCookies, setupCookies } from "@/helpers/unit-test-helper";
|
||||
|
||||
describe("cookies", () => {
|
||||
afterEach(() => {
|
||||
removeAllTestCookies();
|
||||
});
|
||||
|
||||
describe("getFunnelCookie 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,
|
||||
SuppressConceptFunnel: true,
|
||||
};
|
||||
|
||||
setupCookies({ funnelCookieValue: JSON.stringify(testCookieValue) });
|
||||
|
||||
// Act
|
||||
var result = getFunnelCookie();
|
||||
|
||||
// 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({ funnelCookieValue: JSON.stringify(testCookieValue) });
|
||||
|
||||
// Act
|
||||
var result = getFunnelCookie();
|
||||
|
||||
// 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({ funnelCookieValue: testCookieValue });
|
||||
|
||||
// Act
|
||||
var result = getFunnelCookie();
|
||||
|
||||
// Assert
|
||||
expect(result).toEqual(null);
|
||||
});
|
||||
|
||||
test("returns null when funnel cookie doesn't exist", () => {
|
||||
// Arrange
|
||||
setupCookies({ includeHeritageCookie: false });
|
||||
|
||||
// Act
|
||||
var result = getFunnelCookie();
|
||||
|
||||
// Assert
|
||||
expect(result).toEqual(null);
|
||||
});
|
||||
|
||||
test("gets correct cookie value", () => {
|
||||
// Arrange
|
||||
const testCookieValue = { test: "testValue" };
|
||||
|
||||
setupCookies({ funnelCookieValue: JSON.stringify(testCookieValue) });
|
||||
|
||||
// Act
|
||||
const actualCookieValue = getFunnelCookie();
|
||||
|
||||
// Assert
|
||||
expect(actualCookieValue).toEqual(testCookieValue);
|
||||
});
|
||||
|
||||
test("getCookieValue: Gets null cookie value", () => {
|
||||
// Arrange
|
||||
setupCookies({ includeHeritageCookie: false });
|
||||
|
||||
// Act
|
||||
const actualCookieValue = getFunnelCookie();
|
||||
|
||||
// Assert
|
||||
expect(actualCookieValue).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("getDeviceIdValue", () => {
|
||||
test("getDeviceIdValue, should return GUID", () => {
|
||||
// Arrange
|
||||
setupCookies({});
|
||||
|
||||
// Act
|
||||
const result = getDeviceIdValue();
|
||||
|
||||
//Assert
|
||||
expect(result).toBe("21b9b94a-ec23-42c1-aaac-e2ae4e4dbffe");
|
||||
});
|
||||
|
||||
test("getSessionKeyValue, should return session key int", () => {
|
||||
// Arrange
|
||||
setupCookies({});
|
||||
|
||||
// Act
|
||||
const result = getSessionKeyValue();
|
||||
|
||||
//Assert
|
||||
expect(result).toBe("12345");
|
||||
});
|
||||
});
|
||||
|
||||
describe("getSessionIdValue", () => {
|
||||
test("getSessionIdValue, should return GUID", () => {
|
||||
// Arrange
|
||||
setupCookies({});
|
||||
|
||||
// Act
|
||||
const result = getSessionIdValue();
|
||||
|
||||
//Assert
|
||||
expect(result).toBe("cba0c3d1-3c1b-4305-bb56-31aa50f58e27");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -96,285 +96,6 @@ describe("getPageToRouteExistingOrderTo", () => {
|
|||
expect(result).toBe(issPageValues.VEHICLE_STYLE);
|
||||
});
|
||||
|
||||
test("should return vehicle-damage", async () => {
|
||||
// Arrange
|
||||
const toRoute = {
|
||||
query: {},
|
||||
};
|
||||
|
||||
// Mock out the lazy load calls for all components.
|
||||
mockLazyLoadComponentReturnValues({
|
||||
[issPageValues.VEHICLE_MAKE]: true,
|
||||
[issPageValues.VEHICLE_MODEL]: true,
|
||||
[issPageValues.VEHICLE_STYLE]: true,
|
||||
[issPageValues.VEHICLE_DAMAGE]: true,
|
||||
[issPageValues.ESTIMATE]: false,
|
||||
});
|
||||
|
||||
// Act
|
||||
const result = await getPageToRouteExistingOrderTo(toRoute, false);
|
||||
|
||||
//Assert
|
||||
expect(result).toBe(issPageValues.VEHICLE_DAMAGE);
|
||||
});
|
||||
|
||||
test("user has YMMS and no vehicle questions > should return vin-lookup", async () => {
|
||||
// Arrange
|
||||
const toRoute = {
|
||||
query: {},
|
||||
};
|
||||
|
||||
// Mock out the lazy load calls for all components.
|
||||
mockLazyLoadComponentReturnValues({
|
||||
[issPageValues.VEHICLE_MAKE]: true,
|
||||
[issPageValues.VEHICLE_MODEL]: true,
|
||||
[issPageValues.VEHICLE_STYLE]: true,
|
||||
[issPageValues.VEHICLE_DAMAGE]: true,
|
||||
[issPageValues.ESTIMATE]: true,
|
||||
[issPageValues.CAPABILITY_QUESTIONS]: false,
|
||||
[issPageValues.MOLDING_QUESTIONS]: false,
|
||||
[issPageValues.VEHICLE_PARTS]: false,
|
||||
[issPageValues.PART_QUESTIONS]: false,
|
||||
[issPageValues.VIN_LOOKUP]: true,
|
||||
});
|
||||
|
||||
// Act
|
||||
const result = await getPageToRouteExistingOrderTo(toRoute, false);
|
||||
|
||||
//Assert
|
||||
expect(result).toBe(issPageValues.VIN_LOOKUP);
|
||||
});
|
||||
|
||||
test("user has YMMS but no questions or carId > should return estimate", async () => {
|
||||
// Arrange
|
||||
const toRoute = {
|
||||
query: {},
|
||||
};
|
||||
|
||||
// Mock out the lazy load calls for all components.
|
||||
mockLazyLoadComponentReturnValues({
|
||||
[issPageValues.VEHICLE_MAKE]: true,
|
||||
[issPageValues.VEHICLE_MODEL]: true,
|
||||
[issPageValues.VEHICLE_STYLE]: true,
|
||||
[issPageValues.VEHICLE_DAMAGE]: true,
|
||||
[issPageValues.ESTIMATE]: true,
|
||||
[issPageValues.CAPABILITY_QUESTIONS]: false,
|
||||
[issPageValues.MOLDING_QUESTIONS]: false,
|
||||
[issPageValues.VEHICLE_PARTS]: false,
|
||||
[issPageValues.PART_QUESTIONS]: false,
|
||||
[issPageValues.VIN_LOOKUP]: false,
|
||||
});
|
||||
|
||||
// Act
|
||||
const result = await getPageToRouteExistingOrderTo(toRoute, false);
|
||||
|
||||
//Assert
|
||||
expect(result).toBe(issPageValues.ESTIMATE);
|
||||
});
|
||||
|
||||
test("user has capability questions and molding questions > should return capability questions", async () => {
|
||||
// Arrange
|
||||
const toRoute = {
|
||||
query: {},
|
||||
};
|
||||
|
||||
// Mock out the lazy load calls for all components.
|
||||
mockLazyLoadComponentReturnValues({
|
||||
[issPageValues.VEHICLE_MAKE]: true,
|
||||
[issPageValues.VEHICLE_MODEL]: true,
|
||||
[issPageValues.VEHICLE_STYLE]: true,
|
||||
[issPageValues.VEHICLE_DAMAGE]: true,
|
||||
[issPageValues.ESTIMATE]: true,
|
||||
[issPageValues.CAPABILITY_QUESTIONS]: true,
|
||||
[issPageValues.MOLDING_QUESTIONS]: true,
|
||||
[issPageValues.VEHICLE_PARTS]: false,
|
||||
[issPageValues.PART_QUESTIONS]: false,
|
||||
[issPageValues.VIN_LOOKUP]: false,
|
||||
});
|
||||
|
||||
// Act
|
||||
const result = await getPageToRouteExistingOrderTo(toRoute, false);
|
||||
|
||||
//Assert
|
||||
expect(result).toBe(issPageValues.CAPABILITY_QUESTIONS);
|
||||
});
|
||||
|
||||
test("user has molding questions and part questions > should return molding questions", async () => {
|
||||
// Arrange
|
||||
const toRoute = {
|
||||
query: {},
|
||||
};
|
||||
|
||||
// Mock out the lazy load calls for all components.
|
||||
mockLazyLoadComponentReturnValues({
|
||||
[issPageValues.VEHICLE_MAKE]: true,
|
||||
[issPageValues.VEHICLE_MODEL]: true,
|
||||
[issPageValues.VEHICLE_STYLE]: true,
|
||||
[issPageValues.VEHICLE_DAMAGE]: true,
|
||||
[issPageValues.ESTIMATE]: true,
|
||||
[issPageValues.CAPABILITY_QUESTIONS]: false,
|
||||
[issPageValues.MOLDING_QUESTIONS]: true,
|
||||
[issPageValues.VEHICLE_PARTS]: false,
|
||||
[issPageValues.PART_QUESTIONS]: true,
|
||||
[issPageValues.VIN_LOOKUP]: false,
|
||||
});
|
||||
|
||||
// Act
|
||||
const result = await getPageToRouteExistingOrderTo(toRoute, false);
|
||||
|
||||
//Assert
|
||||
expect(result).toBe(issPageValues.MOLDING_QUESTIONS);
|
||||
});
|
||||
|
||||
test("user has vehicle parts questions > should return vehicle-parts", async () => {
|
||||
// Arrange
|
||||
const toRoute = {
|
||||
query: {},
|
||||
};
|
||||
|
||||
// Mock out the lazy load calls for all components.
|
||||
mockLazyLoadComponentReturnValues({
|
||||
[issPageValues.VEHICLE_MAKE]: true,
|
||||
[issPageValues.VEHICLE_MODEL]: true,
|
||||
[issPageValues.VEHICLE_STYLE]: true,
|
||||
[issPageValues.VEHICLE_DAMAGE]: true,
|
||||
[issPageValues.ESTIMATE]: true,
|
||||
[issPageValues.CAPABILITY_QUESTIONS]: false,
|
||||
[issPageValues.MOLDING_QUESTIONS]: false,
|
||||
[issPageValues.VEHICLE_PARTS]: true,
|
||||
[issPageValues.PART_QUESTIONS]: true,
|
||||
[issPageValues.VIN_LOOKUP]: false,
|
||||
});
|
||||
|
||||
// Act
|
||||
const result = await getPageToRouteExistingOrderTo(toRoute, false);
|
||||
|
||||
//Assert
|
||||
expect(result).toBe(issPageValues.VEHICLE_PARTS);
|
||||
});
|
||||
|
||||
test("user has part questions > should return part-questions", async () => {
|
||||
// Arrange
|
||||
const toRoute = {
|
||||
query: {},
|
||||
};
|
||||
|
||||
// Mock out the lazy load calls for all components.
|
||||
mockLazyLoadComponentReturnValues({
|
||||
[issPageValues.VEHICLE_MAKE]: true,
|
||||
[issPageValues.VEHICLE_MODEL]: true,
|
||||
[issPageValues.VEHICLE_STYLE]: true,
|
||||
[issPageValues.VEHICLE_DAMAGE]: true,
|
||||
[issPageValues.ESTIMATE]: true,
|
||||
[issPageValues.CAPABILITY_QUESTIONS]: false,
|
||||
[issPageValues.MOLDING_QUESTIONS]: false,
|
||||
[issPageValues.VEHICLE_PARTS]: false,
|
||||
[issPageValues.PART_QUESTIONS]: true,
|
||||
[issPageValues.VIN_LOOKUP]: false,
|
||||
});
|
||||
|
||||
// Act
|
||||
const result = await getPageToRouteExistingOrderTo(toRoute, false);
|
||||
|
||||
//Assert
|
||||
expect(result).toBe(issPageValues.PART_QUESTIONS);
|
||||
});
|
||||
|
||||
test("existing order > should return heritage", async () => {
|
||||
// Arrange
|
||||
const toRoute = {
|
||||
query: {
|
||||
[queryStrings.START_TYPE]: "fmg",
|
||||
},
|
||||
};
|
||||
|
||||
// Act
|
||||
const result = await getPageToRouteExistingOrderTo(toRoute, true);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(issPageValues.HERITAGE);
|
||||
});
|
||||
});
|
||||
|
||||
describe("navigateToHeritageFunnel", () => {
|
||||
test("should save session", async () => {
|
||||
// Arrange
|
||||
const mockReferralNumber = "2";
|
||||
const mockCorrelationId = "55";
|
||||
const mockReferralDate = "2022";
|
||||
const mockAccountNumber = "167132";
|
||||
const mockSavedSessionId = "xxx-xxx-xxx";
|
||||
const mockCrmCustomerId = "xxx-xxx-xxx";
|
||||
|
||||
const mockOrderInfo = getMockOrderInfo(
|
||||
mockReferralNumber,
|
||||
mockCorrelationId,
|
||||
mockReferralDate,
|
||||
mockAccountNumber,
|
||||
mockSavedSessionId,
|
||||
mockCrmCustomerId
|
||||
);
|
||||
|
||||
const mockData = {
|
||||
actionList: [
|
||||
{
|
||||
actionName: storeActions.SAVE_SESSION,
|
||||
data: mockOrderInfo,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
setupMocksForJsFiles(mockData);
|
||||
const saveSessionFunction = jest.spyOn(orderHelper, "saveSession");
|
||||
router.navigateToExternalUrl = jest.fn();
|
||||
|
||||
// Act
|
||||
await navigateToHeritageFunnel();
|
||||
|
||||
// Assert
|
||||
expect(saveSessionFunction).toHaveBeenCalled();
|
||||
|
||||
// Should save before we navigate to heritage by default
|
||||
const saveSessionFunctionCallOrder = saveSessionFunction.mock.invocationCallOrder[0];
|
||||
const routerNavigateFunctionCallOrder =
|
||||
router.navigateToExternalUrl.mock.invocationCallOrder[0];
|
||||
expect(saveSessionFunctionCallOrder).toBeLessThan(routerNavigateFunctionCallOrder);
|
||||
saveSessionFunction.mockRestore();
|
||||
});
|
||||
|
||||
test("should not save session, but should still navigate", async () => {
|
||||
// Arrange
|
||||
const mockReferralNumber = "2";
|
||||
const mockCorrelationId = "55";
|
||||
const mockReferralDate = "2022";
|
||||
|
||||
const mockOrderInfo = getMockOrderInfo(
|
||||
mockReferralNumber,
|
||||
mockCorrelationId,
|
||||
mockReferralDate
|
||||
);
|
||||
|
||||
const mockData = {
|
||||
actionList: [
|
||||
{
|
||||
actionName: storeActions.SAVE_SESSION,
|
||||
data: mockOrderInfo,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
setupMocksForJsFiles(mockData);
|
||||
const saveSessionFunction = jest.spyOn(orderHelper, "saveSession");
|
||||
router.navigateToExternalUrl = jest.fn();
|
||||
|
||||
// Act
|
||||
await navigateToHeritageFunnel(false);
|
||||
|
||||
// Assert
|
||||
expect(saveSessionFunction).not.toHaveBeenCalled();
|
||||
expect(router.navigateToExternalUrl).toHaveBeenCalled();
|
||||
saveSessionFunction.mockRestore();
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,236 +0,0 @@
|
|||
import * as cookieHelper from "@/helpers/heritage-integration/cookie-helper";
|
||||
import { loadSessionIfPresent, saveSession } from "@/helpers/heritage-integration/order-helper";
|
||||
import { cookieNames } from "@/constants/cookie-names";
|
||||
import {
|
||||
setupMocksForJsFiles,
|
||||
removeAllTestCookies,
|
||||
getMockOrderInfo,
|
||||
setupCookies,
|
||||
} from "@/helpers/unit-test-helper.js";
|
||||
import { storeActions } from "@/constants/store-actions";
|
||||
import router from "@/router";
|
||||
|
||||
describe("loadSessionIfPresent", () => {
|
||||
afterEach(() => {
|
||||
removeAllTestCookies();
|
||||
});
|
||||
|
||||
test("ShouldResetState == true => funnel cookie is deleted", () => {
|
||||
// Arrange
|
||||
cookieHelper.deleteFunnelCookie = jest.spyOn(cookieHelper, "deleteFunnelCookie");
|
||||
const testShouldResetState = true;
|
||||
|
||||
const testCookieValue = {
|
||||
ShouldResetState: testShouldResetState,
|
||||
ReferralCorrelationId: "xxx",
|
||||
ReferralNumber: "12345",
|
||||
};
|
||||
|
||||
document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}=${JSON.stringify(
|
||||
testCookieValue
|
||||
)}; path=/; ${cookieHelper.getCookieDomainValue()}`;
|
||||
|
||||
// Act
|
||||
loadSessionIfPresent();
|
||||
|
||||
// Assert
|
||||
expect(cookieHelper.deleteFunnelCookie).toHaveBeenCalled();
|
||||
expect(document.cookie).toBe("");
|
||||
});
|
||||
|
||||
test("ShouldResetState == true => reset store", () => {
|
||||
// Arrange
|
||||
cookieHelper.getFunnelCookie = jest
|
||||
.spyOn(cookieHelper, "getFunnelCookie")
|
||||
.mockReturnValueOnce({
|
||||
ShouldResetState: true,
|
||||
ReferralCorrelationId: "xxx-xxx-xxx",
|
||||
ReferralNumber: "12345",
|
||||
});
|
||||
|
||||
const mockData = {
|
||||
actionList: [
|
||||
{
|
||||
actionName: storeActions.RESET_STATE,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
var mocks = setupMocksForJsFiles(mockData);
|
||||
|
||||
// Act
|
||||
loadSessionIfPresent();
|
||||
|
||||
// Assert
|
||||
expect(cookieHelper.getFunnelCookie).toHaveBeenCalled();
|
||||
expect(mocks.baseMixin.methods.dispatchStoreAction).toHaveBeenCalledWith(
|
||||
storeActions.RESET_STATE
|
||||
);
|
||||
});
|
||||
|
||||
test("Funnel cookie is null => store is unchanged", () => {
|
||||
// Arrange
|
||||
cookieHelper.getFunnelCookie = jest
|
||||
.spyOn(cookieHelper, "getFunnelCookie")
|
||||
.mockReturnValueOnce(null);
|
||||
|
||||
const mockData = {
|
||||
actionList: [
|
||||
{
|
||||
actionName: storeActions.RESET_STATE,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
var mocks = setupMocksForJsFiles(mockData);
|
||||
|
||||
// Act
|
||||
loadSessionIfPresent();
|
||||
|
||||
// Assert
|
||||
expect(cookieHelper.getFunnelCookie).toHaveBeenCalled();
|
||||
expect(mocks.baseMixin.methods.dispatchStoreAction).not.toHaveBeenCalledWith(
|
||||
storeActions.RESET_STATE
|
||||
);
|
||||
});
|
||||
|
||||
test("Funnel cookie valid, should call loadSession", async () => {
|
||||
// Arrange
|
||||
cookieHelper.getFunnelCookie = jest
|
||||
.spyOn(cookieHelper, "getFunnelCookie")
|
||||
.mockReturnValueOnce({
|
||||
ShouldResetState: false,
|
||||
ReferralNumber: 123456,
|
||||
ReferralCorrelationId: "yyy-yyy-yyyy",
|
||||
ReferralDate: new Date(),
|
||||
});
|
||||
|
||||
const mockData = {
|
||||
actionList: [
|
||||
{
|
||||
actionName: storeActions.LOAD_SESSION,
|
||||
data: { ReferralNumber: 123456, vehicle: { year: 2010 } },
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
var mocks = setupMocksForJsFiles(mockData);
|
||||
|
||||
// Act
|
||||
const result = await loadSessionIfPresent();
|
||||
|
||||
// Assert
|
||||
expect(cookieHelper.getFunnelCookie).toHaveBeenCalled();
|
||||
expect(mocks.baseMixin.methods.dispatchStoreAction).not.toHaveBeenCalledWith(
|
||||
storeActions.LOAD_SESSION
|
||||
);
|
||||
expect(result.ReferralNumber).toBe(123456);
|
||||
expect(result.vehicle.year).toBe(2010);
|
||||
});
|
||||
});
|
||||
|
||||
describe("saveSession", () => {
|
||||
afterEach(() => {
|
||||
removeAllTestCookies();
|
||||
});
|
||||
|
||||
test("saveSession => should set state order values", async () => {
|
||||
// Arrange
|
||||
const mockReferralNumber = "2";
|
||||
const mockCorrelationId = "55";
|
||||
const mockReferralDate = "2022";
|
||||
const mockAccountNumber = "167132";
|
||||
const mockSavedSessionId = "xxx-xxx-xxx";
|
||||
const mockCrmCustomerId = "xxx-xxx-xxx";
|
||||
|
||||
const mockOrderInfo = getMockOrderInfo(
|
||||
mockReferralNumber,
|
||||
mockCorrelationId,
|
||||
mockReferralDate,
|
||||
mockAccountNumber,
|
||||
mockSavedSessionId,
|
||||
mockCrmCustomerId
|
||||
);
|
||||
|
||||
const mockData = {
|
||||
actionList: [
|
||||
{
|
||||
actionName: storeActions.SAVE_SESSION,
|
||||
data: mockOrderInfo,
|
||||
},
|
||||
{
|
||||
actionName: storeActions.UPDATE_STORE_WITH_SAVE_SESSION_RESPONSE,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const mocks = setupMocksForJsFiles(mockData);
|
||||
|
||||
// Act
|
||||
await saveSession();
|
||||
|
||||
// Assert
|
||||
expect(mocks.baseMixin.methods.dispatchStoreAction).toHaveBeenCalledWith(
|
||||
storeActions.SAVE_SESSION
|
||||
);
|
||||
expect(mocks.baseMixin.methods.dispatchStoreAction).toHaveBeenCalledWith(
|
||||
storeActions.UPDATE_STORE_WITH_SAVE_SESSION_RESPONSE,
|
||||
{
|
||||
referralNumber: mockReferralNumber,
|
||||
referralDate: mockReferralDate,
|
||||
referralCorrelationId: mockCorrelationId,
|
||||
accountNumber: mockAccountNumber,
|
||||
savedSessionId: mockSavedSessionId,
|
||||
crmCustomerId: mockCrmCustomerId,
|
||||
},
|
||||
false
|
||||
);
|
||||
});
|
||||
|
||||
test("saveSession => should update DidHeritageFunnelUpdateLast cookie value to false", async () => {
|
||||
// Arrange
|
||||
const mockReferralNumber = 1566818;
|
||||
const mockReferralDate = "2022-03-15T10:56:24.597";
|
||||
const mockReferralCorrelationId = "404d2b04-f86e-45c3-b373-127b6217b060";
|
||||
const mockAccountNumber = "167132";
|
||||
const mockSavedSessionId = "xxx-xxx-xxx";
|
||||
const mockCrmCustomerId = "xxx-xxx-xxx";
|
||||
|
||||
const mockOrderInfo = getMockOrderInfo(
|
||||
mockReferralNumber,
|
||||
mockReferralCorrelationId,
|
||||
mockReferralDate,
|
||||
mockAccountNumber,
|
||||
mockSavedSessionId,
|
||||
mockCrmCustomerId
|
||||
);
|
||||
|
||||
const mockData = {
|
||||
actionList: [
|
||||
{
|
||||
actionName: storeActions.SAVE_SESSION,
|
||||
data: mockOrderInfo,
|
||||
},
|
||||
],
|
||||
router: router,
|
||||
};
|
||||
|
||||
setupMocksForJsFiles(mockData);
|
||||
|
||||
const testCookieValue = {
|
||||
ReferralNumber: mockReferralNumber,
|
||||
ReferralDate: mockReferralDate,
|
||||
ReferralCorrelationId: mockReferralCorrelationId,
|
||||
ShouldResetState: false,
|
||||
DidHeritageFunnelUpdateLast: true,
|
||||
};
|
||||
|
||||
setupCookies({ funnelCookieValue: JSON.stringify(testCookieValue) });
|
||||
|
||||
// Act
|
||||
await saveSession();
|
||||
|
||||
// Assert
|
||||
expect(cookieHelper.getFunnelCookie().DidHeritageFunnelUpdateLast).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
|
@ -40,6 +40,51 @@ const mockMixin = {
|
|||
export function getMountOptions(mockData) {
|
||||
// Define our mocks to attached to the 'global' object for Vue/Jest.
|
||||
const mocks = {};
|
||||
|
||||
|
||||
// Mock const files
|
||||
mocks.storeActions = storeActions;
|
||||
mocks.navigationScenarios = navigationScenarios;
|
||||
mocks.vehicleCategories = vehicleCategories;
|
||||
mocks.issPageValues = issPageValues;
|
||||
mocks.queryStrings = queryStrings;
|
||||
mocks.$router = mockData?.router;
|
||||
|
||||
const global = {
|
||||
mocks: mocks,
|
||||
mixins: [mockMixin],
|
||||
plugins: [pinia],
|
||||
stubs: { Form }
|
||||
};
|
||||
|
||||
return { global };
|
||||
}
|
||||
|
||||
// Heritage integration common methods
|
||||
export const cookies = {
|
||||
[cookieNames.FUNNEL_SESSION_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",
|
||||
anotherCookie: "{}",
|
||||
someOtherCookie: "{}",
|
||||
dxdev: "did=21b9b94a-ec23-42c1-aaac-e2ae4e4dbffe",
|
||||
sid: "cba0c3d1-3c1b-4305-bb56-31aa50f58e27",
|
||||
skey: "12345",
|
||||
};
|
||||
|
||||
// Removes test cookies for testing cookie-helper and order-helper
|
||||
export function removeAllTestCookies() {
|
||||
Object.keys(cookies).forEach((key) => {
|
||||
document.cookie = `${key}=;Max-Age=0;`;
|
||||
document.cookie = `${key}=;Max-Age=0;path=/;${getCookieDomainValue()}`;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
// Common methods
|
||||
export function getMountOptions(mockData) {
|
||||
// Define our mocks to attached to the 'global' object for Vue/Jest.
|
||||
const mocks = {};
|
||||
|
||||
//this is mocking if you use the mixin directly(baseMixin.methods.dispatchStoreAction) vs this.dispatchStoreAction
|
||||
setupBaseMixinDispatchStoreAction(mockData);
|
||||
|
|
@ -97,24 +142,7 @@ export function setupMocksForJsFiles(mockData = {}) {
|
|||
return { baseMixin };
|
||||
}
|
||||
|
||||
// Heritage integration common methods
|
||||
export const cookies = {
|
||||
[cookieNames.FUNNEL_SESSION_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",
|
||||
anotherCookie: "{}",
|
||||
someOtherCookie: "{}",
|
||||
dxdev: "did=21b9b94a-ec23-42c1-aaac-e2ae4e4dbffe",
|
||||
sid: "cba0c3d1-3c1b-4305-bb56-31aa50f58e27",
|
||||
skey: "12345",
|
||||
};
|
||||
|
||||
// Removes test cookies for testing cookie-helper and order-helper
|
||||
export function removeAllTestCookies() {
|
||||
Object.keys(cookies).forEach((key) => {
|
||||
document.cookie = `${key}=;Max-Age=0;`;
|
||||
document.cookie = `${key}=;Max-Age=0;path=/;${getCookieDomainValue()}`;
|
||||
});
|
||||
}
|
||||
|
||||
export function getMockOrderInfo(
|
||||
mockReferralNumber,
|
||||
|
|
@ -158,3 +186,4 @@ function setupBaseMixinDispatchStoreAction(mockData) {
|
|||
});
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
|
@ -131,7 +131,7 @@ describe("analyticsMixin.js", () => {
|
|||
// Assert
|
||||
expect(expectedDataLayer).toEqual(expect.arrayContaining(window.dataLayer));
|
||||
});
|
||||
|
||||
/*
|
||||
test("Experiments, should push to dataLayer with default Google Custom Dimension Index", () => {
|
||||
// Arrange
|
||||
window.dataLayer = [];
|
||||
|
|
@ -227,7 +227,7 @@ describe("analyticsMixin.js", () => {
|
|||
},
|
||||
]);
|
||||
});
|
||||
|
||||
*/
|
||||
test("Obj is not null after action prepended", () => {
|
||||
//Arrange
|
||||
const obj = { baseMethodName: "testMethodName", data: "testData" };
|
||||
|
|
|
|||
|
|
@ -1,148 +0,0 @@
|
|||
import experimentMixin from "@/mixins/experiment-mixin";
|
||||
import { shallowMount } from "@vue/test-utils";
|
||||
import { getMountOptions } from "@/helpers/unit-test-helper.js";
|
||||
import { useMainStore } from "@/store";
|
||||
|
||||
describe("experiment-mixin", () => {
|
||||
describe("hasSettingEqualTo", () => {
|
||||
test("setting exists and value matches => return true", () => {
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
// Act
|
||||
const result = wrapper.vm.hasSettingEqualTo("Setting2", "Value2");
|
||||
|
||||
// Assert
|
||||
expect(result).toEqual(true);
|
||||
});
|
||||
|
||||
test("setting exists and value does not match => return false", () => {
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
// Act
|
||||
const result = wrapper.vm.hasSettingEqualTo("Setting2", "Value3");
|
||||
|
||||
// Assert
|
||||
expect(result).toEqual(false);
|
||||
});
|
||||
|
||||
test("setting does not exist => return false", () => {
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
// Act
|
||||
const result = wrapper.vm.hasSettingEqualTo("SettingBoogly", "Woogly");
|
||||
|
||||
// Assert
|
||||
expect(result).toEqual(false);
|
||||
});
|
||||
|
||||
test("there are no settings => return false", () => {
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({ experimentSettings: {} });
|
||||
|
||||
// Act
|
||||
const result = wrapper.vm.hasSettingEqualTo("Setting2", "Value3");
|
||||
|
||||
// Assert
|
||||
expect(result).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("hasSetting", () => {
|
||||
test("has setting => return true", () => {
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
// Act
|
||||
const result = wrapper.vm.hasSetting("Setting4");
|
||||
|
||||
// Assert
|
||||
expect(result).toEqual(true);
|
||||
});
|
||||
|
||||
test("does not have setting => return false", () => {
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
// Act
|
||||
const result = wrapper.vm.hasSetting("BooglyWoogly");
|
||||
|
||||
// Assert
|
||||
expect(result).toEqual(false);
|
||||
});
|
||||
|
||||
test("experimentSettings is empty => return false", () => {
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({ experimentSettings: {} });
|
||||
|
||||
// Act
|
||||
const result = wrapper.vm.hasSetting("Setting4");
|
||||
|
||||
// Assert
|
||||
expect(result).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getSettingValue", () => {
|
||||
test("has setting => return correct value", () => {
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
// Act
|
||||
const result = wrapper.vm.getSettingValue("Setting3");
|
||||
|
||||
// Assert
|
||||
expect(result).toEqual("Value3");
|
||||
});
|
||||
|
||||
test("does not have setting => return null", () => {
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
// Act
|
||||
const result = wrapper.vm.getSettingValue("Hello");
|
||||
|
||||
// Assert
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
test("experimentSettings is empty => return null", () => {
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({ experimentSettings: {} });
|
||||
|
||||
// Act
|
||||
const result = wrapper.vm.getSettingValue("Hello");
|
||||
|
||||
// Assert
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function setupMocks({ experimentSettings }) {
|
||||
const mocks = getMountOptions({});
|
||||
|
||||
const testExperimentSettings = {
|
||||
Setting1: "Value1",
|
||||
Setting2: "Value2",
|
||||
Setting3: "Value3",
|
||||
Setting4: "Value1",
|
||||
Setting5: "Value2",
|
||||
Setting6: "Value3",
|
||||
};
|
||||
|
||||
useMainStore.getters = {
|
||||
experimentSettings: experimentSettings ?? testExperimentSettings,
|
||||
};
|
||||
|
||||
const mockComponent = {
|
||||
template: "<div></div>",
|
||||
mixins: [experimentMixin],
|
||||
};
|
||||
|
||||
const wrapper = shallowMount(mockComponent, mocks);
|
||||
|
||||
return { wrapper };
|
||||
}
|
||||
Loading…
Reference in a new issue