4584 lines
162 KiB
JavaScript
4584 lines
162 KiB
JavaScript
import globalMethods from "@/global-methods";
|
|
import store from "@/store";
|
|
import { mutations, state, actions, getters } from "@/store";
|
|
import { storeMutations } from "@/constants/store-mutations";
|
|
import { storeActions } from "@/constants/store-actions";
|
|
import { endpoints } from "@/constants/endpoints.js";
|
|
import { sessionStorageKeyConstants } from "@/constants/session-storage";
|
|
import { experimentTriggers } from "@/constants/experiments";
|
|
import { routeData } from "@/router/constants/routes";
|
|
import { AppointmentTypeStrings } from "@/constants/schedule-constants";
|
|
|
|
// Mock global method
|
|
globalMethods.callHttpClient = jest.fn();
|
|
|
|
global.crypto = { randomUUID: jest.fn() };
|
|
|
|
describe("Mutations", () => {
|
|
it("Updates vehicle year in state", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
// Act
|
|
mutations.updateYear(storeState, "2019");
|
|
|
|
// Assert
|
|
expect(storeState.order.vehicle.year).toEqual("2019");
|
|
});
|
|
|
|
it("Updates vehicle make in state", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
// Act
|
|
mutations.updateMake(storeState, "Acura");
|
|
|
|
// Assert
|
|
expect(storeState.order.vehicle.make).toEqual("Acura");
|
|
});
|
|
|
|
it("Updates vehicle model in state", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
// Act
|
|
mutations.updateModel(storeState, "ILX");
|
|
|
|
// Assert
|
|
expect(storeState.order.vehicle.model).toEqual("ILX");
|
|
});
|
|
|
|
it("Updates vehicle style in state", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
// Act
|
|
mutations.updateStyle(storeState, "4 DOOR SEDAN");
|
|
|
|
// Assert
|
|
expect(storeState.order.vehicle.style).toEqual("4 DOOR SEDAN");
|
|
});
|
|
|
|
it("Updates vehicle carId in state", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
// Act
|
|
mutations.updateCarId(storeState, "C0000001");
|
|
|
|
// Assert
|
|
expect(storeState.order.vehicle.carId).toEqual("C0000001");
|
|
});
|
|
|
|
it("Updates vehicle vehicle category in state", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
// Act
|
|
mutations.updateVehicleCategory(storeState, "CAR");
|
|
|
|
// Assert
|
|
expect(storeState.order.vehicle.category).toEqual("CAR");
|
|
});
|
|
|
|
it("Remove item to eventBus in state", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
const event = { category: "CategoryOne", subCategory: "SubCategoryOne" };
|
|
|
|
// Act / Assert
|
|
mutations.addEventToBus(storeState, event);
|
|
expect(storeState.applicationUser.eventBus).toEqual([event]);
|
|
|
|
// Act / Assert
|
|
mutations.removeEventFromBus(storeState, event);
|
|
expect(storeState.applicationUser.eventBus).toEqual([]);
|
|
});
|
|
|
|
it("Adds item to eventBus in state", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
// Act
|
|
mutations.addEventToBus(storeState, { EventOne: "ValueOne" });
|
|
|
|
// Assert
|
|
expect(storeState.applicationUser.eventBus).toEqual([{ EventOne: "ValueOne" }]);
|
|
});
|
|
|
|
it("resetVehicleState, should set fields to null", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
mutations.updateYear(storeState, "2019");
|
|
mutations.updateMake(storeState, "Acura");
|
|
mutations.updateModel(storeState, "ILX");
|
|
mutations.updateStyle(storeState, "4 DOOR SEDAN");
|
|
mutations.updateCarId(storeState, "C0000001");
|
|
mutations.updateVehicleCategory(storeState, "CAR");
|
|
|
|
// Expect
|
|
expect(storeState.order.vehicle.year).toEqual("2019");
|
|
expect(storeState.order.vehicle.make).toEqual("Acura");
|
|
expect(storeState.order.vehicle.model).toEqual("ILX");
|
|
expect(storeState.order.vehicle.style).toEqual("4 DOOR SEDAN");
|
|
expect(storeState.order.vehicle.carId).toEqual("C0000001");
|
|
expect(storeState.order.vehicle.category).toEqual("CAR");
|
|
|
|
// Act
|
|
mutations.resetVehicleState(storeState);
|
|
|
|
// Expect
|
|
expect(storeState.order.vehicle.year).toEqual(null);
|
|
expect(storeState.order.vehicle.make).toEqual(null);
|
|
expect(storeState.order.vehicle.model).toEqual(null);
|
|
expect(storeState.order.vehicle.style).toEqual(null);
|
|
expect(storeState.order.vehicle.carId).toEqual(null);
|
|
expect(storeState.order.vehicle.category).toEqual(null);
|
|
});
|
|
|
|
it("resetDamageState, should set fields to null", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
storeState.order.damage = {
|
|
isRepair: true,
|
|
numberOfChips: 2,
|
|
glassToReplace: [{ location: "Rear", name: "Stationary" }],
|
|
};
|
|
|
|
// Expect
|
|
expect(storeState.order.damage.isRepair).toEqual(true);
|
|
expect(storeState.order.damage.numberOfChips).toEqual(2);
|
|
expect(storeState.order.damage.glassToReplace).toStrictEqual([
|
|
{ location: "Rear", name: "Stationary" },
|
|
]);
|
|
|
|
// Act
|
|
mutations.resetDamageState(storeState);
|
|
|
|
// Expect
|
|
expect(storeState.order.damage.isRepair).toEqual(null);
|
|
expect(storeState.order.damage.numberOfChips).toEqual(null);
|
|
expect(storeState.order.damage.glassToReplace).toEqual(null);
|
|
});
|
|
|
|
it("Updates number of chips in state", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
// Act
|
|
mutations.updateNumberOfChips(storeState, "1");
|
|
|
|
// Assert
|
|
expect(storeState.order.damage.numberOfChips).toEqual("1");
|
|
});
|
|
|
|
it("Updates glass to replace in state", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
// Act
|
|
mutations.updateGlassToReplace(storeState, ["Windshield"]);
|
|
|
|
// Assert
|
|
expect(storeState.order.damage.glassToReplace).toEqual(["Windshield"]);
|
|
});
|
|
|
|
it("Updates Parts in state", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
// Act
|
|
mutations.updateGlassParts(storeState, { "Windshield-Single": "PARTNUM101" });
|
|
|
|
// Assert
|
|
expect(storeState.order.lineItems.glassParts).toEqual({
|
|
"Windshield-Single": "PARTNUM101",
|
|
});
|
|
});
|
|
|
|
it("Updates page data in state", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
// Act
|
|
mutations.updatePageData(storeState, { page: "vehicle-year", data: {} });
|
|
|
|
// Assert
|
|
expect(storeState.applicationUser.pageData["vehicle-year"]).toEqual({});
|
|
});
|
|
|
|
it("updateStateWithSessonInformation, should set session information in state", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
// Act
|
|
mutations.updateStateWithOrderInformation(storeState, {
|
|
order: {
|
|
referralNumber: 123,
|
|
referralDate: new Date().toUTCString(),
|
|
referralCorrelationId: "xxx-xxx-xxx",
|
|
vehicle: {
|
|
year: "2019",
|
|
make: "Acura",
|
|
model: "ILX",
|
|
style: "4 DOOR SEDAN",
|
|
carId: "C0000001",
|
|
category: "CAR",
|
|
registration: {},
|
|
},
|
|
policy: {
|
|
insuranceCompanyName: "LibertyBibity",
|
|
},
|
|
damage: {
|
|
glassToReplace: ["Windshield"],
|
|
isRepair: false,
|
|
numberOfChips: 0,
|
|
},
|
|
lineItems: {
|
|
glassParts: null,
|
|
},
|
|
payment: {
|
|
isInsurance: false,
|
|
parentAccountNumber: "123456789",
|
|
},
|
|
insuranceCoverage: {
|
|
isVerified: false,
|
|
coverageStatus: "Pending",
|
|
},
|
|
parts: [],
|
|
insuranceInfo: {},
|
|
serviceLocation: {},
|
|
customer: {},
|
|
},
|
|
applicationUser: {
|
|
experiments: [
|
|
{
|
|
universeName: "Concept Funnel Test With Rules",
|
|
universeId: 463,
|
|
testName: "Concept Dev Test",
|
|
testId: 392,
|
|
variationName: "Concept Test Variation",
|
|
variationId: 1133,
|
|
isActive: false,
|
|
isExposed: true,
|
|
userPartitionNumber: 84,
|
|
assignmentId: 12211739,
|
|
settings: {
|
|
someKey: "false",
|
|
sampleSetting: "Hi, my name is Vidya",
|
|
},
|
|
},
|
|
],
|
|
},
|
|
});
|
|
|
|
// Assert
|
|
expect(storeState.order.referralNumber).toEqual(123);
|
|
expect(storeState.order.referralCorrelationId).toEqual("xxx-xxx-xxx");
|
|
expect(storeState.order.vehicle.year).toEqual("2019");
|
|
expect(storeState.order.vehicle.make).toEqual("Acura");
|
|
expect(storeState.order.vehicle.model).toEqual("ILX");
|
|
});
|
|
|
|
it("updateInsuranceVerifiedStatus, should set isVerified flag", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
// Act
|
|
mutations.updateInsuranceVerifiedStatus(storeState, true);
|
|
|
|
// Assert
|
|
expect(storeState.order.payment.insuranceCoverage.isVerified).toEqual(true);
|
|
});
|
|
|
|
it("updateExperiments, should set experiments", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
const mockExperimentsList = [
|
|
{
|
|
universeName: "XYZ",
|
|
settings: {
|
|
ExperimentSetting: "ExperimentValue",
|
|
},
|
|
},
|
|
];
|
|
|
|
// Act
|
|
mutations.updateExperiments(storeState, mockExperimentsList);
|
|
|
|
// Assert
|
|
expect(storeState.applicationUser.experiments).toEqual(mockExperimentsList);
|
|
});
|
|
|
|
it("updateTriggeredSiteEntry, should set triggeredSiteEntry", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
// Act
|
|
mutations.updateTriggeredSiteEntry(storeState, true);
|
|
|
|
// Assert
|
|
expect(storeState.applicationUser.triggeredSiteEntry).toEqual(true);
|
|
});
|
|
|
|
it("updateServiceLocation, should set serviceLocation in state", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
const serviceLocation = {
|
|
address: "123 Test Lane",
|
|
city: "Columbus",
|
|
zipCode: "43212",
|
|
state: "OH",
|
|
zipCodeCtu: "01820",
|
|
};
|
|
|
|
// Act
|
|
mutations.updateServiceLocation(storeState, serviceLocation);
|
|
|
|
// Assert
|
|
expect(storeState.order.serviceLocation.address).toEqual("123 Test Lane");
|
|
expect(storeState.order.serviceLocation.city).toEqual("Columbus");
|
|
expect(storeState.order.serviceLocation.zipCode).toEqual("43212");
|
|
expect(storeState.order.serviceLocation.state).toEqual("OH");
|
|
expect(storeState.order.serviceLocation.zipCodeCtu).toEqual("01820");
|
|
});
|
|
|
|
it("updateCustomerDetails, should set customer details in state", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
const customerDetails = {
|
|
firstName: "foo",
|
|
lastName: "bar",
|
|
emailAddress: "foo@bar.com",
|
|
phoneNumber: "555-555-5555",
|
|
isSmsOptIn: true,
|
|
};
|
|
|
|
// Act
|
|
mutations.updateCustomerDetails(storeState, customerDetails);
|
|
|
|
// Assert
|
|
expect(state.order.customer.firstName).toEqual("foo");
|
|
expect(state.order.customer.lastName).toEqual("bar");
|
|
expect(state.order.customer.emailAddress).toEqual("foo@bar.com");
|
|
expect(state.order.customer.phoneNumber).toEqual("555-555-5555");
|
|
expect(state.order.customer.isSmsOptIn).toEqual(true);
|
|
});
|
|
|
|
it("incrementSubmittedStateRevision, should increment submittedStateRevision", () => {
|
|
const storeState = { submittedStateRevision: 0 };
|
|
|
|
mutations.incrementSubmittedStateRevision(storeState);
|
|
|
|
expect(storeState.submittedStateRevision).toEqual(1);
|
|
});
|
|
});
|
|
|
|
describe("Actions", () => {
|
|
it("getVehicleYears action, should return years array", async () => {
|
|
// Arrange
|
|
const context = state;
|
|
|
|
// Act
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({ data: [2023, 2022, 2021] });
|
|
});
|
|
|
|
// Assert
|
|
const response = await actions.getVehicleYears(context, { pageNameToLog: "test" });
|
|
|
|
expect(response.data).toEqual([2023, 2022, 2021]);
|
|
});
|
|
|
|
it("lookupVehicleByYmms action, should return car data", async () => {
|
|
// Arrange
|
|
const context = state;
|
|
|
|
// Act
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({ data: { carId: "C00000001" } });
|
|
});
|
|
|
|
// Assert
|
|
const response = await actions.lookupVehicleByYmms(context, {
|
|
payload: {
|
|
year: "2019",
|
|
make: "Acura",
|
|
model: "ILX",
|
|
style: "4 DOOR SEDAN",
|
|
},
|
|
pageNameToLog: "test",
|
|
});
|
|
|
|
expect(response.data).toEqual({ carId: "C00000001" });
|
|
});
|
|
|
|
it("lookupVehicleByVin action, should return car data", async () => {
|
|
// Arrange
|
|
const context = state;
|
|
context.getters = {
|
|
applicationUser: {
|
|
loggingOption: false,
|
|
},
|
|
};
|
|
|
|
// Act
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({ data: { carId: "C0000001" } });
|
|
});
|
|
|
|
// Assert
|
|
const response = await actions.lookupVehicleByVin(context, {
|
|
payload: {
|
|
vin: "12345678901234567",
|
|
},
|
|
pageNameToLog: "test",
|
|
});
|
|
|
|
expect(response.data).toEqual({ carId: "C0000001" });
|
|
});
|
|
|
|
it("lookupVinByPlate action, should return car data", async () => {
|
|
// Arrange
|
|
const context = state;
|
|
|
|
// Act
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({ data: { carId: "C00000001" } });
|
|
});
|
|
|
|
// Assert
|
|
const response = await actions.lookupVinByPlate(context, {
|
|
payload: { licensePlate: "12345678901234567", licenseState: "OH" },
|
|
pageNameToLog: "test",
|
|
});
|
|
|
|
expect(response.data).toEqual({ carId: "C00000001" });
|
|
});
|
|
|
|
it("lookupVinByImage action, should return list of vins", async () => {
|
|
// Arrange
|
|
const context = state;
|
|
const image = new File([], "test.jpg", {
|
|
type: "image/jpeg",
|
|
});
|
|
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({ data: ["1C6JJTAG3NL134044"] });
|
|
});
|
|
|
|
// Act
|
|
const response = await actions.lookupVinByImage(context, {
|
|
payload: image,
|
|
pageNameToLog: "test",
|
|
});
|
|
|
|
// Assert
|
|
expect(response.data).toEqual(["1C6JJTAG3NL134044"]);
|
|
});
|
|
|
|
it("lookupVinByImage action, should reject if error in calling API", async () => {
|
|
// Arrange
|
|
const context = state;
|
|
const image = new File([], "test.jpg", {
|
|
type: "image/jpeg",
|
|
});
|
|
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.reject("An error occurred");
|
|
});
|
|
|
|
// Act
|
|
|
|
// Assert
|
|
await expect(
|
|
actions.lookupVinByImage(context, { payload: image, pageNameToLog: "test" })
|
|
).rejects.toEqual("An error occurred");
|
|
});
|
|
|
|
it("getVehicleMakes action, should return makes list", async () => {
|
|
// Arrange
|
|
const context = state;
|
|
|
|
// Act
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({ data: ["Acura", "Honda"] });
|
|
});
|
|
|
|
// Assert
|
|
const response = await actions.getVehicleMakes(context, {
|
|
payload: { year: "2019" },
|
|
pageNameToLog: "test",
|
|
});
|
|
|
|
expect(response.data).toEqual(["Acura", "Honda"]);
|
|
});
|
|
|
|
it("getVehicleModels action, should return models list", async () => {
|
|
// Arrange
|
|
const context = state;
|
|
|
|
// Act
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({ data: ["ILX", "RDX"] });
|
|
});
|
|
|
|
// Assert
|
|
const response = await actions.getVehicleModels(context, {
|
|
payload: { year: "2019", make: "Acura" },
|
|
pageNameToLog: "test",
|
|
});
|
|
|
|
expect(response.data).toEqual(["ILX", "RDX"]);
|
|
});
|
|
|
|
it("getVehicleStyles action, should return models list", async () => {
|
|
// Arrange
|
|
const context = state;
|
|
|
|
// Act
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({ data: { style: "4 DOOR SEDAN" } });
|
|
});
|
|
|
|
// Assert
|
|
const response = await actions.getVehicleStyles(context, {
|
|
payload: { year: "2019", make: "Acura", model: "ILX" },
|
|
pageNameToLog: "test",
|
|
});
|
|
|
|
expect(response.data).toEqual({ style: "4 DOOR SEDAN" });
|
|
});
|
|
|
|
it("getVehicle action, should get vehicle data ", async () => {
|
|
// Arrange
|
|
const context = state;
|
|
|
|
// Act
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({ data: { carId: "C00000000", category: "CAR" } });
|
|
});
|
|
|
|
// Assert
|
|
const response = await actions.getVehicle(context, {
|
|
payload: { year: "2019", make: "Acura", model: "IDX", style: "4-door sedan" },
|
|
pageNameToLog: "test",
|
|
});
|
|
|
|
expect(response.data).toEqual({ carId: "C00000000", category: "CAR" });
|
|
});
|
|
|
|
it("getDamageOptions action", async () => {
|
|
// Arrange
|
|
const context = state;
|
|
|
|
// Act
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({ data: ["Windshield", "DriversFrontDoor"] });
|
|
});
|
|
|
|
const response = await actions.getDamageOptions(context, {
|
|
payload: { carId: "C00000000" },
|
|
pageNameToLog: "test",
|
|
});
|
|
|
|
// Assert
|
|
expect(response.data).toEqual(["Windshield", "DriversFrontDoor"]);
|
|
});
|
|
|
|
it("validateZip action", async () => {
|
|
// Arrange
|
|
const context = state;
|
|
context.getters = {
|
|
damage: {
|
|
isRepair: "false",
|
|
},
|
|
};
|
|
|
|
// Act
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({
|
|
data: {
|
|
isValid: true,
|
|
isServiceable: true,
|
|
state: "OH",
|
|
zipCodeCtu: "01820",
|
|
},
|
|
});
|
|
});
|
|
|
|
const response = await actions.validateZip(context, {
|
|
payload: { zip: "43212" },
|
|
pageNameToLog: "test",
|
|
});
|
|
|
|
// Assert
|
|
expect(response.data).toEqual({
|
|
isValid: true,
|
|
isServiceable: true,
|
|
state: "OH",
|
|
zipCodeCtu: "01820",
|
|
});
|
|
});
|
|
|
|
it("resetDamageAndDependencies action", async () => {
|
|
// Arrange
|
|
const context = state;
|
|
const commit = jest.fn();
|
|
const dispatch = jest.fn();
|
|
|
|
context.commit = commit;
|
|
context.dispatch = dispatch;
|
|
|
|
// Act
|
|
await actions.resetDamageAndDependencies(context);
|
|
|
|
expect(commit).toBeCalledWith(storeMutations.RESET_DAMAGE_STATE);
|
|
expect(dispatch).toBeCalledWith(storeActions.RESET_PARTS_STATE_AND_DEPENDENCIES);
|
|
});
|
|
|
|
it("resetRegistrationAndDependencies action", async () => {
|
|
// Arrange
|
|
const context = state;
|
|
const commit = jest.fn();
|
|
const dispatch = jest.fn();
|
|
|
|
context.commit = commit;
|
|
context.dispatch = dispatch;
|
|
|
|
// Act
|
|
await actions.resetRegistrationAndDependencies(context);
|
|
|
|
expect(commit).toBeCalledWith(storeMutations.RESET_REGISTRATION_STATE);
|
|
expect(dispatch).toBeCalledWith(storeActions.RESET_PARTS_STATE_AND_DEPENDENCIES);
|
|
});
|
|
|
|
it("resetPartsAndDependencies action", async () => {
|
|
// Arrange
|
|
const context = state;
|
|
const commit = jest.fn();
|
|
const dispatch = jest.fn();
|
|
|
|
context.commit = commit;
|
|
context.dispatch = dispatch;
|
|
|
|
// Act
|
|
await actions.resetPartsAndDependencies(context);
|
|
|
|
expect(commit).toBeCalledWith(storeMutations.RESET_GLASS_PARTS_STATE);
|
|
expect(dispatch).toBeCalledWith(storeActions.RESET_SERVICE_LOCATION_STATE_AND_DEPENDENCIES);
|
|
});
|
|
|
|
it("resetState action", async () => {
|
|
// Arrange
|
|
const context = state;
|
|
const commit = jest.fn();
|
|
|
|
context.commit = commit;
|
|
|
|
// Act
|
|
await actions.resetState(context);
|
|
|
|
expect(commit).toBeCalledWith(storeMutations.RESET_STATE);
|
|
});
|
|
|
|
it("getPageData action, returns page data", async () => {
|
|
// Arrange
|
|
const context = state;
|
|
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({ data: { Results: [{ Widget: "Data" }] } });
|
|
});
|
|
|
|
// Act
|
|
const response = await actions.getPageData(context, "vehicle-year");
|
|
|
|
expect(response.data).toEqual({ Results: [{ Widget: "Data" }] });
|
|
});
|
|
|
|
it("getEvoxImage action, returns image url", async () => {
|
|
// Arrange
|
|
const context = state;
|
|
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({ data: { imageUrl: "https://test.com" } });
|
|
});
|
|
|
|
// Act
|
|
const response = await actions.getEvoxImage(context, {
|
|
relativeUrl: "https://relativeurl.com",
|
|
});
|
|
|
|
expect(response.data).toEqual({ imageUrl: "https://test.com" });
|
|
});
|
|
|
|
it("saveSession action, returns order information", async () => {
|
|
// Arrange
|
|
const context = state;
|
|
|
|
context.getters = {
|
|
vehicle: {
|
|
registration: {},
|
|
},
|
|
order: {
|
|
damage: {
|
|
numberOfChips: "2",
|
|
partQuestionAnswers: {},
|
|
moldingQuestionAnswers: {},
|
|
capabilityQuestionAnswers: {},
|
|
},
|
|
},
|
|
damage: {},
|
|
applicationUser: {
|
|
lastPageVisited: "test-page",
|
|
crmCustomerId: "xxx-xxx-xxx",
|
|
savedSessionId: "xxx-xxx-xxx",
|
|
},
|
|
};
|
|
context.state = {
|
|
order: {
|
|
damage: {
|
|
numberOfChips: "2",
|
|
partQuestionAnswers: {},
|
|
moldingQuestionAnswers: {},
|
|
capabilityQuestionAnswers: {},
|
|
},
|
|
payment: {
|
|
insuranceCoverage: {
|
|
isVerified: false,
|
|
},
|
|
isInsurance: false,
|
|
ccToken: {
|
|
subscriptionId: null,
|
|
expMonth: null,
|
|
expYear: null,
|
|
cardType: null,
|
|
billToPostalCode: null,
|
|
billToFirstName: null,
|
|
billToLastName: null,
|
|
referenceNumber: null,
|
|
authCode: null,
|
|
transactionId: null,
|
|
transReferenceNumber: null,
|
|
lastFour: null,
|
|
},
|
|
},
|
|
serviceLocation: {},
|
|
customer: {
|
|
emailAddress: "test@safelite.com",
|
|
firstName: "John",
|
|
lastName: "Doe",
|
|
isSmsOptIn: true,
|
|
phoneNumber: "1234567890",
|
|
address: {
|
|
streetAddress: "123 Main St",
|
|
streetAddress2: "Apt 1",
|
|
city: "Anytown",
|
|
state: "OH",
|
|
zipCode: "12345",
|
|
},
|
|
},
|
|
lineItems: {},
|
|
},
|
|
};
|
|
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({ data: { referralNumber: 123 } });
|
|
});
|
|
|
|
// Act
|
|
const response = await actions.saveSession(context, { pageNameToLog: "test" });
|
|
|
|
// Assert
|
|
expect(response.data).toEqual({ referralNumber: 123 });
|
|
});
|
|
|
|
it("loadSession action, returns order information, calls mutation", async () => {
|
|
// Arrange
|
|
const context = state;
|
|
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({ data: { referralNumber: 123, order: {} } });
|
|
});
|
|
|
|
const commit = jest.fn();
|
|
|
|
context.commit = commit;
|
|
|
|
// Act
|
|
const response = await actions.loadSession(context, {
|
|
payload: {
|
|
savedSessionId: "",
|
|
referralDate: "2024-12-11T00:29:41.967",
|
|
},
|
|
pageNameToLog: "test",
|
|
});
|
|
|
|
// Assert
|
|
expect(response.data).toEqual({ referralNumber: 123, order: {} });
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_STATE_WITH_ORDER_INFORMATION, {
|
|
referralNumber: 123,
|
|
order: {},
|
|
});
|
|
});
|
|
|
|
it("loadSession: state doesn't have EON => do not reset state", async () => {
|
|
// Arrange
|
|
const context = state;
|
|
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({ data: { eon: "123", order: {} } });
|
|
});
|
|
|
|
context.commit = jest.fn();
|
|
context.state = {
|
|
order: {},
|
|
};
|
|
|
|
// Act
|
|
const response = await actions.loadSession(context, {
|
|
payload: {
|
|
savedSessionId: "",
|
|
referralDate: "2024-12-11T00:29:41.967",
|
|
},
|
|
pageNameToLog: "test",
|
|
});
|
|
|
|
// Assert
|
|
expect(response.data.eon).toEqual("123");
|
|
expect(context.commit).not.toBeCalledWith(storeMutations.RESET_STATE);
|
|
});
|
|
|
|
it("loadSession eon doesn't match eon in state => reset state", async () => {
|
|
// Arrange
|
|
const context = state;
|
|
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({ data: { eon: "123", order: {} } });
|
|
});
|
|
|
|
context.commit = jest.fn();
|
|
context.state = {
|
|
order: {
|
|
eon: "456",
|
|
},
|
|
};
|
|
|
|
// Act
|
|
const response = await actions.loadSession(context, {
|
|
payload: {
|
|
savedSessionId: "",
|
|
referralDate: "2024-12-11T00:29:41.967",
|
|
},
|
|
pageNameToLog: "test",
|
|
});
|
|
|
|
// Assert
|
|
expect(response.data.eon).toEqual("123");
|
|
expect(context.commit).toBeCalledWith(storeMutations.RESET_STATE);
|
|
});
|
|
|
|
it("updateStoreWithSaveSessionResponse, should call commit six times", () => {
|
|
// Arrange
|
|
const context = state;
|
|
const commit = jest.fn();
|
|
|
|
context.commit = commit;
|
|
|
|
// Act
|
|
actions.updateStoreWithSaveSessionResponse(context, {
|
|
referralNumber: "123",
|
|
referralSequenceNumber: 123,
|
|
referralDate: new Date().toUTCString(),
|
|
referralCorrelationId: "xxx-xxx-xxx",
|
|
parentAccountNumber: "167132",
|
|
savedSessionId: "xxx-xxx-xxx",
|
|
crmCustomerId: "xxx-xxx-xxx",
|
|
});
|
|
|
|
// Assert
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_REFERRAL_NUMBER, "123");
|
|
expect(commit).toBeCalledWith(
|
|
storeMutations.UPDATE_REFERRAL_DATE,
|
|
new Date().toUTCString()
|
|
);
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_REFERRAL_CORRELATION_ID, "xxx-xxx-xxx");
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_PARENT_ACCT_NUMBER, "167132");
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_SAVED_SESSION_ID, "xxx-xxx-xxx");
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_CRM_CUSTOMER_ID, "xxx-xxx-xxx");
|
|
});
|
|
|
|
it("logPageView action, should return nothing", async () => {
|
|
// Arrange
|
|
const context = state;
|
|
var pageEvent = {
|
|
action: "",
|
|
event: "ENTRY",
|
|
};
|
|
|
|
// Act
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({});
|
|
});
|
|
|
|
// Assert
|
|
const response = await actions.logPageView(context, {
|
|
userId: "userId",
|
|
sessionKey: "sessionKey",
|
|
pageName: "pageName",
|
|
sessionId: "sessionId",
|
|
pageEvent: pageEvent,
|
|
shouldUseSessionId: false,
|
|
});
|
|
expect(response).toEqual({});
|
|
});
|
|
|
|
it("logCustomEvent action, should return nothing", async () => {
|
|
// Arrange
|
|
const context = state;
|
|
var customEvent = {
|
|
category: "tstCat",
|
|
action: "click",
|
|
label: "damage",
|
|
value: "psych",
|
|
};
|
|
|
|
// Act
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({});
|
|
});
|
|
|
|
// Assert
|
|
const response = await actions.logCustomEvent(context, {
|
|
userId: "userId",
|
|
sessionKey: "sessionKey",
|
|
pageName: "pageName",
|
|
sessionId: "sessionId",
|
|
customEvent: customEvent,
|
|
category: "category",
|
|
shouldUseSessionId: false,
|
|
});
|
|
expect(response).toEqual({});
|
|
});
|
|
|
|
it("initializeSession action, should return nothing", async () => {
|
|
// Arrange
|
|
const context = state;
|
|
|
|
// Act
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({});
|
|
});
|
|
|
|
// Assert
|
|
const response = await actions.initializeSession(context, {
|
|
userId: "userId",
|
|
sessionId: "",
|
|
userAgent: "",
|
|
referrer: "",
|
|
shouldUseSessionId: false,
|
|
});
|
|
expect(response).toEqual({});
|
|
});
|
|
|
|
it("saveVin, should call mutation when CarId is different and selectedGlass is not available for vehicle", () => {
|
|
// Arrange
|
|
const context = state;
|
|
|
|
context.state = {
|
|
order: {
|
|
vehicle: {
|
|
vin: "YYYYY",
|
|
},
|
|
},
|
|
};
|
|
|
|
const commit = jest.fn();
|
|
const dispatch = jest.fn();
|
|
|
|
context.commit = commit;
|
|
context.dispatch = dispatch;
|
|
|
|
// Act
|
|
actions.saveVin(context, {
|
|
isCarIdDifferent: true,
|
|
isSelectedGlassAvailableForVehicle: false,
|
|
vehicleInfo: { carId: "C010101", vin: "XXXXX" },
|
|
});
|
|
|
|
// Assert
|
|
expect(dispatch).toBeCalledWith(storeActions.RESET_DAMAGE_STATE_AND_DEPENDENCIES);
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_VEHICLE, {
|
|
carId: "C010101",
|
|
vin: "XXXXX",
|
|
});
|
|
});
|
|
|
|
it("saveEmail, should call mutation", () => {
|
|
// Arrange
|
|
const context = state;
|
|
const commit = jest.fn();
|
|
|
|
context.commit = commit;
|
|
|
|
// Act
|
|
actions.saveEmail(context, "test@safelite.com");
|
|
|
|
// Assert
|
|
expect(commit).toBeCalledWith(
|
|
storeMutations.UPDATE_CUSTOMER_EMAIL_ADDRESS,
|
|
"test@safelite.com"
|
|
);
|
|
});
|
|
|
|
it("saveServiceZipCodeInfo, should call mutation", () => {
|
|
// Arrange
|
|
const context = state;
|
|
const commit = jest.fn();
|
|
context.commit = commit;
|
|
|
|
const serviceZipCodeInfo = {
|
|
zipCode: "43212",
|
|
};
|
|
|
|
// Act
|
|
actions.saveServiceLocation(context, serviceZipCodeInfo);
|
|
|
|
// Assert
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_SERVICE_LOCATION, serviceZipCodeInfo);
|
|
});
|
|
|
|
it("saveServiceZipCodeInfo, should reset if zip code is different", () => {
|
|
// Arrange
|
|
const context = {
|
|
state: {
|
|
order: {
|
|
serviceLocation: {
|
|
zipCode: "43212",
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
const commit = jest.fn();
|
|
const dispatch = jest.fn();
|
|
|
|
context.commit = commit;
|
|
context.dispatch = dispatch;
|
|
|
|
const serviceZipCodeInfo = {
|
|
zipCode: "43202",
|
|
};
|
|
|
|
// Act
|
|
actions.saveServiceZipCodeInfo(context, serviceZipCodeInfo);
|
|
|
|
// Assert
|
|
expect(dispatch).toHaveBeenCalledWith(
|
|
storeActions.RESET_SERVICE_LOCATION_STATE_AND_DEPENDENCIES
|
|
);
|
|
expect(commit).toHaveBeenCalledWith(storeMutations.RESET_SERVICE_LOCATION_MOBILE_ADDRESS);
|
|
});
|
|
|
|
it("saveServiceZipCodeInfo, should not reset if zip code is the same", () => {
|
|
// Arrange
|
|
const context = {
|
|
state: {
|
|
order: {
|
|
serviceLocation: {
|
|
zipCode: "43212",
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
const commit = jest.fn();
|
|
const dispatch = jest.fn();
|
|
|
|
context.commit = commit;
|
|
context.dispatch = dispatch;
|
|
|
|
const serviceZipCodeInfo = {
|
|
zipCode: "43212",
|
|
};
|
|
|
|
// Act
|
|
actions.saveServiceZipCodeInfo(context, serviceZipCodeInfo);
|
|
|
|
// Assert
|
|
expect(dispatch).not.toHaveBeenCalledWith(
|
|
storeActions.RESET_SERVICE_LOCATION_STATE_AND_DEPENDENCIES
|
|
);
|
|
expect(commit).not.toHaveBeenCalledWith(
|
|
storeMutations.RESET_SERVICE_LOCATION_MOBILE_ADDRESS
|
|
);
|
|
});
|
|
|
|
it("saveServiceLocation, should call mutation", () => {
|
|
// Arrange
|
|
const context = state;
|
|
const commit = jest.fn();
|
|
context.commit = commit;
|
|
|
|
const serviceLocation = {
|
|
address: "123 Test Lane",
|
|
city: "Columbus",
|
|
zipCode: "43212",
|
|
state: "OH",
|
|
zipCodeCtu: "01820",
|
|
};
|
|
|
|
// Act
|
|
actions.saveServiceLocation(context, serviceLocation);
|
|
|
|
// Assert
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_SERVICE_LOCATION, serviceLocation);
|
|
});
|
|
|
|
it("saveServiceLocation, should reset if zipcode is different", () => {
|
|
// Arrange
|
|
const context = {
|
|
state: {
|
|
order: {
|
|
serviceLocation: {
|
|
address: "123 Test Lane",
|
|
city: "Columbus",
|
|
zipCode: "43212",
|
|
state: "OH",
|
|
zipCodeCtu: "01820",
|
|
appointmentType: "Mobile",
|
|
isVehicleProtected: true,
|
|
provider: {
|
|
providerNumber: "11111",
|
|
address: {
|
|
streetAddress: "123 Test Lane",
|
|
city: "Columbus",
|
|
state: "OH",
|
|
zipCode: "43212",
|
|
zipCodeCtu: "01820",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
const commit = jest.fn();
|
|
const dispatch = jest.fn();
|
|
|
|
context.commit = commit;
|
|
context.dispatch = dispatch;
|
|
|
|
const serviceLocation = {
|
|
address: "123 Test Lane",
|
|
city: "Columbus",
|
|
zipCode: "43202",
|
|
state: "OH",
|
|
zipCodeCtu: "01820",
|
|
appointmentType: "Mobile",
|
|
isVehicleProtected: true,
|
|
provider: {
|
|
providerNumber: "11111",
|
|
address: {
|
|
streetAddress: "123 Test Lane",
|
|
city: "Columbus",
|
|
state: "OH",
|
|
zipCode: "43212",
|
|
zipCodeCtu: "01820",
|
|
},
|
|
},
|
|
};
|
|
|
|
// Act
|
|
actions.saveServiceLocation(context, serviceLocation);
|
|
|
|
// Assert
|
|
expect(commit).toHaveBeenCalledWith(storeMutations.RESET_SCHEDULE);
|
|
});
|
|
|
|
it("saveServiceLocation, should reset if provider is different", () => {
|
|
// Arrange
|
|
const context = {
|
|
state: {
|
|
order: {
|
|
serviceLocation: {
|
|
address: "123 Test Lane",
|
|
city: "Columbus",
|
|
zipCode: "43212",
|
|
state: "OH",
|
|
zipCodeCtu: "01820",
|
|
appointmentType: "Mobile",
|
|
isVehicleProtected: true,
|
|
provider: {
|
|
providerNumber: "11111",
|
|
address: {
|
|
streetAddress: "123 Test Lane",
|
|
city: "Columbus",
|
|
state: "OH",
|
|
zipCode: "43212",
|
|
zipCodeCtu: "01820",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
const commit = jest.fn();
|
|
const dispatch = jest.fn();
|
|
|
|
context.commit = commit;
|
|
context.dispatch = dispatch;
|
|
|
|
const serviceLocation = {
|
|
address: "123 Test Lane",
|
|
city: "Columbus",
|
|
zipCode: "43212",
|
|
state: "OH",
|
|
zipCodeCtu: "01820",
|
|
appointmentType: "Mobile",
|
|
isVehicleProtected: true,
|
|
provider: {
|
|
providerNumber: "22222",
|
|
address: {
|
|
streetAddress: "321 Test Lane",
|
|
city: "Columbus",
|
|
state: "OH",
|
|
zipCode: "43212",
|
|
zipCodeCtu: "01820",
|
|
},
|
|
},
|
|
};
|
|
|
|
// Act
|
|
actions.saveServiceLocation(context, serviceLocation);
|
|
|
|
// Assert
|
|
expect(commit).toHaveBeenCalledWith(storeMutations.RESET_SCHEDULE);
|
|
});
|
|
|
|
it("saveServiceLocation, should reset if appointment type is different", () => {
|
|
// Arrange
|
|
const context = {
|
|
state: {
|
|
order: {
|
|
serviceLocation: {
|
|
address: "123 Test Lane",
|
|
city: "Columbus",
|
|
zipCode: "43212",
|
|
state: "OH",
|
|
zipCodeCtu: "01820",
|
|
appointmentType: "Mobile",
|
|
isVehicleProtected: true,
|
|
provider: {
|
|
providerNumber: "11111",
|
|
address: {
|
|
streetAddress: "123 Test Lane",
|
|
city: "Columbus",
|
|
state: "OH",
|
|
zipCode: "43212",
|
|
zipCodeCtu: "01820",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
const commit = jest.fn();
|
|
const dispatch = jest.fn();
|
|
|
|
context.commit = commit;
|
|
context.dispatch = dispatch;
|
|
|
|
const serviceLocation = {
|
|
address: "123 Test Lane",
|
|
city: "Columbus",
|
|
zipCode: "43212",
|
|
state: "OH",
|
|
zipCodeCtu: "01820",
|
|
appointmentType: "Inshop",
|
|
isVehicleProtected: true,
|
|
provider: {
|
|
providerNumber: "11111",
|
|
address: {
|
|
streetAddress: "123 Test Lane",
|
|
city: "Columbus",
|
|
state: "OH",
|
|
zipCode: "43212",
|
|
zipCodeCtu: "01820",
|
|
},
|
|
},
|
|
};
|
|
|
|
// Act
|
|
actions.saveServiceLocation(context, serviceLocation);
|
|
|
|
// Assert
|
|
expect(commit).toHaveBeenCalledWith(storeMutations.RESET_SCHEDULE);
|
|
});
|
|
|
|
it("saveServiceLocation, should not reset if parameters are the same", () => {
|
|
// Arrange
|
|
const context = {
|
|
state: {
|
|
order: {
|
|
serviceLocation: {
|
|
address: "123 Test Lane",
|
|
city: "Columbus",
|
|
zipCode: "43212",
|
|
state: "OH",
|
|
zipCodeCtu: "01820",
|
|
appointmentType: "Mobile",
|
|
isVehicleProtected: true,
|
|
provider: {
|
|
providerNumber: "11111",
|
|
address: {
|
|
streetAddress: "123 Test Lane",
|
|
city: "Columbus",
|
|
state: "OH",
|
|
zipCode: "43212",
|
|
zipCodeCtu: "01820",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
const commit = jest.fn();
|
|
const dispatch = jest.fn();
|
|
|
|
context.commit = commit;
|
|
context.dispatch = dispatch;
|
|
|
|
const serviceLocation = {
|
|
address: "123 Test Lane",
|
|
city: "Columbus",
|
|
zipCode: "43212",
|
|
state: "OH",
|
|
zipCodeCtu: "01820",
|
|
appointmentType: "Mobile",
|
|
isVehicleProtected: true,
|
|
provider: {
|
|
providerNumber: "11111",
|
|
address: {
|
|
streetAddress: "123 Test Lane",
|
|
city: "Columbus",
|
|
state: "OH",
|
|
zipCode: "43212",
|
|
zipCodeCtu: "01820",
|
|
},
|
|
},
|
|
};
|
|
|
|
// Act
|
|
actions.saveServiceLocation(context, serviceLocation);
|
|
|
|
// Assert
|
|
expect(commit).not.toHaveBeenCalledWith(storeMutations.RESET_SCHEDULE);
|
|
});
|
|
|
|
it("saveCustomerDetails, should call mutation", () => {
|
|
// Arrange
|
|
const context = state;
|
|
const commit = jest.fn();
|
|
context.commit = commit;
|
|
|
|
const customerDetails = {
|
|
firstName: "foo",
|
|
lastName: "bar",
|
|
emailAddress: "foo@bar.com",
|
|
phoneNumber: "555-555-5555",
|
|
isSmsOptIn: true,
|
|
};
|
|
|
|
// Act
|
|
actions.saveCustomerDetails(context, customerDetails);
|
|
|
|
// Assert
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_CUSTOMER_DETAILS, customerDetails);
|
|
});
|
|
|
|
it("saveGlassParts, should call mutation", () => {
|
|
// Arrange
|
|
const context = {
|
|
state: state,
|
|
};
|
|
|
|
context.state.order.lineItems = [];
|
|
|
|
const commit = jest.fn();
|
|
const dispatch = jest.fn();
|
|
|
|
context.commit = commit;
|
|
context.dispatch = dispatch;
|
|
|
|
// Act
|
|
actions.saveGlassParts(context, []);
|
|
|
|
// Assert
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_GLASS_PARTS, []);
|
|
expect(dispatch).toBeCalledWith(storeActions.RESET_SERVICE_LOCATION_STATE_AND_DEPENDENCIES);
|
|
});
|
|
|
|
it("saveSupportingItems, should call mutations", () => {
|
|
// Arrange
|
|
const context = {
|
|
state: state,
|
|
};
|
|
|
|
const commit = jest.fn();
|
|
const dispatch = jest.fn();
|
|
|
|
context.commit = commit;
|
|
context.dispatch = dispatch;
|
|
|
|
// Act
|
|
actions.saveSupportingItems(context, []);
|
|
|
|
// Assert
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_SUPPORTING_ITEMS, []);
|
|
});
|
|
|
|
it("saveSupportingItems, should call reset logic when value is new", () => {
|
|
// Arrange
|
|
const context = {
|
|
state: {
|
|
order: {
|
|
lineItems: {
|
|
supportingItems: [{ partNum: "TestValue1" }, { partNum: "TestValue2" }],
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
const commit = jest.fn();
|
|
const dispatch = jest.fn();
|
|
|
|
context.commit = commit;
|
|
context.dispatch = dispatch;
|
|
|
|
// Act
|
|
actions.saveSupportingItems(context, [
|
|
{ partNum: "TestValue3" },
|
|
{ partNum: "TestValue4" },
|
|
{ partNum: "TestValue5" },
|
|
]);
|
|
|
|
// Assert
|
|
expect(dispatch).toBeCalledWith(storeActions.RESET_SERVICE_LOCATION_STATE_AND_DEPENDENCIES);
|
|
});
|
|
|
|
it("saveSupportingItems, should not call reset logic when value is the same", () => {
|
|
// Arrange
|
|
const context = {
|
|
state: {
|
|
order: {
|
|
lineItems: {
|
|
supportingItems: [{ partNum: "TestValue1" }, { partNum: "TestValue2" }],
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
const commit = jest.fn();
|
|
const dispatch = jest.fn();
|
|
|
|
context.commit = commit;
|
|
context.dispatch = dispatch;
|
|
|
|
// Act
|
|
actions.saveSupportingItems(context, [
|
|
{ partNum: "TestValue1" },
|
|
{ partNum: "TestValue2" },
|
|
]);
|
|
|
|
// Assert
|
|
expect(dispatch).not.toBeCalledWith(
|
|
storeActions.RESET_SERVICE_LOCATION_STATE_AND_DEPENDENCIES
|
|
);
|
|
});
|
|
|
|
it("clearVin, should call mutation", () => {
|
|
// Arrange
|
|
const context = state;
|
|
const commit = jest.fn();
|
|
|
|
context.commit = commit;
|
|
|
|
// Act
|
|
actions.clearVin(context);
|
|
|
|
// Assert
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_VEHICLE_VIN, null);
|
|
});
|
|
|
|
it("saveVinLookup, should call mutation if vin is different", () => {
|
|
// Arrange
|
|
const context = state;
|
|
const commit = jest.fn();
|
|
const dispatch = jest.fn();
|
|
|
|
context.commit = commit;
|
|
context.dispatch = dispatch;
|
|
|
|
// Act
|
|
const payload = {
|
|
isCarIdDifferent: true,
|
|
isSelectedGlassAvailableForVehicle: false,
|
|
vehicleInfo: {
|
|
carId: "C010101",
|
|
vin: "XXXXX",
|
|
},
|
|
registrationInfo: {
|
|
zipCode: "80020",
|
|
},
|
|
serviceLocationInfo: {
|
|
state: "CO",
|
|
},
|
|
customerEmail: "test@safleite.com",
|
|
};
|
|
|
|
actions.saveVinLookup(context, payload);
|
|
|
|
// Assert
|
|
expect(dispatch).toHaveBeenNthCalledWith(
|
|
1,
|
|
storeActions.RESET_REGISTRATION_STATE_AND_DEPENDENCIES
|
|
);
|
|
expect(dispatch).toHaveBeenNthCalledWith(
|
|
2,
|
|
storeActions.RESET_PARTS_STATE_AND_DEPENDENCIES
|
|
);
|
|
expect(dispatch).toHaveBeenNthCalledWith(
|
|
3,
|
|
storeActions.RESET_DAMAGE_STATE_AND_DEPENDENCIES
|
|
);
|
|
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_VEHICLE, payload.vehicleInfo);
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_REGISTRATION, payload.registrationInfo);
|
|
});
|
|
|
|
it("saveRegistrationLicensePlateLookup, should call mutation if LP is different", () => {
|
|
// Arrange
|
|
const context = state;
|
|
|
|
context.state = {
|
|
order: {
|
|
vehicle: {
|
|
registration: {
|
|
licensePlate: "ABC123",
|
|
},
|
|
},
|
|
customer: {
|
|
firstName: "test",
|
|
lastName: "test",
|
|
},
|
|
},
|
|
};
|
|
|
|
context.getters = {
|
|
...getters,
|
|
order: getters.order(context),
|
|
};
|
|
|
|
const commit = jest.fn();
|
|
const dispatch = jest.fn();
|
|
|
|
context.commit = commit;
|
|
context.dispatch = dispatch;
|
|
|
|
// Act
|
|
const payload = {
|
|
isCarIdDifferent: true,
|
|
isSelectedGlassAvailableForVehicle: false,
|
|
vehicleInfo: { carId: "C010101", vin: "XXXXX" },
|
|
registrationInfo: { zipCode: "80020", licensePlate: "ALQX35" },
|
|
serviceLocationInfo: { state: "CO" },
|
|
customerEmail: "test@safelite.com",
|
|
};
|
|
|
|
actions.saveRegistrationLicensePlateLookup(context, payload);
|
|
|
|
// Assert
|
|
expect(dispatch).toHaveBeenNthCalledWith(
|
|
1,
|
|
storeActions.RESET_REGISTRATION_STATE_AND_DEPENDENCIES
|
|
);
|
|
expect(dispatch).toHaveBeenNthCalledWith(
|
|
2,
|
|
storeActions.RESET_DAMAGE_STATE_AND_DEPENDENCIES
|
|
);
|
|
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_VEHICLE, payload.vehicleInfo);
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_REGISTRATION, payload.registrationInfo);
|
|
});
|
|
|
|
it("saveRegistrationAddressLookup, should call mutation when address is different", () => {
|
|
// Arrange
|
|
const context = state;
|
|
|
|
context.state = {
|
|
order: {
|
|
vehicle: {
|
|
registration: {
|
|
address: "123 Main St",
|
|
},
|
|
},
|
|
customer: {
|
|
firstName: "test",
|
|
lastName: "test",
|
|
},
|
|
},
|
|
};
|
|
|
|
context.getters = {
|
|
...getters,
|
|
order: getters.order(context),
|
|
};
|
|
|
|
const commit = jest.fn();
|
|
const dispatch = jest.fn();
|
|
|
|
context.commit = commit;
|
|
context.dispatch = dispatch;
|
|
|
|
// Act
|
|
const payload = {
|
|
isCarIdDifferent: true,
|
|
isSelectedGlassAvailableForVehicle: false,
|
|
vehicleInfo: { carId: "C010101", vin: "XXXXX" },
|
|
customerInfo: { firstName: "abc", lastName: "123" },
|
|
serviceLocationInfo: { state: "CO" },
|
|
customerEmail: "test@safelite.com",
|
|
};
|
|
|
|
actions.saveRegistrationAddressLookup(context, payload);
|
|
|
|
// Assert
|
|
expect(dispatch).toHaveBeenNthCalledWith(
|
|
1,
|
|
storeActions.RESET_REGISTRATION_STATE_AND_DEPENDENCIES
|
|
);
|
|
expect(dispatch).toHaveBeenNthCalledWith(
|
|
2,
|
|
storeActions.RESET_DAMAGE_STATE_AND_DEPENDENCIES
|
|
);
|
|
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_VEHICLE, payload.vehicleInfo);
|
|
});
|
|
|
|
it("saveVehicle, should save vehicle info", () => {
|
|
// Arrange
|
|
const context = state;
|
|
|
|
context.state = {
|
|
order: {
|
|
vehicle: {
|
|
year: "2016",
|
|
make: "Toyota",
|
|
model: "Accord",
|
|
style: "SUV",
|
|
},
|
|
},
|
|
};
|
|
|
|
const commit = jest.fn();
|
|
const dispatch = jest.fn();
|
|
|
|
context.commit = commit;
|
|
context.dispatch = dispatch;
|
|
|
|
//Act
|
|
const payload = {
|
|
year: "2015",
|
|
make: "Honda",
|
|
model: "Civic",
|
|
style: "Sedan",
|
|
carId: "C00000000",
|
|
category: "CAR",
|
|
};
|
|
actions.saveVehicle(context, payload);
|
|
|
|
//Assert
|
|
expect(dispatch).toHaveBeenNthCalledWith(
|
|
1,
|
|
storeActions.RESET_DAMAGE_STATE_AND_DEPENDENCIES
|
|
);
|
|
expect(dispatch).toHaveBeenNthCalledWith(
|
|
2,
|
|
storeActions.RESET_REGISTRATION_STATE_AND_DEPENDENCIES
|
|
);
|
|
if (context.state.order.vehicle.year !== payload.year) {
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_YEAR, payload.year);
|
|
}
|
|
if (context.state.order.vehicle.make !== payload.make) {
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_MAKE, payload.make);
|
|
}
|
|
if (context.state.order.vehicle.model !== payload.model) {
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_MODEL, payload.model);
|
|
}
|
|
if (context.state.order.vehicle.style !== payload.style) {
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_STYLE, payload.style);
|
|
}
|
|
context.commit(storeMutations.UPDATE_CAR_ID, payload.carId);
|
|
context.commit(storeMutations.UPDATE_VEHICLE_CATEGORY, payload.category);
|
|
});
|
|
|
|
it("saveVehicleDamage, should wipe out damage if different", () => {
|
|
// Arrange
|
|
const context = state;
|
|
|
|
context.state = {
|
|
order: {
|
|
damage: {
|
|
glassToReplace: [{ glassName: "Single", glassLocation: "Windshield" }],
|
|
},
|
|
},
|
|
};
|
|
|
|
const commit = jest.fn();
|
|
const dispatch = jest.fn();
|
|
|
|
context.commit = commit;
|
|
context.dispatch = dispatch;
|
|
|
|
// Act
|
|
const payload = {
|
|
isWindshieldRepair: false,
|
|
selectedGlassToReplace: [{ glassName: "Rear", glassLocation: "quarter" }],
|
|
selectedWindshieldChipCount: 0,
|
|
};
|
|
actions.saveVehicleDamage(context, payload);
|
|
|
|
// Assert
|
|
expect(dispatch).toHaveBeenNthCalledWith(
|
|
1,
|
|
storeActions.RESET_PARTS_STATE_AND_DEPENDENCIES
|
|
);
|
|
expect(commit).toBeCalledWith(storeMutations.UPDATE_IS_REPAIR, payload.isWindshieldRepair);
|
|
expect(commit).toBeCalledWith(
|
|
storeMutations.UPDATE_NUMBER_OF_CHIPS,
|
|
payload.isWindshieldRepair ? parseInt(payload.selectedWindshieldChipCount) : null
|
|
);
|
|
expect(commit).toBeCalledWith(
|
|
storeMutations.UPDATE_GLASS_TO_REPLACE,
|
|
payload.selectedGlassToReplace
|
|
);
|
|
});
|
|
|
|
describe("runExperimentsForTrigger", () => {
|
|
beforeEach(() => {
|
|
mutations.resetState(state);
|
|
globalMethods.callHttpClient = jest.fn().mockReturnValue({
|
|
data: {
|
|
experiments: [
|
|
{
|
|
mockProperty: "mockValue",
|
|
},
|
|
],
|
|
},
|
|
});
|
|
});
|
|
|
|
test("triggerEvent is SiteEntry => set triggeredSiteEntry to true in store", async () => {
|
|
// Arrange
|
|
const context = state;
|
|
context.commit = jest
|
|
.fn()
|
|
.mockImplementation((storeMutation, value) =>
|
|
mutations[storeMutation](context, value)
|
|
);
|
|
context.getters = {
|
|
...getters,
|
|
applicationUser: getters.applicationUser(context),
|
|
};
|
|
|
|
// Act
|
|
await actions.runExperimentsForTrigger(context, {
|
|
payload: {
|
|
triggerEvent: experimentTriggers.SITE_ENTRY,
|
|
},
|
|
pageNameToLog: "test",
|
|
});
|
|
|
|
// Assert
|
|
expect(context.commit).toHaveBeenNthCalledWith(
|
|
1,
|
|
storeMutations.UPDATE_TRIGGERED_SITE_ENTRY,
|
|
true
|
|
);
|
|
expect(context.getters.applicationUser.triggeredSiteEntry).toBe(true);
|
|
expect(globalMethods.callHttpClient).toHaveBeenCalled();
|
|
expect(context.commit).toHaveBeenNthCalledWith(2, storeMutations.UPDATE_EXPERIMENTS, [
|
|
{
|
|
mockProperty: "mockValue",
|
|
},
|
|
]);
|
|
});
|
|
|
|
test("triggerEvent is not SiteEntry => triggeredSiteEntry is false in store", async () => {
|
|
// Arrange
|
|
const context = state;
|
|
context.commit = jest
|
|
.fn()
|
|
.mockImplementation((storeMutation, value) =>
|
|
mutations[storeMutation](context, value)
|
|
);
|
|
context.getters = {
|
|
...getters,
|
|
applicationUser: getters.applicationUser(context),
|
|
};
|
|
expect(context.commit).toHaveBeenCalledTimes(0);
|
|
|
|
// Act
|
|
await actions.runExperimentsForTrigger(context, {
|
|
payload: {
|
|
triggerEvent: "NotSiteEntry",
|
|
},
|
|
pageNameToLog: "test",
|
|
});
|
|
|
|
// Assert
|
|
expect(context.commit).not.toHaveBeenCalledWith(
|
|
storeMutations.UPDATE_TRIGGERED_SITE_ENTRY,
|
|
expect.any
|
|
);
|
|
expect(context.getters.applicationUser.triggeredSiteEntry).toBe(false);
|
|
|
|
expect(globalMethods.callHttpClient).toHaveBeenCalledTimes(1);
|
|
expect(context.commit).toHaveBeenNthCalledWith(1, storeMutations.UPDATE_EXPERIMENTS, [
|
|
{
|
|
mockProperty: "mockValue",
|
|
},
|
|
]);
|
|
});
|
|
});
|
|
|
|
describe("savePartQuestionAnswers", () => {
|
|
let context;
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
mutations.resetState(state);
|
|
context = state;
|
|
context.commit = jest
|
|
.fn()
|
|
.mockImplementation((storeMutation, value) =>
|
|
mutations[storeMutation](context, value)
|
|
);
|
|
context.getters = {
|
|
...getters,
|
|
damage: getters.damage(context),
|
|
};
|
|
});
|
|
|
|
function testPartQuestionAnswerDependenciesHaveBeenReset(
|
|
context,
|
|
shouldPartQuestionAnswersBeReset
|
|
) {
|
|
if (shouldPartQuestionAnswersBeReset) {
|
|
expect(context.commit).toBeCalledWith(storeMutations.UPDATE_GLASS_PARTS, null);
|
|
expect(context.commit).toBeCalledWith(
|
|
storeMutations.UPDATE_MOLDING_QUESTION_ANSWERS,
|
|
null
|
|
);
|
|
expect(context.commit).toBeCalledWith(
|
|
storeMutations.UPDATE_CAPABILITY_QUESTION_ANSWERS,
|
|
null
|
|
);
|
|
expect(context.commit).toBeCalledWith(storeMutations.UPDATE_PAGE_DATA, {
|
|
page: routeData.VEHICLE_PARTS.name,
|
|
data: null,
|
|
});
|
|
expect(context.commit).toBeCalledWith(storeMutations.UPDATE_PAGE_DATA, {
|
|
page: routeData.MOLDING_QUESTIONS.name,
|
|
data: null,
|
|
});
|
|
expect(context.commit).toBeCalledWith(storeMutations.UPDATE_PAGE_DATA, {
|
|
page: routeData.CAPABILITY_QUESTIONS.name,
|
|
data: null,
|
|
});
|
|
} else {
|
|
expect(context.commit).not.toBeCalledWith(storeMutations.UPDATE_GLASS_PARTS, null);
|
|
expect(context.commit).not.toBeCalledWith(
|
|
storeMutations.UPDATE_MOLDING_QUESTION_ANSWERS,
|
|
null
|
|
);
|
|
expect(context.commit).not.toBeCalledWith(
|
|
storeMutations.UPDATE_CAPABILITY_QUESTION_ANSWERS,
|
|
null
|
|
);
|
|
expect(context.commit).not.toBeCalledWith(storeMutations.UPDATE_PAGE_DATA, {
|
|
page: routeData.VEHICLE_PARTS.name,
|
|
data: null,
|
|
});
|
|
expect(context.commit).not.toBeCalledWith(storeMutations.UPDATE_PAGE_DATA, {
|
|
page: routeData.MOLDING_QUESTIONS.name,
|
|
data: null,
|
|
});
|
|
expect(context.commit).not.toBeCalledWith(storeMutations.UPDATE_PAGE_DATA, {
|
|
page: routeData.CAPABILITY_QUESTIONS.name,
|
|
data: null,
|
|
});
|
|
}
|
|
|
|
expect(context.commit).toBeCalledWith(
|
|
storeMutations.UPDATE_PART_QUESTION_ANSWERS,
|
|
expect.anything()
|
|
);
|
|
}
|
|
|
|
test("there are no previous answers => resets necessary fields", async () => {
|
|
// Arrange
|
|
const previousPartQuestionAnswers = [];
|
|
const currentPartQuestionAnswers = [
|
|
{ result: "I'M A PART!" },
|
|
{ result: "I'M A PART3!" },
|
|
{ result: "I'M A PART2!" },
|
|
];
|
|
|
|
actions.savePartQuestionAnswers(context, previousPartQuestionAnswers);
|
|
jest.clearAllMocks();
|
|
|
|
// Act
|
|
actions.savePartQuestionAnswers(context, currentPartQuestionAnswers);
|
|
|
|
// Assert
|
|
testPartQuestionAnswerDependenciesHaveBeenReset(context, true);
|
|
});
|
|
|
|
test("previous answers does not match current answers => resets necessary fields", () => {
|
|
// Arrange
|
|
const previousPartQuestionAnswers = [
|
|
{ result: "I'M A PART2!" },
|
|
{ result: "I'M A PART4!" },
|
|
{ result: "I'M A PART3!" },
|
|
];
|
|
const currentPartQuestionAnswers = [
|
|
{ result: "I'M A PART!" },
|
|
{ result: "I'M A PART3!" },
|
|
{ result: "I'M A PART2!" },
|
|
];
|
|
|
|
actions.savePartQuestionAnswers(context, previousPartQuestionAnswers);
|
|
jest.clearAllMocks();
|
|
|
|
// Act
|
|
actions.savePartQuestionAnswers(context, currentPartQuestionAnswers);
|
|
|
|
// Assert
|
|
testPartQuestionAnswerDependenciesHaveBeenReset(context, true);
|
|
});
|
|
|
|
test("previous answers match current answers => does not reset fields", () => {
|
|
// Arrange
|
|
const previousPartQuestionAnswers = [
|
|
{ result: "I'M A PART2!" },
|
|
{ result: "I'M A PART!" },
|
|
{ result: "I'M A PART3!" },
|
|
];
|
|
const currentPartQuestionAnswers = [
|
|
{ result: "I'M A PART!" },
|
|
{ result: "I'M A PART3!" },
|
|
{ result: "I'M A PART2!" },
|
|
];
|
|
|
|
actions.savePartQuestionAnswers(context, previousPartQuestionAnswers);
|
|
jest.clearAllMocks();
|
|
|
|
// Act
|
|
actions.savePartQuestionAnswers(context, currentPartQuestionAnswers);
|
|
|
|
// Assert
|
|
testPartQuestionAnswerDependenciesHaveBeenReset(context, false);
|
|
});
|
|
test("previous answers have more questions/answers than current => resets fields", () => {
|
|
// Arrange
|
|
const previousPartQuestionAnswers = [
|
|
{ result: "I'M A PART2!" },
|
|
{ result: "I'M A PART!" },
|
|
{ result: "I'M A PART3!" },
|
|
];
|
|
const currentPartQuestionAnswers = [
|
|
{ result: "I'M A PART!" },
|
|
{ result: "I'M A PART3!" },
|
|
];
|
|
|
|
actions.savePartQuestionAnswers(context, previousPartQuestionAnswers);
|
|
jest.clearAllMocks();
|
|
|
|
// Act
|
|
actions.savePartQuestionAnswers(context, currentPartQuestionAnswers);
|
|
|
|
// Assert
|
|
testPartQuestionAnswerDependenciesHaveBeenReset(context, true);
|
|
});
|
|
|
|
test("current answers have more questions/answers than previous => resets fields", () => {
|
|
// Arrange
|
|
const previousPartQuestionAnswers = [
|
|
{ result: "I'M A PART2!" },
|
|
{ result: "I'M A PART3!" },
|
|
];
|
|
const currentPartQuestionAnswers = [
|
|
{ result: "I'M A PART!" },
|
|
{ result: "I'M A PART3!" },
|
|
{ result: "I'M A PART2!" },
|
|
];
|
|
|
|
actions.savePartQuestionAnswers(context, previousPartQuestionAnswers);
|
|
jest.clearAllMocks();
|
|
|
|
// Act
|
|
actions.savePartQuestionAnswers(context, currentPartQuestionAnswers);
|
|
|
|
// Assert
|
|
testPartQuestionAnswerDependenciesHaveBeenReset(context, true);
|
|
});
|
|
});
|
|
|
|
describe("resetMoldingAndCapabilityQuestionAnswersIfNeeded", () => {
|
|
let context;
|
|
beforeEach(() => {
|
|
mutations.resetState(state);
|
|
context = state;
|
|
context.commit = jest
|
|
.fn()
|
|
.mockImplementation((storeMutation, value) =>
|
|
mutations[storeMutation](context, value)
|
|
);
|
|
context.getters = {
|
|
...getters,
|
|
pageData: getters.pageData(context),
|
|
};
|
|
});
|
|
|
|
function testVehiclePartDependenciesHaveBeenReset(context, shouldAnswersBeReset) {
|
|
if (shouldAnswersBeReset) {
|
|
expect(context.commit).toBeCalledWith(storeMutations.UPDATE_GLASS_PARTS, null);
|
|
expect(context.commit).toBeCalledWith(
|
|
storeMutations.UPDATE_MOLDING_QUESTION_ANSWERS,
|
|
null
|
|
);
|
|
expect(context.commit).toBeCalledWith(
|
|
storeMutations.UPDATE_CAPABILITY_QUESTION_ANSWERS,
|
|
null
|
|
);
|
|
expect(context.commit).toBeCalledWith(storeMutations.UPDATE_PAGE_DATA, {
|
|
page: routeData.MOLDING_QUESTIONS.name,
|
|
data: null,
|
|
});
|
|
expect(context.commit).toBeCalledWith(storeMutations.UPDATE_PAGE_DATA, {
|
|
page: routeData.CAPABILITY_QUESTIONS.name,
|
|
data: null,
|
|
});
|
|
} else {
|
|
expect(context.commit).not.toBeCalledWith(storeMutations.UPDATE_GLASS_PARTS, null);
|
|
expect(context.commit).not.toBeCalledWith(
|
|
storeMutations.UPDATE_MOLDING_QUESTION_ANSWERS,
|
|
null
|
|
);
|
|
expect(context.commit).not.toBeCalledWith(
|
|
storeMutations.UPDATE_CAPABILITY_QUESTION_ANSWERS,
|
|
null
|
|
);
|
|
expect(context.commit).not.toBeCalledWith(storeMutations.UPDATE_PAGE_DATA, {
|
|
page: routeData.MOLDING_QUESTIONS.name,
|
|
data: null,
|
|
});
|
|
expect(context.commit).not.toBeCalledWith(storeMutations.UPDATE_PAGE_DATA, {
|
|
page: routeData.CAPABILITY_QUESTIONS.name,
|
|
data: null,
|
|
});
|
|
}
|
|
}
|
|
|
|
test("there are no saved parts from molding or capability question pages => resets necessary fields", () => {
|
|
// Arrange
|
|
const previouslySelectedParts = {};
|
|
|
|
const currentlySelectedParts = [
|
|
{
|
|
glassLocation: "Windshield",
|
|
glassName: "Single",
|
|
parts: [
|
|
{ partNumber: "PART3" },
|
|
{ partNumber: "PART1" },
|
|
{ partNumber: "PART2" },
|
|
],
|
|
},
|
|
];
|
|
|
|
mutations.updatePageData(context, {
|
|
page: routeData.MOLDING_QUESTIONS.name,
|
|
data: previouslySelectedParts,
|
|
});
|
|
|
|
mutations.updatePageData(context, {
|
|
page: routeData.CAPABILITY_QUESTIONS.name,
|
|
data: previouslySelectedParts,
|
|
});
|
|
|
|
// Act
|
|
actions.resetMoldingAndCapabilityQuestionAnswersIfNeeded(
|
|
context,
|
|
currentlySelectedParts
|
|
);
|
|
|
|
// Assert
|
|
testVehiclePartDependenciesHaveBeenReset(context, true);
|
|
});
|
|
|
|
describe("previously saved parts from molding-questions match selected parts => does not reset fields", () => {
|
|
test("single glass location", () => {
|
|
// Arrange
|
|
const previouslySelectedParts = {
|
|
partsOrQuestions: [
|
|
{
|
|
glassLocation: "Windshield",
|
|
glassName: "Single",
|
|
parts: [
|
|
{ partNumber: "PART1" },
|
|
{ partNumber: "PART2" },
|
|
{ partNumber: "PART3" },
|
|
],
|
|
},
|
|
],
|
|
};
|
|
|
|
const currentlySelectedParts = [
|
|
{
|
|
glassLocation: "Windshield",
|
|
glassName: "Single",
|
|
parts: [
|
|
{ partNumber: "PART3" },
|
|
{ partNumber: "PART1" },
|
|
{ partNumber: "PART2" },
|
|
],
|
|
},
|
|
];
|
|
|
|
mutations.updatePageData(context, {
|
|
page: routeData.MOLDING_QUESTIONS.name,
|
|
data: previouslySelectedParts,
|
|
});
|
|
|
|
// Act
|
|
actions.resetMoldingAndCapabilityQuestionAnswersIfNeeded(
|
|
context,
|
|
currentlySelectedParts
|
|
);
|
|
|
|
// Assert
|
|
testVehiclePartDependenciesHaveBeenReset(context, false);
|
|
});
|
|
|
|
test("multiple glass locations", () => {
|
|
// Arrange
|
|
const previouslySelectedParts = {
|
|
partsOrQuestions: [
|
|
{
|
|
glassLocation: "Windshield",
|
|
glassName: "Single",
|
|
parts: [
|
|
{ partNumber: "PART1" },
|
|
{ partNumber: "PART2" },
|
|
{ partNumber: "PART3" },
|
|
],
|
|
},
|
|
{
|
|
glassLocation: "Driver",
|
|
glassName: "Front",
|
|
parts: [{ partNumber: "PART5" }, { partNumber: "PART4" }],
|
|
},
|
|
],
|
|
};
|
|
|
|
const currentlySelectedParts = [
|
|
{
|
|
glassLocation: "Driver",
|
|
glassName: "Front",
|
|
parts: [{ partNumber: "PART4" }, { partNumber: "PART5" }],
|
|
},
|
|
{
|
|
glassLocation: "Windshield",
|
|
glassName: "Single",
|
|
parts: [
|
|
{ partNumber: "PART3" },
|
|
{ partNumber: "PART1" },
|
|
{ partNumber: "PART2" },
|
|
],
|
|
},
|
|
];
|
|
|
|
mutations.updatePageData(context, {
|
|
page: routeData.MOLDING_QUESTIONS.name,
|
|
data: previouslySelectedParts,
|
|
});
|
|
|
|
// Act
|
|
actions.resetMoldingAndCapabilityQuestionAnswersIfNeeded(
|
|
context,
|
|
currentlySelectedParts
|
|
);
|
|
|
|
// Assert
|
|
testVehiclePartDependenciesHaveBeenReset(context, false);
|
|
});
|
|
});
|
|
|
|
describe("previously saved parts from capability-questions match selected parts and there are none from molding-questions => does not reset fields", () => {
|
|
test("Single glass location", () => {
|
|
// Arrange
|
|
const previouslySelectedParts = {
|
|
partsOrQuestions: [
|
|
{
|
|
glassLocation: "Windshield",
|
|
glassName: "Single",
|
|
parts: [
|
|
{ partNumber: "PART1" },
|
|
{ partNumber: "PART2" },
|
|
{ partNumber: "PART3" },
|
|
],
|
|
},
|
|
],
|
|
};
|
|
|
|
const currentlySelectedParts = [
|
|
{
|
|
glassLocation: "Windshield",
|
|
glassName: "Single",
|
|
parts: [
|
|
{ partNumber: "PART3" },
|
|
{ partNumber: "PART1" },
|
|
{ partNumber: "PART2" },
|
|
],
|
|
},
|
|
];
|
|
|
|
mutations.updatePageData(context, {
|
|
page: routeData.CAPABILITY_QUESTIONS.name,
|
|
data: previouslySelectedParts,
|
|
});
|
|
|
|
// Act
|
|
actions.resetMoldingAndCapabilityQuestionAnswersIfNeeded(
|
|
context,
|
|
currentlySelectedParts
|
|
);
|
|
|
|
// Assert
|
|
testVehiclePartDependenciesHaveBeenReset(context, false);
|
|
});
|
|
|
|
test("multiple glass locations", () => {
|
|
// Arrange
|
|
const previouslySelectedParts = {
|
|
partsOrQuestions: [
|
|
{
|
|
glassLocation: "Windshield",
|
|
glassName: "Single",
|
|
parts: [
|
|
{ partNumber: "PART1" },
|
|
{ partNumber: "PART2" },
|
|
{ partNumber: "PART3" },
|
|
],
|
|
},
|
|
{
|
|
glassLocation: "Driver",
|
|
glassName: "Front",
|
|
parts: [{ partNumber: "PART5" }, { partNumber: "PART4" }],
|
|
},
|
|
],
|
|
};
|
|
|
|
const currentlySelectedParts = [
|
|
{
|
|
glassLocation: "Driver",
|
|
glassName: "Front",
|
|
parts: [{ partNumber: "PART4" }, { partNumber: "PART5" }],
|
|
},
|
|
{
|
|
glassLocation: "Windshield",
|
|
glassName: "Single",
|
|
parts: [
|
|
{ partNumber: "PART3" },
|
|
{ partNumber: "PART1" },
|
|
{ partNumber: "PART2" },
|
|
],
|
|
},
|
|
];
|
|
|
|
mutations.updatePageData(context, {
|
|
page: routeData.CAPABILITY_QUESTIONS.name,
|
|
data: previouslySelectedParts,
|
|
});
|
|
|
|
// Act
|
|
actions.resetMoldingAndCapabilityQuestionAnswersIfNeeded(
|
|
context,
|
|
currentlySelectedParts
|
|
);
|
|
|
|
// Assert
|
|
testVehiclePartDependenciesHaveBeenReset(context, false);
|
|
});
|
|
});
|
|
|
|
describe("previously saved parts from molding-questions do not match selected parts => resets necessary fields", () => {
|
|
test("single glass location", () => {
|
|
// Arrange
|
|
const previouslySelectedParts = {
|
|
partsOrQuestions: [
|
|
{
|
|
glassLocation: "Windshield",
|
|
glassName: "Single",
|
|
parts: [
|
|
{ partNumber: "PART1" },
|
|
{ partNumber: "PART6" },
|
|
{ partNumber: "PART3" },
|
|
],
|
|
},
|
|
],
|
|
};
|
|
|
|
const currentlySelectedParts = [
|
|
{
|
|
glassLocation: "Windshield",
|
|
glassName: "Single",
|
|
parts: [
|
|
{ partNumber: "PART3" },
|
|
{ partNumber: "PART1" },
|
|
{ partNumber: "PART2" },
|
|
],
|
|
},
|
|
];
|
|
|
|
mutations.updatePageData(context, {
|
|
page: routeData.MOLDING_QUESTIONS.name,
|
|
data: previouslySelectedParts,
|
|
});
|
|
|
|
// Act
|
|
actions.resetMoldingAndCapabilityQuestionAnswersIfNeeded(
|
|
context,
|
|
currentlySelectedParts
|
|
);
|
|
|
|
// Assert
|
|
testVehiclePartDependenciesHaveBeenReset(context, true);
|
|
});
|
|
|
|
test("multiple glass locations", () => {
|
|
// Arrange
|
|
const previouslySelectedParts = {
|
|
partsOrQuestions: [
|
|
{
|
|
glassLocation: "Windshield",
|
|
glassName: "Single",
|
|
parts: [
|
|
{ partNumber: "PART1" },
|
|
{ partNumber: "PART6" },
|
|
{ partNumber: "PART3" },
|
|
],
|
|
},
|
|
{
|
|
glassLocation: "Driver",
|
|
glassName: "Front",
|
|
parts: [{ partNumber: "PART5" }, { partNumber: "PART4" }],
|
|
},
|
|
],
|
|
};
|
|
|
|
const currentlySelectedParts = [
|
|
{
|
|
glassLocation: "Driver",
|
|
glassName: "Front",
|
|
parts: [{ partNumber: "PART4" }, { partNumber: "PART5" }],
|
|
},
|
|
{
|
|
glassLocation: "Windshield",
|
|
glassName: "Single",
|
|
parts: [
|
|
{ partNumber: "PART3" },
|
|
{ partNumber: "PART1" },
|
|
{ partNumber: "PART2" },
|
|
],
|
|
},
|
|
];
|
|
|
|
mutations.updatePageData(context, {
|
|
page: routeData.MOLDING_QUESTIONS.name,
|
|
data: previouslySelectedParts,
|
|
});
|
|
|
|
// Act
|
|
actions.resetMoldingAndCapabilityQuestionAnswersIfNeeded(
|
|
context,
|
|
currentlySelectedParts
|
|
);
|
|
|
|
// Assert
|
|
testVehiclePartDependenciesHaveBeenReset(context, true);
|
|
});
|
|
});
|
|
|
|
describe("previously saved parts from capability-questions do not match selected parts => resets necessary fields", () => {
|
|
test("single glass location", () => {
|
|
// Arrange
|
|
const previouslySelectedParts = {
|
|
partsOrQuestions: [
|
|
{
|
|
glassLocation: "Windshield",
|
|
glassName: "Single",
|
|
parts: [
|
|
{ partNumber: "PART1" },
|
|
{ partNumber: "PART6" },
|
|
{ partNumber: "PART3" },
|
|
],
|
|
},
|
|
],
|
|
};
|
|
|
|
const currentlySelectedParts = [
|
|
{
|
|
glassLocation: "Windshield",
|
|
glassName: "Single",
|
|
parts: [
|
|
{ partNumber: "PART3" },
|
|
{ partNumber: "PART1" },
|
|
{ partNumber: "PART2" },
|
|
],
|
|
},
|
|
];
|
|
|
|
mutations.updatePageData(context, {
|
|
page: routeData.MOLDING_QUESTIONS.name,
|
|
data: previouslySelectedParts,
|
|
});
|
|
|
|
// Act
|
|
actions.resetMoldingAndCapabilityQuestionAnswersIfNeeded(
|
|
context,
|
|
currentlySelectedParts
|
|
);
|
|
|
|
// Assert
|
|
testVehiclePartDependenciesHaveBeenReset(context, true);
|
|
});
|
|
|
|
test("multiple glass locations", () => {
|
|
// Arrange
|
|
const previouslySelectedParts = {
|
|
partsOrQuestions: [
|
|
{
|
|
glassLocation: "Windshield",
|
|
glassName: "Single",
|
|
parts: [
|
|
{ partNumber: "PART1" },
|
|
{ partNumber: "PART6" },
|
|
{ partNumber: "PART3" },
|
|
],
|
|
},
|
|
{
|
|
glassLocation: "Driver",
|
|
glassName: "Front",
|
|
parts: [{ partNumber: "PART5" }, { partNumber: "PART4" }],
|
|
},
|
|
],
|
|
};
|
|
|
|
const currentlySelectedParts = [
|
|
{
|
|
glassLocation: "Driver",
|
|
glassName: "Front",
|
|
parts: [{ partNumber: "PART4" }, { partNumber: "PART5" }],
|
|
},
|
|
{
|
|
glassLocation: "Windshield",
|
|
glassName: "Single",
|
|
parts: [
|
|
{ partNumber: "PART3" },
|
|
{ partNumber: "PART1" },
|
|
{ partNumber: "PART2" },
|
|
],
|
|
},
|
|
];
|
|
|
|
mutations.updatePageData(context, {
|
|
page: routeData.CAPABILITY_QUESTIONS.name,
|
|
data: previouslySelectedParts,
|
|
});
|
|
|
|
// Act
|
|
actions.resetMoldingAndCapabilityQuestionAnswersIfNeeded(
|
|
context,
|
|
currentlySelectedParts
|
|
);
|
|
|
|
// Assert
|
|
testVehiclePartDependenciesHaveBeenReset(context, true);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("saveMoldingQuestionAnswers", () => {
|
|
let context;
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
mutations.resetState(state);
|
|
context = state;
|
|
context.commit = jest
|
|
.fn()
|
|
.mockImplementation((storeMutation, value) =>
|
|
mutations[storeMutation](context, value)
|
|
);
|
|
context.getters = {
|
|
...getters,
|
|
damage: getters.damage(context),
|
|
};
|
|
});
|
|
|
|
function testMoldingQuestionAnswerDependenciesHaveBeenReset(context, shouldAnswersBeReset) {
|
|
if (shouldAnswersBeReset) {
|
|
expect(context.commit).toBeCalledWith(storeMutations.UPDATE_GLASS_PARTS, null);
|
|
expect(context.commit).toBeCalledWith(
|
|
storeMutations.UPDATE_CAPABILITY_QUESTION_ANSWERS,
|
|
null
|
|
);
|
|
expect(context.commit).toBeCalledWith(storeMutations.UPDATE_PAGE_DATA, {
|
|
page: routeData.CAPABILITY_QUESTIONS.name,
|
|
data: null,
|
|
});
|
|
} else {
|
|
expect(context.commit).not.toBeCalledWith(storeMutations.UPDATE_GLASS_PARTS, null);
|
|
expect(context.commit).not.toBeCalledWith(
|
|
storeMutations.UPDATE_CAPABILITY_QUESTION_ANSWERS,
|
|
null
|
|
);
|
|
expect(context.commit).not.toBeCalledWith(storeMutations.UPDATE_PAGE_DATA, {
|
|
page: routeData.CAPABILITY_QUESTIONS.name,
|
|
data: null,
|
|
});
|
|
}
|
|
}
|
|
|
|
test("there are no previous answers => resets necessary fields", () => {
|
|
// Arrange
|
|
const previousMoldingQuestionAnswers = [];
|
|
const currentMoldingQuestionAnswers = [
|
|
{ partNum: "I'M A PART!" },
|
|
{ partNum: "I'M A PART3!" },
|
|
{ partNum: "I'M A PART2!" },
|
|
];
|
|
|
|
actions.saveMoldingQuestionAnswers(context, previousMoldingQuestionAnswers);
|
|
jest.clearAllMocks();
|
|
|
|
// Act
|
|
actions.saveMoldingQuestionAnswers(context, currentMoldingQuestionAnswers);
|
|
|
|
// Assert
|
|
testMoldingQuestionAnswerDependenciesHaveBeenReset(context, true);
|
|
});
|
|
|
|
test("previous answers match current answers => does not reset fields", () => {
|
|
// Arrange
|
|
const previousMoldingQuestionAnswers = [
|
|
{ partNum: "I'M A PART2!" },
|
|
{ partNum: "I'M A PART3!" },
|
|
{ partNum: "I'M A PART!" },
|
|
];
|
|
const currentMoldingQuestionAnswers = [
|
|
{ partNum: "I'M A PART!" },
|
|
{ partNum: "I'M A PART3!" },
|
|
{ partNum: "I'M A PART2!" },
|
|
];
|
|
|
|
actions.saveMoldingQuestionAnswers(context, previousMoldingQuestionAnswers);
|
|
jest.clearAllMocks();
|
|
|
|
// Act
|
|
actions.saveMoldingQuestionAnswers(context, currentMoldingQuestionAnswers);
|
|
|
|
// Assert
|
|
testMoldingQuestionAnswerDependenciesHaveBeenReset(context, false);
|
|
});
|
|
|
|
test("previous answers do not match current answers => resets necessary fields", () => {
|
|
// Arrange
|
|
const previousMoldingQuestionAnswers = [
|
|
{ partNum: "I'M A PART2!" },
|
|
{ partNum: "I'M A PART4!" },
|
|
{ partNum: "I'M A PART!" },
|
|
];
|
|
const currentMoldingQuestionAnswers = [
|
|
{ partNum: "I'M A PART!" },
|
|
{ partNum: "I'M A PART3!" },
|
|
{ partNum: "I'M A PART2!" },
|
|
];
|
|
|
|
actions.saveMoldingQuestionAnswers(context, previousMoldingQuestionAnswers);
|
|
jest.clearAllMocks();
|
|
|
|
// Act
|
|
actions.saveMoldingQuestionAnswers(context, currentMoldingQuestionAnswers);
|
|
|
|
// Assert
|
|
testMoldingQuestionAnswerDependenciesHaveBeenReset(context, true);
|
|
});
|
|
|
|
test("previous answers have more questions/answers than current => resets fields", () => {
|
|
// Arrange
|
|
const previousMoldingQuestionAnswers = [
|
|
{ partNum: "I'M A PART2!" },
|
|
{ partNum: "I'M A PART4!" },
|
|
{ partNum: "I'M A PART!" },
|
|
];
|
|
const currentMoldingQuestionAnswers = [{ partNum: "I'M A PART!" }];
|
|
|
|
actions.saveMoldingQuestionAnswers(context, previousMoldingQuestionAnswers);
|
|
jest.clearAllMocks();
|
|
|
|
// Act
|
|
actions.saveMoldingQuestionAnswers(context, currentMoldingQuestionAnswers);
|
|
|
|
// Assert
|
|
testMoldingQuestionAnswerDependenciesHaveBeenReset(context, true);
|
|
});
|
|
|
|
test("current answers have more questions/answers than previous => resets fields", () => {
|
|
// Arrange
|
|
const previousMoldingQuestionAnswers = [
|
|
{ partNum: "I'M A PART2!" },
|
|
{ partNum: "I'M A PART!" },
|
|
];
|
|
const currentMoldingQuestionAnswers = [
|
|
{ partNum: "I'M A PART!" },
|
|
{ partNum: "I'M A PART3!" },
|
|
{ partNum: "I'M A PART2!" },
|
|
];
|
|
|
|
actions.saveMoldingQuestionAnswers(context, previousMoldingQuestionAnswers);
|
|
jest.clearAllMocks();
|
|
|
|
// Act
|
|
actions.saveMoldingQuestionAnswers(context, currentMoldingQuestionAnswers);
|
|
|
|
// Assert
|
|
testMoldingQuestionAnswerDependenciesHaveBeenReset(context, true);
|
|
});
|
|
});
|
|
|
|
describe("saveCapabilityQuestionAnswers", () => {
|
|
let context;
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
mutations.resetState(state);
|
|
context = state;
|
|
context.commit = jest
|
|
.fn()
|
|
.mockImplementation((storeMutation, value) =>
|
|
mutations[storeMutation](context, value)
|
|
);
|
|
context.getters = {
|
|
...getters,
|
|
damage: getters.damage(context),
|
|
};
|
|
});
|
|
|
|
function testCapabilityQuestionAnswerDependenciesHaveBeenReset(
|
|
context,
|
|
shouldAnswersBeReset
|
|
) {
|
|
if (shouldAnswersBeReset) {
|
|
expect(context.commit).toBeCalledWith(storeMutations.UPDATE_GLASS_PARTS, null);
|
|
} else {
|
|
expect(context.commit).not.toBeCalledWith(storeMutations.UPDATE_GLASS_PARTS, null);
|
|
}
|
|
}
|
|
|
|
test("there are no previous answers => resets necessary fields", () => {
|
|
// Arrange
|
|
const previousCapabilityQuestionAnswers = [];
|
|
const currentCapabilityQuestionAnswers = [
|
|
{ result: "DYNAMIC" },
|
|
{ result: "STATIC" },
|
|
{ result: "UNKNOWN" },
|
|
];
|
|
|
|
actions.saveCapabilityQuestionAnswers(context, previousCapabilityQuestionAnswers);
|
|
jest.clearAllMocks();
|
|
|
|
// Act
|
|
actions.saveCapabilityQuestionAnswers(context, currentCapabilityQuestionAnswers);
|
|
|
|
// Assert
|
|
testCapabilityQuestionAnswerDependenciesHaveBeenReset(context, true);
|
|
});
|
|
|
|
test("previous answers match current answers => does not reset fields", () => {
|
|
// Arrange
|
|
const previousCapabilityQuestionAnswers = [
|
|
{ result: "STATIC" },
|
|
{ result: "DYNAMIC" },
|
|
{ result: "UNKNOWN" },
|
|
];
|
|
const currentCapabilityQuestionAnswers = [
|
|
{ result: "DYNAMIC" },
|
|
{ result: "STATIC" },
|
|
{ result: "UNKNOWN" },
|
|
];
|
|
|
|
actions.saveCapabilityQuestionAnswers(context, previousCapabilityQuestionAnswers);
|
|
jest.clearAllMocks();
|
|
|
|
// Act
|
|
actions.saveCapabilityQuestionAnswers(context, currentCapabilityQuestionAnswers);
|
|
|
|
// Assert
|
|
testCapabilityQuestionAnswerDependenciesHaveBeenReset(context, false);
|
|
});
|
|
|
|
test("previous answers do not match current answers => resets necessary fields", () => {
|
|
// Arrange
|
|
const previousCapabilityQuestionAnswers = [
|
|
{ result: "DYNAMIC" },
|
|
{ result: "DYNAMIC" },
|
|
{ result: "STATIC" },
|
|
];
|
|
const currentCapabilityQuestionAnswers = [
|
|
{ result: "STATIC" },
|
|
{ result: "STATIC" },
|
|
{ result: "DYNAMIC" },
|
|
];
|
|
|
|
actions.saveCapabilityQuestionAnswers(context, previousCapabilityQuestionAnswers);
|
|
jest.clearAllMocks();
|
|
|
|
// Act
|
|
actions.saveCapabilityQuestionAnswers(context, currentCapabilityQuestionAnswers);
|
|
|
|
// Assert
|
|
testCapabilityQuestionAnswerDependenciesHaveBeenReset(context, true);
|
|
});
|
|
|
|
test("previous answers have more questions/answers than current => resets fields", () => {
|
|
// Arrange
|
|
const previousCapabilityQuestionAnswers = [
|
|
{ result: "STATIC" },
|
|
{ result: "DYNAMIC" },
|
|
{ result: "UNKNOWN" },
|
|
];
|
|
const currentCapabilityQuestionAnswers = [{ result: "DYNAMIC" }];
|
|
|
|
actions.saveCapabilityQuestionAnswers(context, previousCapabilityQuestionAnswers);
|
|
jest.clearAllMocks();
|
|
|
|
// Act
|
|
actions.saveCapabilityQuestionAnswers(context, currentCapabilityQuestionAnswers);
|
|
|
|
// Assert
|
|
testCapabilityQuestionAnswerDependenciesHaveBeenReset(context, true);
|
|
});
|
|
|
|
test("current answers have more questions/answers than previous => resets fields", () => {
|
|
// Arrange
|
|
const previousCapabilityQuestionAnswers = [{ result: "STATIC" }, { result: "UNKNOWN" }];
|
|
const currentCapabilityQuestionAnswers = [
|
|
{ result: "DYNAMIC" },
|
|
{ result: "STATIC" },
|
|
{ result: "UNKNOWN" },
|
|
];
|
|
actions.saveCapabilityQuestionAnswers(context, previousCapabilityQuestionAnswers);
|
|
jest.clearAllMocks();
|
|
|
|
// Act
|
|
actions.saveCapabilityQuestionAnswers(context, currentCapabilityQuestionAnswers);
|
|
|
|
// Assert
|
|
testCapabilityQuestionAnswerDependenciesHaveBeenReset(context, true);
|
|
});
|
|
});
|
|
describe("saveActiveAndOrInactivePromos", () => {
|
|
it("should save empty arrays to promos and inactivePromos when provided with empty or null parameters", () => {
|
|
// Arrange
|
|
const context = state;
|
|
context.commit = jest.fn();
|
|
|
|
const emptyActivePromos = [];
|
|
const emptyInactivePromos = [];
|
|
const nullActivePromos = [];
|
|
const nullInactivePromos = [];
|
|
|
|
// Act
|
|
actions.saveActiveAndOrInactivePromos(context, {
|
|
activePromos: emptyActivePromos,
|
|
inactivePromos: emptyInactivePromos,
|
|
});
|
|
actions.saveActiveAndOrInactivePromos(context, {
|
|
activePromos: nullActivePromos,
|
|
inactivePromos: nullInactivePromos,
|
|
});
|
|
// Assert
|
|
expect(context.commit).toHaveBeenNthCalledWith(1, storeMutations.UPDATE_PROMOS, []);
|
|
expect(context.commit).toHaveBeenNthCalledWith(
|
|
2,
|
|
storeMutations.UPDATE_INACTIVE_PROMOS,
|
|
[]
|
|
);
|
|
expect(context.commit).toHaveBeenNthCalledWith(3, storeMutations.UPDATE_PROMOS, []);
|
|
expect(context.commit).toHaveBeenNthCalledWith(
|
|
4,
|
|
storeMutations.UPDATE_INACTIVE_PROMOS,
|
|
[]
|
|
);
|
|
});
|
|
it("should save both active and inactivePromos when method is supplied with both active and inactive", () => {
|
|
// Arrange
|
|
const context = state;
|
|
context.commit = jest.fn();
|
|
|
|
const activePromos = [{ promoCode: "activePromo" }];
|
|
const inactivePromos = ["inactivePromo"];
|
|
|
|
// Act
|
|
actions.saveActiveAndOrInactivePromos(context, {
|
|
activePromos: activePromos,
|
|
inactivePromos: inactivePromos,
|
|
});
|
|
|
|
// Assert
|
|
expect(context.commit).toBeCalledWith(storeMutations.UPDATE_PROMOS, activePromos);
|
|
expect(context.commit).toBeCalledWith(
|
|
storeMutations.UPDATE_INACTIVE_PROMOS,
|
|
inactivePromos
|
|
);
|
|
});
|
|
it("should remove any inactivePromos that are already active when supplied with both active and inactive", () => {
|
|
// Arrange
|
|
const context = state;
|
|
context.commit = jest.fn();
|
|
|
|
const activePromos = [{ promoCode: "duplicatePromo" }];
|
|
const inactivePromos = ["duplicatePromo", "uniquePromo"];
|
|
|
|
const expectedInactivePromos = ["uniquePromo"];
|
|
|
|
// Act
|
|
actions.saveActiveAndOrInactivePromos(context, {
|
|
activePromos: activePromos,
|
|
inactivePromos: inactivePromos,
|
|
});
|
|
|
|
// Assert
|
|
expect(context.commit).toBeCalledWith(
|
|
storeMutations.UPDATE_INACTIVE_PROMOS,
|
|
expectedInactivePromos
|
|
);
|
|
});
|
|
it("should save active promos from store and inactive promos from method call when only inactivePromos is provided", () => {
|
|
// Arrange
|
|
const context = state;
|
|
context.commit = jest.fn();
|
|
|
|
const activePromos = [{ promoCode: "storedPromo" }];
|
|
const inactivePromos = ["inactivePromo"];
|
|
context["getters"] = { lineItems: { promos: activePromos } };
|
|
|
|
// Act
|
|
actions.saveActiveAndOrInactivePromos(context, { inactivePromos: inactivePromos });
|
|
|
|
// Assert
|
|
expect(context.commit).toBeCalledWith(storeMutations.UPDATE_PROMOS, activePromos);
|
|
expect(context.commit).toBeCalledWith(
|
|
storeMutations.UPDATE_INACTIVE_PROMOS,
|
|
inactivePromos
|
|
);
|
|
});
|
|
it("should save active promos but remove duplicates from store and inactive promos from method call when only inactivePromos is provided", () => {
|
|
// If only inactivePromos is supplied, it will remove duplicates from active promos in the store
|
|
// Arrange
|
|
const context = state;
|
|
context.commit = jest.fn();
|
|
|
|
const activePromos = [{ promoCode: "storedPromo" }, { promoCode: "duplicatePromo" }];
|
|
const inactivePromos = ["duplicatePromo"];
|
|
context["getters"] = { lineItems: { promos: activePromos } };
|
|
|
|
const expectedSavedActivePromos = [{ promoCode: "storedPromo" }];
|
|
|
|
// Act
|
|
actions.saveActiveAndOrInactivePromos(context, { inactivePromos: inactivePromos });
|
|
|
|
// Assert
|
|
expect(context.commit).toBeCalledWith(
|
|
storeMutations.UPDATE_PROMOS,
|
|
expectedSavedActivePromos
|
|
);
|
|
expect(context.commit).toBeCalledWith(
|
|
storeMutations.UPDATE_INACTIVE_PROMOS,
|
|
inactivePromos
|
|
);
|
|
});
|
|
it("should save inactivePromos from the store and provided activePromos when only activePromos is provided", () => {
|
|
// Arrange
|
|
const context = state;
|
|
context.commit = jest.fn();
|
|
|
|
const activePromos = [{ promoCode: "activePromo" }];
|
|
const inactivePromos = ["inactivePromo"];
|
|
context["getters"] = { payment: { inactivePromos: inactivePromos } };
|
|
|
|
// Act
|
|
actions.saveActiveAndOrInactivePromos(context, { activePromos: activePromos });
|
|
|
|
// Assert
|
|
expect(context.commit).toBeCalledWith(storeMutations.UPDATE_PROMOS, activePromos);
|
|
expect(context.commit).toBeCalledWith(
|
|
storeMutations.UPDATE_INACTIVE_PROMOS,
|
|
inactivePromos
|
|
);
|
|
});
|
|
it("should save inactivePromos without duplicates from activePromos from the store and provided activePromos when only activePromos is provided", () => {
|
|
// Arrange
|
|
const context = state;
|
|
context.commit = jest.fn();
|
|
|
|
const activePromos = [{ promoCode: "activePromo" }, { promoCode: "duplicatePromo" }];
|
|
const inactivePromos = ["inactivePromo", "duplicatePromo"];
|
|
context["getters"] = { payment: { inactivePromos: inactivePromos } };
|
|
|
|
const expectedInactivePromos = ["inactivePromo"];
|
|
|
|
// Act
|
|
actions.saveActiveAndOrInactivePromos(context, { activePromos: activePromos });
|
|
|
|
// Assert
|
|
expect(context.commit).toBeCalledWith(storeMutations.UPDATE_PROMOS, activePromos);
|
|
expect(context.commit).toBeCalledWith(
|
|
storeMutations.UPDATE_INACTIVE_PROMOS,
|
|
expectedInactivePromos
|
|
);
|
|
});
|
|
});
|
|
describe("validateOrderPromoAndSaveServerData", () => {
|
|
it("should add GUIDs if not there to provided lineItemsToUse.vaps before sending the http call", async () => {
|
|
// Arrange
|
|
const context = state;
|
|
const promoCode = "testPromo";
|
|
const lineItemsToUse = {
|
|
vaps: [{ partNumber: 1 }],
|
|
promos: [{ promoCode: "1wiper0" }],
|
|
};
|
|
const addableVaps = [{ partNumber: "addableVap" }];
|
|
|
|
context["getters"] = {
|
|
order: {
|
|
serviceLocation: {
|
|
appointmentType: "test",
|
|
state: "test",
|
|
zipCodeCtu: "test",
|
|
},
|
|
vehicle: {
|
|
carId: "test",
|
|
year: "test",
|
|
},
|
|
referralCorrelationId: "test",
|
|
eon: "test",
|
|
damage: {
|
|
isRepair: true,
|
|
glassToReplace: null,
|
|
},
|
|
payment: {
|
|
parentAccountNumber: "test",
|
|
},
|
|
referralSequenceNumber: "test",
|
|
lineItems: {
|
|
serverData: "test",
|
|
},
|
|
},
|
|
};
|
|
|
|
globalMethods.callHttpClient = jest.fn().mockResolvedValue({
|
|
data: {},
|
|
});
|
|
|
|
crypto.randomUUID = jest.fn(() => "GUID");
|
|
|
|
// Act
|
|
actions.validateOrderPromoAndSaveServerData(context, {
|
|
payload: {
|
|
promoCode: promoCode,
|
|
lineItemsToUse: lineItemsToUse,
|
|
addableVaps: addableVaps,
|
|
},
|
|
pageNameToLog: "test",
|
|
});
|
|
|
|
const firstCallArgs = globalMethods.callHttpClient.mock.calls[0];
|
|
|
|
// Assert
|
|
const vapsItem = firstCallArgs[0].payload.order.lineItemsOnOrder.filter(
|
|
(item) => item.partNumber == 1
|
|
)[0];
|
|
expect(vapsItem.id).toEqual("GUID");
|
|
});
|
|
it("should not duplicate ids during syncing if there are two identical vaps items", async () => {
|
|
// Arrange
|
|
const context = state;
|
|
const promoCode = "testPromo";
|
|
// AddableVaps will sync its ids to vaps already on the order
|
|
const lineItemsToUse = {
|
|
vaps: [
|
|
{ partNumber: "SBB22", id: "GUID1" },
|
|
{ partNumber: "SBB22", id: "GUID2" },
|
|
],
|
|
promos: [{ promoCode: "1wiper0" }],
|
|
};
|
|
const addableVaps = [{ partNumber: "SBB22" }, { partNumber: "SBB22" }];
|
|
|
|
context["getters"] = {
|
|
order: {
|
|
serviceLocation: {
|
|
appointmentType: "test",
|
|
state: "test",
|
|
zipCodeCtu: "test",
|
|
},
|
|
vehicle: {
|
|
carId: "test",
|
|
year: "test",
|
|
},
|
|
referralCorrelationId: "test",
|
|
eon: "test",
|
|
damage: {
|
|
isRepair: true,
|
|
glassToReplace: null,
|
|
},
|
|
payment: {
|
|
parentAccountNumber: "test",
|
|
},
|
|
referralSequenceNumber: "test",
|
|
lineItems: {
|
|
serverData: "test",
|
|
},
|
|
},
|
|
};
|
|
|
|
globalMethods.callHttpClient = jest.fn().mockResolvedValue({
|
|
data: {},
|
|
});
|
|
|
|
crypto.randomUUID = jest.fn(() => "GUID");
|
|
|
|
// Act
|
|
actions.validateOrderPromoAndSaveServerData(context, {
|
|
payload: {
|
|
promoCode: promoCode,
|
|
lineItemsToUse: lineItemsToUse,
|
|
addableVaps: addableVaps,
|
|
},
|
|
pageNameToLog: "test",
|
|
});
|
|
|
|
const firstCallArgs = globalMethods.callHttpClient.mock.calls[0];
|
|
|
|
// Assert
|
|
const vapsItems = firstCallArgs[0].payload.addableVaps.filter(
|
|
(item) => item.partNumber == "SBB22"
|
|
);
|
|
expect(vapsItems[1].id).toEqual("GUID1");
|
|
expect(vapsItems[0].id).toEqual("GUID2");
|
|
});
|
|
it("should add GUIDs if not there to provided addableVaps before sending the http call", async () => {
|
|
// Arrange
|
|
const context = state;
|
|
const promoCode = "testPromo";
|
|
const lineItemsToUse = {
|
|
vaps: [{ partNumber: 1 }],
|
|
promos: [{ promoCode: "1wiper0" }],
|
|
};
|
|
const addableVaps = [{ partNumber: "addableVap" }];
|
|
|
|
context["getters"] = {
|
|
order: {
|
|
serviceLocation: {
|
|
appointmentType: "test",
|
|
state: "test",
|
|
zipCodeCtu: "test",
|
|
},
|
|
vehicle: {
|
|
carId: "test",
|
|
year: "test",
|
|
},
|
|
referralCorrelationId: "test",
|
|
eon: "test",
|
|
damage: {
|
|
isRepair: true,
|
|
glassToReplace: null,
|
|
},
|
|
payment: {
|
|
parentAccountNumber: "test",
|
|
},
|
|
referralSequenceNumber: "test",
|
|
lineItems: {
|
|
serverData: "test",
|
|
},
|
|
},
|
|
};
|
|
|
|
globalMethods.callHttpClient = jest.fn().mockResolvedValue({
|
|
data: {},
|
|
});
|
|
|
|
crypto.randomUUID = jest.fn(() => "GUID");
|
|
|
|
// Act
|
|
actions.validateOrderPromoAndSaveServerData(context, {
|
|
payload: {
|
|
promoCode: promoCode,
|
|
lineItemsToUse: lineItemsToUse,
|
|
addableVaps: addableVaps,
|
|
},
|
|
pageNameToLog: "test",
|
|
});
|
|
|
|
const firstCallArgs = globalMethods.callHttpClient.mock.calls[0];
|
|
|
|
// Assert
|
|
expect(firstCallArgs[0].payload.addableVaps[0].id).toEqual("GUID");
|
|
});
|
|
it("should use lineItems from the store if not provided in the call", async () => {
|
|
// Arrange
|
|
const context = state;
|
|
const promoCode = "testPromo";
|
|
const lineItemsToUse = null;
|
|
const addableVaps = [{ partNumber: "addableVap" }];
|
|
|
|
context["getters"] = {
|
|
order: {
|
|
serviceLocation: {
|
|
appointmentType: "test",
|
|
state: "test",
|
|
zipCodeCtu: "test",
|
|
},
|
|
vehicle: {
|
|
carId: "test",
|
|
year: "test",
|
|
},
|
|
referralCorrelationId: "test",
|
|
eon: "test",
|
|
damage: {
|
|
isRepair: true,
|
|
glassToReplace: null,
|
|
},
|
|
payment: {
|
|
parentAccountNumber: "test",
|
|
},
|
|
referralSequenceNumber: "test",
|
|
lineItems: {
|
|
vaps: [{ partNumber: 1 }],
|
|
promos: [{ promoCode: "1wiper0" }],
|
|
serverData: "test",
|
|
},
|
|
},
|
|
};
|
|
|
|
globalMethods.callHttpClient = jest.fn().mockResolvedValue({
|
|
data: {},
|
|
});
|
|
|
|
crypto.randomUUID = jest.fn(() => "GUID");
|
|
|
|
const expectedLineItemsOnOrder = [
|
|
{ partNumber: 1, isChildPart: false, id: "GUID" },
|
|
{ promoCode: "1wiper0", isChildPart: false },
|
|
];
|
|
|
|
// Act
|
|
actions.validateOrderPromoAndSaveServerData(context, {
|
|
payload: {
|
|
promoCode: promoCode,
|
|
lineItemsToUse: lineItemsToUse,
|
|
addableVaps: addableVaps,
|
|
},
|
|
pageNameToLog: "test",
|
|
});
|
|
const firstCallArgs = globalMethods.callHttpClient.mock.calls[0];
|
|
|
|
// Assert
|
|
expect(firstCallArgs[0].payload.order.lineItemsOnOrder).toEqual(
|
|
expectedLineItemsOnOrder
|
|
);
|
|
});
|
|
it("should not blow up if an error comes back from the http call", async () => {
|
|
// Arrange
|
|
const context = state;
|
|
const promoCode = "testPromo";
|
|
const lineItemsToUse = null;
|
|
const addableVaps = [{ partNumber: "addableVap" }];
|
|
|
|
context["getters"] = {
|
|
order: {
|
|
serviceLocation: {
|
|
appointmentType: "test",
|
|
state: "test",
|
|
zipCodeCtu: "test",
|
|
},
|
|
vehicle: {
|
|
carId: "test",
|
|
year: "test",
|
|
},
|
|
referralCorrelationId: "test",
|
|
eon: "test",
|
|
damage: {
|
|
isRepair: true,
|
|
glassToReplace: null,
|
|
},
|
|
payment: {
|
|
parentAccountNumber: "test",
|
|
},
|
|
referralSequenceNumber: "test",
|
|
lineItems: {
|
|
vaps: [{ partNumber: 1 }],
|
|
promos: [{ promoCode: "1wiper0" }],
|
|
serverData: "test",
|
|
},
|
|
},
|
|
};
|
|
|
|
globalMethods.callHttpClient = jest.fn(() =>
|
|
Promise.reject(new Error("Error message"))
|
|
);
|
|
|
|
crypto.randomUUID = jest.fn(() => "GUID");
|
|
|
|
// Act
|
|
try {
|
|
await actions.validateOrderPromoAndSaveServerData(context, {
|
|
payload: {
|
|
promoCode: promoCode,
|
|
lineItemsToUse: lineItemsToUse,
|
|
addableVaps: addableVaps,
|
|
},
|
|
pageNameToLog: "test",
|
|
});
|
|
} catch (error) {
|
|
// Assert
|
|
fail("Unhandled error occurred");
|
|
}
|
|
});
|
|
it("should always save serverData if any is received from the http call", async () => {
|
|
// Arrange
|
|
const context = state;
|
|
const promoCode = "testPromo";
|
|
const lineItemsToUse = null;
|
|
const addableVaps = [{ partNumber: "addableVap" }];
|
|
context.commit = jest.fn(() => {});
|
|
|
|
context["getters"] = {
|
|
order: {
|
|
serviceLocation: {
|
|
appointmentType: "test",
|
|
state: "test",
|
|
zipCodeCtu: "test",
|
|
},
|
|
vehicle: {
|
|
carId: "test",
|
|
year: "test",
|
|
},
|
|
referralCorrelationId: "test",
|
|
eon: "test",
|
|
damage: {
|
|
isRepair: true,
|
|
glassToReplace: null,
|
|
},
|
|
payment: {
|
|
parentAccountNumber: "test",
|
|
},
|
|
referralSequenceNumber: "test",
|
|
lineItems: {
|
|
vaps: [{ partNumber: 1 }],
|
|
promos: [{ promoCode: "1wiper0" }],
|
|
serverData: "test",
|
|
},
|
|
},
|
|
};
|
|
|
|
globalMethods.callHttpClient = jest.fn().mockResolvedValue({
|
|
data: { serverData: "serverData" },
|
|
});
|
|
|
|
crypto.randomUUID = jest.fn(() => "GUID");
|
|
|
|
// Act
|
|
await actions.validateOrderPromoAndSaveServerData(context, {
|
|
payload: {
|
|
promoCode: promoCode,
|
|
lineItemsToUse: lineItemsToUse,
|
|
addableVaps: addableVaps,
|
|
},
|
|
pageNameToLog: "test",
|
|
});
|
|
|
|
// Assert
|
|
expect(context.commit).toBeCalledWith(
|
|
storeMutations.UPDATE_LINE_ITEMS_SERVER_DATA,
|
|
expect.anything()
|
|
);
|
|
});
|
|
});
|
|
describe("revalidateOrderPromosAndSaveServerData", () => {
|
|
it("should add GUIDs if not there to provided vaps before sending the http call", async () => {
|
|
// Arrange
|
|
const context = state;
|
|
context.commit = jest.fn(() => {});
|
|
|
|
context["getters"] = {
|
|
order: {
|
|
serviceLocation: {
|
|
appointmentType: "test",
|
|
state: "test",
|
|
zipCodeCtu: "test",
|
|
},
|
|
vehicle: {
|
|
carId: "test",
|
|
year: "test",
|
|
},
|
|
referralCorrelationId: "test",
|
|
eon: "test",
|
|
damage: {
|
|
isRepair: true,
|
|
glassToReplace: null,
|
|
},
|
|
payment: {
|
|
parentAccountNumber: "test",
|
|
inactivePromos: ["inactiveTest"],
|
|
},
|
|
referralSequenceNumber: "test",
|
|
lineItems: {
|
|
serverData: "test",
|
|
promos: [{ promoCode: "test" }],
|
|
vaps: [{ partNumber: "testVap" }],
|
|
},
|
|
},
|
|
};
|
|
|
|
globalMethods.callHttpClient = jest.fn().mockResolvedValue({
|
|
data: { lineItemsServerData: "testData" },
|
|
});
|
|
|
|
crypto.randomUUID = jest.fn(() => "GUID");
|
|
|
|
// Act
|
|
actions.revalidateOrderPromosAndSaveServerData(context, {
|
|
payload: {},
|
|
pageNameToLog: "test",
|
|
});
|
|
|
|
const firstCallArgs = globalMethods.callHttpClient.mock.calls[0];
|
|
|
|
// Assert
|
|
const vapsLineItem = firstCallArgs[0].payload.order.lineItemsOnOrder.filter(
|
|
(lineItem) => {
|
|
return lineItem.partNumber == "testVap";
|
|
}
|
|
);
|
|
expect(vapsLineItem[0].id).toEqual("GUID");
|
|
});
|
|
it("uses provided parameters in favor of store values", async () => {
|
|
// Arrange
|
|
const context = state;
|
|
context.commit = jest.fn(() => {});
|
|
|
|
const activePromosToUse = [{ promoCode: "providedPromo", isChildPart: false }];
|
|
const inactivePromosToUse = ["providedInactivePromo"];
|
|
const vapsProvided = [{ id: 123, isChildPart: false }];
|
|
const lineItemsToUse = { vaps: vapsProvided };
|
|
|
|
context["getters"] = {
|
|
order: {
|
|
serviceLocation: {
|
|
appointmentType: "test",
|
|
state: "test",
|
|
zipCodeCtu: "test",
|
|
},
|
|
vehicle: {
|
|
carId: "test",
|
|
year: "test",
|
|
},
|
|
referralCorrelationId: "test",
|
|
eon: "test",
|
|
damage: {
|
|
isRepair: true,
|
|
glassToReplace: null,
|
|
},
|
|
payment: {
|
|
parentAccountNumber: "test",
|
|
inactivePromos: ["inactiveTest"],
|
|
},
|
|
referralSequenceNumber: "test",
|
|
lineItems: {
|
|
serverData: "test",
|
|
promos: [{ promoCode: "test" }],
|
|
vaps: [{ partNumber: "testVap" }],
|
|
},
|
|
},
|
|
};
|
|
|
|
globalMethods.callHttpClient = jest.fn().mockResolvedValue({
|
|
data: { lineItemsServerData: "testData" },
|
|
});
|
|
|
|
crypto.randomUUID = jest.fn(() => "GUID");
|
|
|
|
// Act
|
|
actions.revalidateOrderPromosAndSaveServerData(context, {
|
|
payload: {
|
|
activePromosToUse: activePromosToUse,
|
|
inactivePromosToUse: inactivePromosToUse,
|
|
lineItemsToUse: lineItemsToUse,
|
|
},
|
|
pageNameToLog: "test",
|
|
});
|
|
|
|
const firstCallArgs = globalMethods.callHttpClient.mock.calls[0];
|
|
const expectedInactivePromos = ["providedInactivePromo"];
|
|
const expectedLineItemsOnOrder = [...vapsProvided, ...activePromosToUse];
|
|
|
|
// Assert
|
|
expect(firstCallArgs[0].payload.inactivePromos).toEqual(expectedInactivePromos);
|
|
expect(firstCallArgs[0].payload.order.lineItemsOnOrder).toEqual(
|
|
expectedLineItemsOnOrder
|
|
);
|
|
});
|
|
it("can build a valid payload with store data only", async () => {
|
|
// Arrange
|
|
const context = state;
|
|
context.commit = jest.fn(() => {});
|
|
|
|
context["getters"] = {
|
|
order: {
|
|
serviceLocation: {
|
|
appointmentType: "test",
|
|
state: "test",
|
|
zipCodeCtu: "test",
|
|
},
|
|
vehicle: {
|
|
carId: "test",
|
|
year: "test",
|
|
},
|
|
referralCorrelationId: "test",
|
|
eon: "test",
|
|
damage: {
|
|
isRepair: true,
|
|
glassToReplace: null,
|
|
},
|
|
payment: {
|
|
parentAccountNumber: "test",
|
|
inactivePromos: ["inactiveTest"],
|
|
},
|
|
referralSequenceNumber: "test",
|
|
lineItems: {
|
|
serverData: "test",
|
|
promos: [{ promoCode: "test", isChildPart: false }],
|
|
vaps: [{ partNumber: "testVap", isChildPart: false, id: "providedId" }],
|
|
},
|
|
},
|
|
};
|
|
|
|
globalMethods.callHttpClient = jest.fn().mockResolvedValue({
|
|
data: { lineItemsServerData: "testData" },
|
|
});
|
|
|
|
crypto.randomUUID = jest.fn(() => "GUID");
|
|
|
|
// Act
|
|
actions.revalidateOrderPromosAndSaveServerData(context, {
|
|
payload: {},
|
|
pageNameToLog: "test",
|
|
});
|
|
|
|
const expectedLineItemsOnOrder = [
|
|
...context.getters.order.lineItems.vaps,
|
|
...context.getters.order.lineItems.promos,
|
|
];
|
|
const firstCallArgs = globalMethods.callHttpClient.mock.calls[0];
|
|
// Assert
|
|
expect(firstCallArgs[0].payload.inactivePromos).toEqual(
|
|
context.getters.order.payment.inactivePromos
|
|
);
|
|
expect(firstCallArgs[0].payload.order.lineItemsOnOrder).toEqual(
|
|
expectedLineItemsOnOrder
|
|
);
|
|
});
|
|
it("removes any promos from inactivePromos that are already active before sending the request", async () => {
|
|
// Arrange
|
|
const context = state;
|
|
context.commit = jest.fn(() => {});
|
|
|
|
const activePromosToUse = [{ promoCode: "providedPromoDuplicate" }];
|
|
const inactivePromosToUse = ["providedPromoDuplicate"];
|
|
const vapsProvided = [{ id: 123 }];
|
|
const lineItemsToUse = { vaps: vapsProvided };
|
|
|
|
context["getters"] = {
|
|
order: {
|
|
serviceLocation: {
|
|
appointmentType: "test",
|
|
state: "test",
|
|
zipCodeCtu: "test",
|
|
},
|
|
vehicle: {
|
|
carId: "test",
|
|
year: "test",
|
|
},
|
|
referralCorrelationId: "test",
|
|
eon: "test",
|
|
damage: {
|
|
isRepair: true,
|
|
glassToReplace: null,
|
|
},
|
|
payment: {
|
|
parentAccountNumber: "test",
|
|
},
|
|
referralSequenceNumber: "test",
|
|
lineItems: {
|
|
serverData: "test",
|
|
},
|
|
},
|
|
};
|
|
|
|
globalMethods.callHttpClient = jest.fn().mockResolvedValue({
|
|
data: { lineItemsServerData: "testData" },
|
|
});
|
|
|
|
crypto.randomUUID = jest.fn(() => "GUID");
|
|
|
|
// Act
|
|
actions.revalidateOrderPromosAndSaveServerData(context, {
|
|
payload: {
|
|
activePromosToUse: activePromosToUse,
|
|
inactivePromosToUse: inactivePromosToUse,
|
|
lineItemsToUse: lineItemsToUse,
|
|
},
|
|
pageNameToLog: "test",
|
|
});
|
|
|
|
const firstCallArgs = globalMethods.callHttpClient.mock.calls[0];
|
|
// Assert
|
|
expect(firstCallArgs[0].payload.inactivePromos).toEqual([]);
|
|
});
|
|
it("saves serverData to the store", async () => {
|
|
// Arrange
|
|
const context = state;
|
|
context.commit = jest.fn(() => {});
|
|
|
|
const activePromosToUse = [{ promoCode: "providedPromoDuplicate" }];
|
|
const inactivePromosToUse = ["providedPromoDuplicate"];
|
|
const vapsProvided = [{ id: 123 }];
|
|
const lineItemsToUse = { vaps: vapsProvided };
|
|
|
|
context["getters"] = {
|
|
order: {
|
|
serviceLocation: {
|
|
appointmentType: "test",
|
|
state: "test",
|
|
zipCodeCtu: "test",
|
|
},
|
|
vehicle: {
|
|
carId: "test",
|
|
year: "test",
|
|
},
|
|
referralCorrelationId: "test",
|
|
eon: "test",
|
|
damage: {
|
|
isRepair: true,
|
|
glassToReplace: null,
|
|
},
|
|
payment: {
|
|
parentAccountNumber: "test",
|
|
},
|
|
referralSequenceNumber: "test",
|
|
lineItems: {
|
|
serverData: "test",
|
|
},
|
|
},
|
|
};
|
|
|
|
globalMethods.callHttpClient = jest.fn().mockResolvedValue({
|
|
data: { lineItemsServerData: "testData" },
|
|
});
|
|
|
|
crypto.randomUUID = jest.fn(() => "GUID");
|
|
|
|
// Act
|
|
await actions.revalidateOrderPromosAndSaveServerData(context, {
|
|
payload: {
|
|
activePromosToUse: activePromosToUse,
|
|
inactivePromosToUse: inactivePromosToUse,
|
|
lineItemsToUse: lineItemsToUse,
|
|
},
|
|
pageNameToLog: "test",
|
|
});
|
|
|
|
// Assert
|
|
expect(context.commit).toBeCalledWith(
|
|
storeMutations.UPDATE_LINE_ITEMS_SERVER_DATA,
|
|
expect.anything()
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("v2 time slot actions", () => {
|
|
const buildTimeSlotContext = () => ({
|
|
state,
|
|
getters: {
|
|
payment: { billToAccountNumber: "87291" },
|
|
},
|
|
});
|
|
|
|
it("getShopTimeSlotsV2 calls v2 shop endpoint with providerNumbers and endDate", async () => {
|
|
const context = buildTimeSlotContext();
|
|
|
|
globalMethods.callHttpClient.mockResolvedValue({ data: { providerTimeSlots: [] } });
|
|
|
|
await actions.getShopTimeSlotsV2(context, {
|
|
payload: {
|
|
startDate: "2026-07-07",
|
|
endDate: "2026-07-21",
|
|
shopAppointmentType: "InshopOrDropoff",
|
|
providerNumbers: ["05018", "05019"],
|
|
},
|
|
pageNameToLog: "scheduling",
|
|
});
|
|
|
|
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
method: endpoints.GetShopTimeSlotsV2.method,
|
|
endpoint: endpoints.GetShopTimeSlotsV2.url,
|
|
payload: expect.objectContaining({
|
|
startDate: "2026-07-07",
|
|
endDate: "2026-07-21",
|
|
providerNumbers: ["05018", "05019"],
|
|
shopAppointmentType: "InshopOrDropoff",
|
|
}),
|
|
})
|
|
);
|
|
});
|
|
|
|
it("getMobileTimeSlotsV2 calls v2 mobile endpoint with endDate", async () => {
|
|
const context = buildTimeSlotContext();
|
|
|
|
globalMethods.callHttpClient.mockResolvedValue({ data: { days: [] } });
|
|
|
|
await actions.getMobileTimeSlotsV2(context, {
|
|
payload: {
|
|
startDate: "2026-07-07",
|
|
endDate: "2026-07-21",
|
|
zipCode: "43235",
|
|
},
|
|
pageNameToLog: "scheduling",
|
|
});
|
|
|
|
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
method: endpoints.GetMobileTimeSlotsV2.method,
|
|
endpoint: endpoints.GetMobileTimeSlotsV2.url,
|
|
payload: expect.objectContaining({
|
|
startDate: "2026-07-07",
|
|
endDate: "2026-07-21",
|
|
zipCode: "43235",
|
|
}),
|
|
})
|
|
);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("submittedStateRevision", () => {
|
|
beforeEach(() => {
|
|
mutations.resetState(store.state);
|
|
window.sessionStorage.removeItem(sessionStorageKeyConstants.SUBMITTED_STATE);
|
|
});
|
|
|
|
it("resetSubmittedState action commits INCREMENT_SUBMITTED_STATE_REVISION", async () => {
|
|
const context = { commit: jest.fn() };
|
|
|
|
await actions.resetSubmittedState(context);
|
|
|
|
expect(context.commit).toHaveBeenCalledWith(
|
|
storeMutations.INCREMENT_SUBMITTED_STATE_REVISION
|
|
);
|
|
});
|
|
|
|
it("createSubmittedState action commits INCREMENT_SUBMITTED_STATE_REVISION at end", async () => {
|
|
const context = {
|
|
commit: jest.fn(),
|
|
state: {
|
|
order: {
|
|
payment: { insuranceCoverage: { isVerified: false } },
|
|
policy: { currentDeductible: 0 },
|
|
lineItems: {},
|
|
},
|
|
applicationUser: {
|
|
experiments: [],
|
|
affiliateCookies: [],
|
|
},
|
|
},
|
|
};
|
|
|
|
await actions.createSubmittedState(context);
|
|
|
|
expect(context.commit).toHaveBeenCalledWith(
|
|
storeMutations.INCREMENT_SUBMITTED_STATE_REVISION
|
|
);
|
|
});
|
|
|
|
it("addDonationToSubmittedState action commits INCREMENT_SUBMITTED_STATE_REVISION", async () => {
|
|
window.sessionStorage.setItem(
|
|
sessionStorageKeyConstants.SUBMITTED_STATE,
|
|
JSON.stringify({
|
|
order: {
|
|
lineItems: { supportingItems: [] },
|
|
},
|
|
applicationUser: {},
|
|
})
|
|
);
|
|
|
|
const context = { commit: jest.fn() };
|
|
|
|
await actions.addDonationToSubmittedState(context, 5);
|
|
|
|
expect(context.commit).toHaveBeenCalledWith(
|
|
storeMutations.INCREMENT_SUBMITTED_STATE_REVISION
|
|
);
|
|
});
|
|
|
|
it("coverageIsVerified re-evaluates after resetSubmittedState clears sessionStorage", () => {
|
|
window.sessionStorage.setItem(
|
|
sessionStorageKeyConstants.SUBMITTED_STATE,
|
|
JSON.stringify({
|
|
order: {
|
|
payment: { insuranceCoverage: { isVerified: true } },
|
|
policy: { currentDeductible: 500 },
|
|
},
|
|
applicationUser: {},
|
|
})
|
|
);
|
|
|
|
expect(store.getters.coverageIsVerified).toBe(true);
|
|
|
|
store.dispatch(storeActions.RESET_SUBMITTED_STATE);
|
|
|
|
expect(store.getters.coverageIsVerified).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("Getters", () => {
|
|
it("Vehicle getter, should return vehicle data", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
// Act
|
|
mutations.updateYear(storeState, "2019");
|
|
mutations.updateMake(storeState, "Acura");
|
|
mutations.updateModel(storeState, "ILX");
|
|
|
|
// Assert
|
|
expect(getters.vehicle(storeState).year).toEqual("2019");
|
|
expect(getters.vehicle(storeState).make).toEqual("Acura");
|
|
expect(getters.vehicle(storeState).model).toEqual("ILX");
|
|
});
|
|
|
|
it("Get event bus item by event category and eventSubCategory", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
const event = {
|
|
category: "CategoryOne",
|
|
subCategory: "SubCategoryOne",
|
|
eventValue: "EventValueOne",
|
|
};
|
|
|
|
// Act
|
|
mutations.addEventToBus(storeState, event);
|
|
|
|
// Assert
|
|
//expect(storeState.applicationUser.eventBus).toEqual([event]);
|
|
expect(getters.eventBusItem(storeState)(event.category, event.subCategory)).toEqual(
|
|
event.eventValue
|
|
);
|
|
});
|
|
|
|
it("Get event bus", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
storeState.applicationUser.eventBus = [];
|
|
|
|
const event = {
|
|
category: "CategoryOne",
|
|
subCategory: "SubCategoryOne",
|
|
eventValue: "EventValueOne",
|
|
};
|
|
|
|
// Act
|
|
mutations.addEventToBus(storeState, event);
|
|
|
|
// Assert
|
|
expect(getters.eventBus(storeState)).toEqual([event]);
|
|
});
|
|
|
|
it("Damage getter, should return damage data", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
// Act
|
|
mutations.updateGlassToReplace(storeState, ["Rear"]);
|
|
|
|
// Assert
|
|
expect(getters.damage(storeState).glassToReplace).toEqual(["Rear"]);
|
|
});
|
|
|
|
it("lineItems getter, should return lineItem data", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
// Act
|
|
mutations.updateGlassParts(storeState, { "Rear-Stationary": "PART101" });
|
|
|
|
// Assert
|
|
expect(getters.lineItems(storeState).glassParts).toEqual({ "Rear-Stationary": "PART101" });
|
|
});
|
|
|
|
it("PageData getter, should return page data for specific page", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
// Act
|
|
mutations.updatePageData(storeState, { page: "vehicle-year", data: {} });
|
|
|
|
// Assert
|
|
expect(getters.pageData(storeState)("vehicle-year")).toEqual({});
|
|
});
|
|
|
|
it("Payment getter, should return payment data", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
//Act
|
|
mutations.updateInsuranceVerifiedStatus(storeState, true);
|
|
|
|
//Assert
|
|
expect(getters.payment(storeState).insuranceCoverage.isVerified).toEqual(true);
|
|
});
|
|
|
|
describe("isMobileAppointment", () => {
|
|
it("Should return true for mobile appointments", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
// Act
|
|
mutations.updateServiceLocation(storeState, {
|
|
appointmentType: AppointmentTypeStrings.MOBILE,
|
|
});
|
|
|
|
// Assert
|
|
expect(getters.isMobileAppointment(storeState)).toBe(true);
|
|
});
|
|
|
|
it("Should return false for non-mobile appointments", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
// Act
|
|
mutations.updateServiceLocation(storeState, {
|
|
appointmentType: AppointmentTypeStrings.IN_SHOP,
|
|
});
|
|
|
|
// Assert
|
|
expect(getters.isMobileAppointment(storeState)).toBe(false);
|
|
});
|
|
|
|
it("Should return false for null appointments", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
|
|
// Act
|
|
mutations.updateServiceLocation(storeState, { appointmentType: null });
|
|
|
|
// Assert
|
|
expect(getters.isMobileAppointment(storeState)).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("experimentOrder", () => {
|
|
test("glassToReplace, glassParts, and otherParts are null > return correct experimentOrder values", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
const mockStateValues = {
|
|
funnelVehicleYear: 1000,
|
|
funnelVehicleMake: "CarMake",
|
|
funnelVehicleModel: "CarModel",
|
|
funnelVehicleStyle: "SuperCoolStyle",
|
|
funnelIsRepair: true,
|
|
funnelNumberOfChips: 9999999,
|
|
funnelCarId: "Gibberish",
|
|
funnelServiceCity: "Columbus",
|
|
funnelServiceState: "OH-IO",
|
|
funnelServiceZipCode: 43215,
|
|
funnelParentAccountNumber: "999999",
|
|
funnelPolicyIsItac: "false",
|
|
funnelPolicyIsNoComp: "false",
|
|
funnelIsCoverageVerified: true,
|
|
funnelGlassParts: null,
|
|
funnelSupportingItems: null,
|
|
funnelVaps: null,
|
|
funnelGlassToReplace: null,
|
|
funnelProviderNumber: "1",
|
|
funnelReferralType: "CASH QUOTE",
|
|
funnelServiceZipCodeCtu: "11111",
|
|
};
|
|
|
|
//Act
|
|
mutations.updateYear(storeState, mockStateValues.funnelVehicleYear);
|
|
mutations.updateMake(storeState, mockStateValues.funnelVehicleMake);
|
|
mutations.updateModel(storeState, mockStateValues.funnelVehicleModel);
|
|
mutations.updateStyle(storeState, mockStateValues.funnelVehicleStyle);
|
|
mutations.updateIsRepair(storeState, mockStateValues.funnelIsRepair);
|
|
mutations.updateNumberOfChips(storeState, mockStateValues.funnelNumberOfChips);
|
|
mutations.updateCarId(storeState, mockStateValues.funnelCarId);
|
|
mutations.updateServiceLocation(storeState, {
|
|
city: mockStateValues.funnelServiceCity,
|
|
state: mockStateValues.funnelServiceState,
|
|
zipCode: mockStateValues.funnelServiceZipCode,
|
|
zipCodeCtu: mockStateValues.funnelServiceZipCodeCtu,
|
|
provider: {
|
|
providerNumber: mockStateValues.funnelProviderNumber,
|
|
},
|
|
});
|
|
mutations.updateParentAcctNumber(storeState, mockStateValues.funnelParentAccountNumber);
|
|
mutations.updateInsuranceVerifiedStatus(
|
|
storeState,
|
|
mockStateValues.funnelIsCoverageVerified
|
|
);
|
|
mutations.updateIsInsurance(storeState, false);
|
|
mutations.updateGlassParts(storeState, mockStateValues.funnelGlassParts);
|
|
mutations.updateSupportingItems(storeState, mockStateValues.funnelSupportingItems);
|
|
mutations.updateVaps(storeState, mockStateValues.funnelVaps);
|
|
mutations.updateGlassToReplace(storeState, mockStateValues.funnelGlassToReplace);
|
|
|
|
//Assert
|
|
expect(getters.experimentOrder(storeState)).toEqual({
|
|
funnelVehicleYear: mockStateValues.funnelVehicleYear,
|
|
funnelVehicleMake: mockStateValues.funnelVehicleMake,
|
|
funnelVehicleModel: mockStateValues.funnelVehicleModel,
|
|
funnelVehicleStyle: mockStateValues.funnelVehicleStyle,
|
|
funnelIsRepair: mockStateValues.funnelIsRepair,
|
|
funnelNumberOfChips: mockStateValues.funnelNumberOfChips,
|
|
funnelCarId: mockStateValues.funnelCarId,
|
|
funnelServiceCity: mockStateValues.funnelServiceCity,
|
|
funnelServiceState: mockStateValues.funnelServiceState,
|
|
funnelServiceZipCode: mockStateValues.funnelServiceZipCode,
|
|
funnelParentAccountNumber: mockStateValues.funnelParentAccountNumber,
|
|
funnelPolicyIsItac: mockStateValues.funnelPolicyIsItac,
|
|
funnelPolicyIsNoComp: mockStateValues.funnelPolicyIsNoComp,
|
|
funnelIsCoverageVerified: mockStateValues.funnelIsCoverageVerified,
|
|
funnelOrderPartNumbers: [],
|
|
funnelOrderPartTypes: [],
|
|
funnelHasRecalibrationPart: false,
|
|
funnelSelectedMultiGlass: false,
|
|
funnelSelectedWindshieldGlass: false,
|
|
funnelSelectedBackGlass: false,
|
|
funnelSelectedDriverSideGlass: false,
|
|
funnelSelectedPassengerSideGlass: false,
|
|
funnelProviderNumber: mockStateValues.funnelProviderNumber,
|
|
funnelReferralType: mockStateValues.funnelReferralType,
|
|
funnelServiceZipCodeCtu: mockStateValues.funnelServiceZipCodeCtu,
|
|
});
|
|
});
|
|
|
|
test("glassToReplace, glassParts, and otherParts are empty > return correct experimentOrder values", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
const mockStateValues = {
|
|
funnelVehicleYear: 1000,
|
|
funnelVehicleMake: "CarMake",
|
|
funnelVehicleModel: "CarModel",
|
|
funnelVehicleStyle: "SuperCoolStyle",
|
|
funnelIsRepair: true,
|
|
funnelNumberOfChips: 9999999,
|
|
funnelCarId: "Gibberish",
|
|
funnelServiceCity: "Columbus",
|
|
funnelServiceState: "OH-IO",
|
|
funnelServiceZipCode: 43215,
|
|
funnelParentAccountNumber: "999999",
|
|
funnelPolicyIsItac: "false",
|
|
funnelPolicyIsNoComp: "false",
|
|
funnelIsCoverageVerified: true,
|
|
funnelGlassParts: [],
|
|
funnelOtherParts: [],
|
|
funnelGlassToReplace: [],
|
|
funnelProviderNumber: "1",
|
|
funnelReferralType: "CASH QUOTE",
|
|
funnelServiceZipCodeCtu: "11111",
|
|
};
|
|
|
|
//Act
|
|
mutations.updateYear(storeState, mockStateValues.funnelVehicleYear);
|
|
mutations.updateMake(storeState, mockStateValues.funnelVehicleMake);
|
|
mutations.updateModel(storeState, mockStateValues.funnelVehicleModel);
|
|
mutations.updateStyle(storeState, mockStateValues.funnelVehicleStyle);
|
|
mutations.updateIsRepair(storeState, mockStateValues.funnelIsRepair);
|
|
mutations.updateNumberOfChips(storeState, mockStateValues.funnelNumberOfChips);
|
|
mutations.updateCarId(storeState, mockStateValues.funnelCarId);
|
|
mutations.updateServiceLocation(storeState, {
|
|
city: mockStateValues.funnelServiceCity,
|
|
state: mockStateValues.funnelServiceState,
|
|
zipCode: mockStateValues.funnelServiceZipCode,
|
|
zipCodeCtu: mockStateValues.funnelServiceZipCodeCtu,
|
|
provider: {
|
|
providerNumber: mockStateValues.funnelProviderNumber,
|
|
},
|
|
});
|
|
mutations.updateParentAcctNumber(storeState, mockStateValues.funnelParentAccountNumber);
|
|
mutations.updateInsuranceVerifiedStatus(
|
|
storeState,
|
|
mockStateValues.funnelIsCoverageVerified
|
|
);
|
|
mutations.updateIsInsurance(storeState, false);
|
|
mutations.updateGlassParts(storeState, mockStateValues.funnelGlassParts);
|
|
mutations.updateSupportingItems(storeState, mockStateValues.funnelSupportingItems);
|
|
mutations.updateVaps(storeState, mockStateValues.funnelVaps);
|
|
mutations.updateGlassToReplace(storeState, mockStateValues.funnelGlassToReplace);
|
|
|
|
//Assert
|
|
expect(getters.experimentOrder(storeState)).toEqual({
|
|
funnelVehicleYear: mockStateValues.funnelVehicleYear,
|
|
funnelVehicleMake: mockStateValues.funnelVehicleMake,
|
|
funnelVehicleModel: mockStateValues.funnelVehicleModel,
|
|
funnelVehicleStyle: mockStateValues.funnelVehicleStyle,
|
|
funnelIsRepair: mockStateValues.funnelIsRepair,
|
|
funnelNumberOfChips: mockStateValues.funnelNumberOfChips,
|
|
funnelCarId: mockStateValues.funnelCarId,
|
|
funnelServiceCity: mockStateValues.funnelServiceCity,
|
|
funnelServiceState: mockStateValues.funnelServiceState,
|
|
funnelServiceZipCode: mockStateValues.funnelServiceZipCode,
|
|
funnelParentAccountNumber: mockStateValues.funnelParentAccountNumber,
|
|
funnelPolicyIsItac: mockStateValues.funnelPolicyIsItac,
|
|
funnelPolicyIsNoComp: mockStateValues.funnelPolicyIsNoComp,
|
|
funnelIsCoverageVerified: mockStateValues.funnelIsCoverageVerified,
|
|
funnelOrderPartNumbers: [],
|
|
funnelOrderPartTypes: [],
|
|
funnelHasRecalibrationPart: false,
|
|
funnelSelectedMultiGlass: false,
|
|
funnelSelectedWindshieldGlass: false,
|
|
funnelSelectedBackGlass: false,
|
|
funnelSelectedDriverSideGlass: false,
|
|
funnelSelectedPassengerSideGlass: false,
|
|
funnelProviderNumber: mockStateValues.funnelProviderNumber,
|
|
funnelReferralType: mockStateValues.funnelReferralType,
|
|
funnelServiceZipCodeCtu: mockStateValues.funnelServiceZipCodeCtu,
|
|
});
|
|
});
|
|
|
|
test("Single windshield requiring recalibration is selected > return correct experimentOrder values", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
const mockStateValues = {
|
|
vehicleYear: 1000,
|
|
vehicleMake: "CarMake",
|
|
vehicleModel: "CarModel",
|
|
vehicleStyle: "SuperCoolStyle",
|
|
isRepair: false,
|
|
numberOfChips: 0,
|
|
carId: "Gibberish",
|
|
serviceCity: "Columbus",
|
|
serviceState: "OH-IO",
|
|
serviceZipCode: 43215,
|
|
parentAccountNumber: "999999",
|
|
funnelPolicyIsItac: "false",
|
|
funnelPolicyIsNoComp: "false",
|
|
isCoverageVerified: false,
|
|
glassParts: [
|
|
{
|
|
partNumber: "WINDSHIELDPARTNUMBER",
|
|
description: "This is a windshield",
|
|
recalibrationType: "ADAS, maybe",
|
|
requiresRecalibration: true,
|
|
requiresCapabilityQuestions: false,
|
|
},
|
|
],
|
|
otherParts: [],
|
|
glassToReplace: [
|
|
{
|
|
glassLocation: "Windshield",
|
|
glassName: "Single",
|
|
},
|
|
],
|
|
funnelProviderNumber: "1",
|
|
funnelReferralType: "CASH QUOTE",
|
|
funnelServiceZipCodeCtu: "11111",
|
|
};
|
|
|
|
//Act
|
|
mutations.updateYear(storeState, mockStateValues.vehicleYear);
|
|
mutations.updateMake(storeState, mockStateValues.vehicleMake);
|
|
mutations.updateModel(storeState, mockStateValues.vehicleModel);
|
|
mutations.updateStyle(storeState, mockStateValues.vehicleStyle);
|
|
mutations.updateIsRepair(storeState, mockStateValues.isRepair);
|
|
mutations.updateNumberOfChips(storeState, mockStateValues.numberOfChips);
|
|
mutations.updateCarId(storeState, mockStateValues.carId);
|
|
mutations.updateServiceLocation(storeState, {
|
|
city: mockStateValues.serviceCity,
|
|
state: mockStateValues.serviceState,
|
|
zipCode: mockStateValues.serviceZipCode,
|
|
zipCodeCtu: mockStateValues.funnelServiceZipCodeCtu,
|
|
provider: {
|
|
providerNumber: mockStateValues.funnelProviderNumber,
|
|
},
|
|
});
|
|
mutations.updateParentAcctNumber(storeState, mockStateValues.parentAccountNumber);
|
|
mutations.updateInsuranceVerifiedStatus(storeState, mockStateValues.isCoverageVerified);
|
|
mutations.updateIsInsurance(storeState, false);
|
|
mutations.updateGlassParts(storeState, mockStateValues.glassParts);
|
|
mutations.updateSupportingItems(storeState, mockStateValues.funnelSupportingItems);
|
|
mutations.updateVaps(storeState, mockStateValues.funnelVaps);
|
|
mutations.updateGlassToReplace(storeState, mockStateValues.glassToReplace);
|
|
|
|
//Assert
|
|
expect(getters.experimentOrder(storeState)).toEqual({
|
|
funnelVehicleYear: mockStateValues.vehicleYear,
|
|
funnelVehicleMake: mockStateValues.vehicleMake,
|
|
funnelVehicleModel: mockStateValues.vehicleModel,
|
|
funnelVehicleStyle: mockStateValues.vehicleStyle,
|
|
funnelIsRepair: mockStateValues.isRepair,
|
|
funnelNumberOfChips: mockStateValues.numberOfChips,
|
|
funnelCarId: mockStateValues.carId,
|
|
funnelServiceCity: mockStateValues.serviceCity,
|
|
funnelServiceState: mockStateValues.serviceState,
|
|
funnelServiceZipCode: mockStateValues.serviceZipCode,
|
|
funnelParentAccountNumber: mockStateValues.parentAccountNumber,
|
|
funnelPolicyIsItac: mockStateValues.funnelPolicyIsItac,
|
|
funnelPolicyIsNoComp: mockStateValues.funnelPolicyIsNoComp,
|
|
funnelIsCoverageVerified: mockStateValues.isCoverageVerified,
|
|
funnelOrderPartNumbers: ["WINDSHIELDPARTNUMBER"],
|
|
funnelOrderPartTypes: ["ADAS, maybe"],
|
|
funnelHasRecalibrationPart: false,
|
|
funnelSelectedMultiGlass: false,
|
|
funnelSelectedWindshieldGlass: true,
|
|
funnelSelectedBackGlass: false,
|
|
funnelSelectedDriverSideGlass: false,
|
|
funnelSelectedPassengerSideGlass: false,
|
|
funnelProviderNumber: mockStateValues.funnelProviderNumber,
|
|
funnelReferralType: mockStateValues.funnelReferralType,
|
|
funnelServiceZipCodeCtu: mockStateValues.funnelServiceZipCodeCtu,
|
|
});
|
|
});
|
|
|
|
test("Single windshield with recalibration child part > return correct experimentOrder values", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
const mockStateValues = {
|
|
vehicleYear: 1000,
|
|
vehicleMake: "CarMake",
|
|
vehicleModel: "CarModel",
|
|
vehicleStyle: "SuperCoolStyle",
|
|
isRepair: false,
|
|
numberOfChips: 0,
|
|
carId: "Gibberish",
|
|
serviceCity: "Columbus",
|
|
serviceState: "OH-IO",
|
|
serviceZipCode: 43215,
|
|
parentAccountNumber: "999999",
|
|
funnelPolicyIsItac: "false",
|
|
funnelPolicyIsNoComp: "false",
|
|
isCoverageVerified: false,
|
|
glassParts: [
|
|
{
|
|
partNumber: "WINDSHIELDPARTNUMBER",
|
|
description: "This is a windshield",
|
|
recalibrationType: "ADAS, maybe",
|
|
requiresRecalibration: true,
|
|
requiresCapabilityQuestions: false,
|
|
childParts: [
|
|
{
|
|
partNumber: "THIRD RECAL",
|
|
description: "Additional Static Recal",
|
|
recalibrationType:
|
|
"DUAL & RECAL THIRD & HC FUNCTION TEST & RL SENSOR",
|
|
ribCode: "RL",
|
|
safelitePartNumber: "THIRD RECAL",
|
|
status: "ACTIVE",
|
|
partType: "ADAS RECALIBRATION",
|
|
childParts: [],
|
|
recalibrationFees: [],
|
|
salesTax: null,
|
|
},
|
|
],
|
|
},
|
|
],
|
|
otherParts: [],
|
|
glassToReplace: [
|
|
{
|
|
glassLocation: "Windshield",
|
|
glassName: "Single",
|
|
},
|
|
],
|
|
funnelProviderNumber: "1",
|
|
funnelReferralType: "CASH QUOTE",
|
|
funnelServiceZipCodeCtu: "11111",
|
|
};
|
|
|
|
//Act
|
|
mutations.updateYear(storeState, mockStateValues.vehicleYear);
|
|
mutations.updateMake(storeState, mockStateValues.vehicleMake);
|
|
mutations.updateModel(storeState, mockStateValues.vehicleModel);
|
|
mutations.updateStyle(storeState, mockStateValues.vehicleStyle);
|
|
mutations.updateIsRepair(storeState, mockStateValues.isRepair);
|
|
mutations.updateNumberOfChips(storeState, mockStateValues.numberOfChips);
|
|
mutations.updateCarId(storeState, mockStateValues.carId);
|
|
mutations.updateServiceLocation(storeState, {
|
|
city: mockStateValues.serviceCity,
|
|
state: mockStateValues.serviceState,
|
|
zipCode: mockStateValues.serviceZipCode,
|
|
zipCodeCtu: mockStateValues.funnelServiceZipCodeCtu,
|
|
provider: {
|
|
providerNumber: mockStateValues.funnelProviderNumber,
|
|
},
|
|
});
|
|
mutations.updateParentAcctNumber(storeState, mockStateValues.parentAccountNumber);
|
|
mutations.updateInsuranceVerifiedStatus(storeState, mockStateValues.isCoverageVerified);
|
|
mutations.updateIsInsurance(storeState, false);
|
|
mutations.updateGlassParts(storeState, mockStateValues.glassParts);
|
|
mutations.updateSupportingItems(storeState, mockStateValues.funnelSupportingItems);
|
|
mutations.updateVaps(storeState, mockStateValues.funnelVaps);
|
|
mutations.updateGlassToReplace(storeState, mockStateValues.glassToReplace);
|
|
|
|
//Assert
|
|
expect(getters.experimentOrder(storeState)).toEqual({
|
|
funnelVehicleYear: mockStateValues.vehicleYear,
|
|
funnelVehicleMake: mockStateValues.vehicleMake,
|
|
funnelVehicleModel: mockStateValues.vehicleModel,
|
|
funnelVehicleStyle: mockStateValues.vehicleStyle,
|
|
funnelIsRepair: mockStateValues.isRepair,
|
|
funnelNumberOfChips: mockStateValues.numberOfChips,
|
|
funnelCarId: mockStateValues.carId,
|
|
funnelServiceCity: mockStateValues.serviceCity,
|
|
funnelServiceState: mockStateValues.serviceState,
|
|
funnelServiceZipCode: mockStateValues.serviceZipCode,
|
|
funnelParentAccountNumber: mockStateValues.parentAccountNumber,
|
|
funnelPolicyIsItac: mockStateValues.funnelPolicyIsItac,
|
|
funnelPolicyIsNoComp: mockStateValues.funnelPolicyIsNoComp,
|
|
funnelIsCoverageVerified: mockStateValues.isCoverageVerified,
|
|
funnelOrderPartNumbers: ["WINDSHIELDPARTNUMBER"],
|
|
funnelOrderPartTypes: ["ADAS, maybe"],
|
|
funnelHasRecalibrationPart: true,
|
|
funnelSelectedMultiGlass: false,
|
|
funnelSelectedWindshieldGlass: true,
|
|
funnelSelectedBackGlass: false,
|
|
funnelSelectedDriverSideGlass: false,
|
|
funnelSelectedPassengerSideGlass: false,
|
|
funnelProviderNumber: mockStateValues.funnelProviderNumber,
|
|
funnelReferralType: mockStateValues.funnelReferralType,
|
|
funnelServiceZipCodeCtu: mockStateValues.funnelServiceZipCodeCtu,
|
|
});
|
|
});
|
|
|
|
test("Select multiglass > return correct experimentOrder values", () => {
|
|
// Arrange
|
|
const storeState = state;
|
|
const mockStateValues = {
|
|
vehicleYear: 1000,
|
|
vehicleMake: "CarMake",
|
|
vehicleModel: "CarModel",
|
|
vehicleStyle: "SuperCoolStyle",
|
|
isRepair: false,
|
|
numberOfChips: 0,
|
|
carId: "Gibberish",
|
|
serviceCity: "Columbus",
|
|
serviceState: "OH-IO",
|
|
serviceZipCode: 43215,
|
|
parentAccountNumber: "999999",
|
|
funnelPolicyIsItac: "false",
|
|
funnelPolicyIsNoComp: "false",
|
|
isCoverageVerified: false,
|
|
glassParts: [
|
|
{
|
|
partNumber: "BACKGLASS_PN",
|
|
description: "This is a back glass",
|
|
recalibrationType: null,
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: false,
|
|
},
|
|
{
|
|
partNumber: "DRIVERGLASS_PN",
|
|
description: "This is a driver side glass",
|
|
recalibrationType: null,
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: false,
|
|
},
|
|
{
|
|
partNumber: "PASSENGERGLASS_PN",
|
|
description: "This is a passenger side glass",
|
|
recalibrationType: null,
|
|
requiresRecalibration: false,
|
|
requiresCapabilityQuestions: false,
|
|
},
|
|
],
|
|
otherParts: [],
|
|
glassToReplace: [
|
|
{
|
|
glassLocation: "Rear",
|
|
glassName: "Stationary",
|
|
},
|
|
{
|
|
glassLocation: "Driver",
|
|
glassName: "Front",
|
|
},
|
|
{
|
|
glassLocation: "Passenger",
|
|
glassName: "Front",
|
|
},
|
|
{
|
|
glassLocation: "Passenger",
|
|
glassName: "Quarter",
|
|
},
|
|
],
|
|
funnelProviderNumber: "1",
|
|
funnelReferralType: "CASH QUOTE",
|
|
funnelServiceZipCodeCtu: "11111",
|
|
};
|
|
|
|
//Act
|
|
mutations.updateYear(storeState, mockStateValues.vehicleYear);
|
|
mutations.updateMake(storeState, mockStateValues.vehicleMake);
|
|
mutations.updateModel(storeState, mockStateValues.vehicleModel);
|
|
mutations.updateStyle(storeState, mockStateValues.vehicleStyle);
|
|
mutations.updateIsRepair(storeState, mockStateValues.isRepair);
|
|
mutations.updateNumberOfChips(storeState, mockStateValues.numberOfChips);
|
|
mutations.updateCarId(storeState, mockStateValues.carId);
|
|
mutations.updateServiceLocation(storeState, {
|
|
city: mockStateValues.serviceCity,
|
|
state: mockStateValues.serviceState,
|
|
zipCode: mockStateValues.serviceZipCode,
|
|
zipCodeCtu: mockStateValues.funnelServiceZipCodeCtu,
|
|
provider: {
|
|
providerNumber: mockStateValues.funnelProviderNumber,
|
|
},
|
|
});
|
|
mutations.updateParentAcctNumber(storeState, mockStateValues.parentAccountNumber);
|
|
mutations.updateInsuranceVerifiedStatus(storeState, mockStateValues.isCoverageVerified);
|
|
mutations.updateIsInsurance(storeState, false);
|
|
mutations.updateGlassParts(storeState, mockStateValues.glassParts);
|
|
mutations.updateSupportingItems(storeState, mockStateValues.funnelSupportingItems);
|
|
mutations.updateVaps(storeState, mockStateValues.funnelVaps);
|
|
mutations.updateGlassToReplace(storeState, mockStateValues.glassToReplace);
|
|
|
|
//Assert
|
|
expect(getters.experimentOrder(storeState)).toEqual({
|
|
funnelVehicleYear: mockStateValues.vehicleYear,
|
|
funnelVehicleMake: mockStateValues.vehicleMake,
|
|
funnelVehicleModel: mockStateValues.vehicleModel,
|
|
funnelVehicleStyle: mockStateValues.vehicleStyle,
|
|
funnelIsRepair: mockStateValues.isRepair,
|
|
funnelNumberOfChips: mockStateValues.numberOfChips,
|
|
funnelCarId: mockStateValues.carId,
|
|
funnelServiceCity: mockStateValues.serviceCity,
|
|
funnelServiceState: mockStateValues.serviceState,
|
|
funnelServiceZipCode: mockStateValues.serviceZipCode,
|
|
funnelParentAccountNumber: mockStateValues.parentAccountNumber,
|
|
funnelPolicyIsItac: mockStateValues.funnelPolicyIsItac,
|
|
funnelPolicyIsNoComp: mockStateValues.funnelPolicyIsNoComp,
|
|
funnelIsCoverageVerified: mockStateValues.isCoverageVerified,
|
|
funnelOrderPartNumbers: ["BACKGLASS_PN", "DRIVERGLASS_PN", "PASSENGERGLASS_PN"],
|
|
funnelOrderPartTypes: [],
|
|
funnelHasRecalibrationPart: false,
|
|
funnelSelectedMultiGlass: true,
|
|
funnelSelectedWindshieldGlass: false,
|
|
funnelSelectedBackGlass: true,
|
|
funnelSelectedDriverSideGlass: true,
|
|
funnelSelectedPassengerSideGlass: true,
|
|
funnelProviderNumber: mockStateValues.funnelProviderNumber,
|
|
funnelReferralType: mockStateValues.funnelReferralType,
|
|
funnelServiceZipCodeCtu: mockStateValues.funnelServiceZipCodeCtu,
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("isVinOptionalVehicle", () => {
|
|
const testVehicles = [
|
|
["2017", "acura", false],
|
|
["2018", "bmw", false],
|
|
["2009", "bmw", true],
|
|
["2016", "bmw", false],
|
|
["2016", "mercedes benz", false],
|
|
["2016", "volkswagen", false],
|
|
["2016", "audi", false],
|
|
["2016", "porsche", true],
|
|
["2009", "audi", true],
|
|
];
|
|
test.each(testVehicles)(
|
|
"%s %s should skip vin lookup is %s",
|
|
async (year, make, expectedVinSkip) => {
|
|
const context = state;
|
|
|
|
context.state = {
|
|
order: {
|
|
vehicle: { year: year, make: make },
|
|
},
|
|
};
|
|
|
|
mutations.updateSkipVINLookup(context.state, expectedVinSkip);
|
|
|
|
var vinOptionalResult = actions.isVinOptionalVehicle(context);
|
|
expect(vinOptionalResult).toEqual(expectedVinSkip);
|
|
}
|
|
);
|
|
const testcarID = [
|
|
["CR00000100", "make", [{ glassLocation: "driver" }], false],
|
|
["CR00067899", "make2", [{ glassLocation: "windshield" }], true],
|
|
[
|
|
"CR00062396",
|
|
"make3",
|
|
[{ glassLocation: "windshield" }, { glassLocation: "driver" }],
|
|
true,
|
|
],
|
|
["CR00066428", "make4", [{ glassLocation: "rear" }], false],
|
|
];
|
|
|
|
test.each(testcarID)(
|
|
"%s %s %o should skip vin lookup is %s",
|
|
async (carId, make, glassLocation, expectedVinSkip) => {
|
|
const context = state;
|
|
|
|
context.state = {
|
|
order: {
|
|
vehicle: { make: make, carId: carId },
|
|
damage: {
|
|
glassToReplace: glassLocation,
|
|
},
|
|
},
|
|
};
|
|
|
|
mutations.updateSkipVINLookup(context.state, expectedVinSkip);
|
|
|
|
var vinOptionalResult = actions.isVinOptionalVehicle(context);
|
|
expect(vinOptionalResult).toEqual(expectedVinSkip);
|
|
}
|
|
);
|
|
|
|
it("getParts action, should include problemQuestionId in answerResults payload", async () => {
|
|
const context = {
|
|
getters: {
|
|
vehicle: { carId: "CR00065283", vin: "SAJWA6A73F8K13235" },
|
|
damage: {
|
|
glassToReplace: [{ glassLocation: "Windshield", glassName: "Single" }],
|
|
partQuestionAnswers: [
|
|
{
|
|
glassLocation: "Windshield",
|
|
glassName: "Single",
|
|
result: "FW04848",
|
|
problemQuestionId: 38560,
|
|
answeredQuestions: [
|
|
{
|
|
questionText:
|
|
"Is your vehicle equipped with the Panoramic Sunroof which can be identified by having a glass panel over the rear seats?",
|
|
selectedAnswer: "1|nextQuestion|2|Yes",
|
|
selectedAnswerText: "Yes",
|
|
questionNum: 1,
|
|
problemQuestionId: 38557,
|
|
},
|
|
{
|
|
questionText:
|
|
"Is your vehicle equipped with a heated windshield that melts snow and ice from underneath the windshield wiper blades?",
|
|
selectedAnswer: "2|answer|FW04848|Yes",
|
|
selectedAnswerText: "Yes",
|
|
questionNum: 2,
|
|
problemQuestionId: 38560,
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
payment: { parentAccountNumber: "167132" },
|
|
},
|
|
state: {
|
|
order: {
|
|
serviceLocation: { zipCode: "43085", appointmentType: null },
|
|
referralSequenceNumber: "11330779",
|
|
},
|
|
},
|
|
};
|
|
|
|
globalMethods.callHttpClient.mockImplementation(({ payload }) => {
|
|
return Promise.resolve({ data: { glassPieceParts: [] }, payload });
|
|
});
|
|
|
|
await actions.getParts(context, { pageNameToLog: "part-questions" });
|
|
|
|
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
endpoint: endpoints.GetParts.url,
|
|
payload: expect.objectContaining({
|
|
answerResults: [
|
|
{
|
|
location: "Windshield",
|
|
name: "Single",
|
|
result: "FW04848",
|
|
problemQuestionId: 38560,
|
|
},
|
|
],
|
|
}),
|
|
})
|
|
);
|
|
});
|
|
|
|
it("getParts action, should omit problemQuestionId when not saved on part question answer", async () => {
|
|
const context = {
|
|
getters: {
|
|
vehicle: { carId: "CR00065283", vin: "SAJWA6A73F8K13235" },
|
|
damage: {
|
|
glassToReplace: [{ glassLocation: "Windshield", glassName: "Single" }],
|
|
partQuestionAnswers: [
|
|
{
|
|
glassLocation: "Windshield",
|
|
glassName: "Single",
|
|
result: "FW04848",
|
|
},
|
|
],
|
|
},
|
|
payment: { parentAccountNumber: "167132" },
|
|
},
|
|
state: {
|
|
order: {
|
|
serviceLocation: { zipCode: "43085", appointmentType: null },
|
|
referralSequenceNumber: "11330779",
|
|
},
|
|
},
|
|
};
|
|
|
|
globalMethods.callHttpClient.mockImplementation(() => {
|
|
return Promise.resolve({ data: { glassPieceParts: [] } });
|
|
});
|
|
|
|
await actions.getParts(context, { pageNameToLog: "part-questions" });
|
|
|
|
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
payload: expect.objectContaining({
|
|
answerResults: [
|
|
{
|
|
location: "Windshield",
|
|
name: "Single",
|
|
result: "FW04848",
|
|
},
|
|
],
|
|
}),
|
|
})
|
|
);
|
|
});
|
|
});
|