Merge pull request #810 from Safelite/feature/CSR-777

Feature/csr 777
This commit is contained in:
CarlNation 2022-11-11 14:09:20 -05:00 committed by GitHub
commit b6b98b2499
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 118 additions and 95 deletions

View file

@ -76,7 +76,7 @@ const endpoints = {
}, },
LoadSession: { LoadSession: {
url: "/order/api/v1/order/load-session", url: "/order/api/v1/order/load-session",
method: "POST", method: "GET",
}, },
ValidateZip: { ValidateZip: {
url: "/location/api/v1/location/zip", url: "/location/api/v1/location/zip",

View file

@ -21,6 +21,7 @@ export function updateOrCreateFunnelCookie() {
ReferralParentAccountNumber: store.getters.order.accountNumber, ReferralParentAccountNumber: store.getters.order.accountNumber,
HasDelayedClaimRegistration: wasClaimRegistrationDelayed, HasDelayedClaimRegistration: wasClaimRegistrationDelayed,
SuppressConceptFunnel: shouldSuppressConceptFunnel, SuppressConceptFunnel: shouldSuppressConceptFunnel,
SavedSessionId: store.getters.applicationUser.savedSessionId,
}); });
} }

View file

@ -17,12 +17,8 @@ import { storeMutations } from "@/constants/store-mutations";
export async function loadSessionIfPresent() { export async function loadSessionIfPresent() {
const funnelCookie = getFunnelCookie(); const funnelCookie = getFunnelCookie();
// Do nothing if there is no cookie, correlation id, or referral number. // Do nothing if there is no cookie or session to use for loading.
if ( if (funnelCookie == null || funnelCookie.SavedSessionId == null) {
funnelCookie == null ||
funnelCookie.ReferralCorrelationId == null ||
!funnelCookie.ReferralNumber
) {
return null; return null;
} }
@ -33,15 +29,8 @@ export async function loadSessionIfPresent() {
return null; return null;
} }
// Load referral if there is a cookie, and it doesn't indicate it needs a state reset. // Loads session including referral if there is a cookie, and it doesn't indicate it needs a state reset.
return ( return (await loadSession(funnelCookie.SavedSessionId)).data;
await loadSession(
funnelCookie.ReferralNumber,
funnelCookie.ReferralDate,
funnelCookie.ReferralCorrelationId,
funnelCookie.ReferralParentAccountNumber
)
).data;
} }
/* /*
@ -72,16 +61,13 @@ export async function saveSession() {
Calls API to load session given the referral number, referralDate, and referralCorrelationId Calls API to load session given the referral number, referralDate, and referralCorrelationId
and returns the response. and returns the response.
*/ */
async function loadSession(referralNumber, referralDate, referralCorrelationId, accountNumber) { async function loadSession(savedSessionId) {
// await the saveSessionPromise in the store to make sure we're loading up to date information // await the saveSessionPromise in the store to make sure we're loading up to date information
await store.getters.applicationUser.saveSessionPromise; await store.getters.applicationUser.saveSessionPromise;
const response = await baseMixin.methods.dispatchStoreAction( const response = await baseMixin.methods.dispatchStoreAction(
storeActions.LOAD_SESSION, storeActions.LOAD_SESSION,
{ {
referralNumber: referralNumber.toString(), savedSessionId: savedSessionId?.toString(),
referralDate: referralDate,
referralCorrelationId: referralCorrelationId,
accountNumber: accountNumber?.toString(),
}, },
false false
); );

View file

@ -24,6 +24,7 @@ describe("loadSessionIfPresent", () => {
ShouldResetState: testShouldResetState, ShouldResetState: testShouldResetState,
ReferralCorrelationId: "xxx", ReferralCorrelationId: "xxx",
ReferralNumber: "12345", ReferralNumber: "12345",
SavedSessionId: "aa115a05-e268-4eb4-a095-1d54b44f4a99",
}; };
document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}=${JSON.stringify( document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}=${JSON.stringify(
@ -46,6 +47,7 @@ describe("loadSessionIfPresent", () => {
ShouldResetState: true, ShouldResetState: true,
ReferralCorrelationId: "xxx-xxx-xxx", ReferralCorrelationId: "xxx-xxx-xxx",
ReferralNumber: "12345", ReferralNumber: "12345",
SavedSessionId: "aa115a05-e268-4eb4-a095-1d54b44f4a99",
}); });
const mockData = { const mockData = {
@ -103,6 +105,7 @@ describe("loadSessionIfPresent", () => {
ReferralNumber: 123456, ReferralNumber: 123456,
ReferralCorrelationId: "yyy-yyy-yyyy", ReferralCorrelationId: "yyy-yyy-yyyy",
ReferralDate: new Date(), ReferralDate: new Date(),
SavedSessionId: "aa115a05-e268-4eb4-a095-1d54b44f4a99",
}); });
const mockData = { const mockData = {

View file

@ -303,13 +303,13 @@ export const mutations = {
state.applicationUser.saveSessionPromise = null; state.applicationUser.saveSessionPromise = null;
}, },
// Misc Mutations // Misc Mutations
updateStateWithOrderInformation(state, orderInformation) { updateStateWithOrderInformation(state, sessionInformation) {
state.order.referralNumber = orderInformation.referralNumber; state.order.referralNumber = sessionInformation.order.referralNumber;
state.order.referralDate = orderInformation.referralDate; state.order.referralDate = sessionInformation.order.referralDate;
state.order.referralCorrelationId = orderInformation.referralCorrelationId; state.order.referralCorrelationId = sessionInformation.order.referralCorrelationId;
state.order.eon = orderInformation.eon; state.order.eon = sessionInformation.order.eon;
if (state.order.vehicle.vin !== orderInformation.vehicle?.vin) { if (state.order.vehicle.vin !== sessionInformation.order.vehicle?.vin) {
state.applicationUser.pageData[fmgPageValues.PART_QUESTIONS] = null; state.applicationUser.pageData[fmgPageValues.PART_QUESTIONS] = null;
state.applicationUser.pageData[fmgPageValues.VEHICLE_PARTS] = null; state.applicationUser.pageData[fmgPageValues.VEHICLE_PARTS] = null;
state.applicationUser.pageData[fmgPageValues.MOLDING_QUESTIONS] = null; state.applicationUser.pageData[fmgPageValues.MOLDING_QUESTIONS] = null;
@ -317,44 +317,51 @@ export const mutations = {
} }
state.order.vehicle = Object.assign(state.order.vehicle, { state.order.vehicle = Object.assign(state.order.vehicle, {
year: orderInformation.vehicle?.year, year: sessionInformation.order.vehicle?.year,
make: orderInformation.vehicle?.make, make: sessionInformation.order.vehicle?.make,
model: orderInformation.vehicle?.model, model: sessionInformation.order.vehicle?.model,
style: orderInformation.vehicle?.style, style: sessionInformation.order.vehicle?.style,
vin: orderInformation.vehicle?.vin, vin: sessionInformation.order.vehicle?.vin,
carId: orderInformation.vehicle?.carId, carId: sessionInformation.order.vehicle?.carId,
category: orderInformation.vehicle?.category, category: sessionInformation.order.vehicle?.category,
imageUrl: orderInformation.vehicle?.imageUrl, imageUrl: sessionInformation.order.vehicle?.imageUrl,
imageVifNumber: orderInformation.vehicle?.imageVifNumber, imageVifNumber: sessionInformation.order.vehicle?.imageVifNumber,
imageColor: orderInformation.vehicle?.imageVifColor, imageColor: sessionInformation.order.vehicle?.imageVifColor,
registration: { registration: {
firstName: orderInformation.vehicle.registration.firstName, firstName: sessionInformation.order.vehicle.registration.firstName,
lastName: orderInformation.vehicle.registration.lastName, lastName: sessionInformation.order.vehicle.registration.lastName,
address: orderInformation.vehicle.registration.streetAddress, address: sessionInformation.order.vehicle.registration.streetAddress,
city: orderInformation.vehicle.registration.city, city: sessionInformation.order.vehicle.registration.city,
state: orderInformation.vehicle.registration.state, state: sessionInformation.order.vehicle.registration.state,
zipCode: orderInformation.vehicle.registration.zipCode, zipCode: sessionInformation.order.vehicle.registration.zipCode,
licensePlate: orderInformation.vehicle.registration.licensePlateNumber, licensePlate: sessionInformation.order.vehicle.registration.licensePlateNumber,
}, },
}); });
state.order.damage.glassToReplace = orderInformation.damage.glassToReplace; state.order.damage.glassToReplace = sessionInformation.order.damage.glassToReplace;
state.order.damage.isRepair = orderInformation.damage.isRepair; state.order.damage.isRepair = sessionInformation.order.damage.isRepair;
state.order.damage.numberOfChips = orderInformation.damage.numberOfChips; state.order.damage.numberOfChips = sessionInformation.order.damage.numberOfChips;
state.order.lineItems.glassParts = orderInformation.parts; state.order.lineItems.glassParts = sessionInformation.order.lineItems.parts;
state.order.accountNumber = orderInformation.accountNumber; state.order.accountNumber = sessionInformation.order.accountNumber;
(state.order.serviceLocation.address = orderInformation.serviceLocation.streetAddress), state.order.providerNumber = sessionInformation.order.providerNumber;
(state.order.serviceLocation.city = orderInformation.serviceLocation.city), (state.order.serviceLocation.address =
(state.order.serviceLocation.state = orderInformation.serviceLocation.state), sessionInformation.order.serviceLocation.streetAddress),
(state.order.serviceLocation.zipCode = orderInformation.serviceLocation.zipCode); (state.order.serviceLocation.city = sessionInformation.order.serviceLocation.city),
(state.order.serviceLocation.state = sessionInformation.order.serviceLocation.state),
(state.order.serviceLocation.zipCode =
sessionInformation.order.serviceLocation.zipCode);
state.order.payment.isInsurance = orderInformation.IsInsuranceOrder; state.order.payment.isInsurance = sessionInformation.order.payment.isInsurance;
state.order.payment.insuranceCoverage.isVerified = state.order.payment.insuranceCoverage.isVerified =
orderInformation?.insuranceInfo.coverageVerified; sessionInformation?.order.payment.insuranceCoverage.isVerified;
state.order.customer.emailAddress = orderInformation.customer.emailAddress; state.order.customer.emailAddress = sessionInformation.order.customer.emailAddress;
state.applicationUser.experiments = orderInformation.experiments; state.order.existingPromoCode = sessionInformation.order.existingPromoCode;
state.applicationUser.experiments = sessionInformation.applicationUser.experiments;
state.applicationUser.crmCustomerId = sessionInformation.applicationUser.crmCustomerId;
state.applicationUser.pageData = sessionInformation.applicationUser.pageData;
state.applicationUser.lastPage = sessionInformation.applicationUser.lastPage;
}, },
updateExperiments(state, experiments) { updateExperiments(state, experiments) {
state.applicationUser.experiments = experiments; state.applicationUser.experiments = experiments;
@ -984,17 +991,12 @@ export const actions = {
}, },
}); });
}, },
loadSession(context, { referralNumber, referralDate, referralCorrelationId, accountNumber }) { loadSession(context, { savedSessionId }) {
return globalMethods return globalMethods
.callHttpClient({ .callHttpClient({
method: endpoints.LoadSession.method, method: endpoints.LoadSession.method,
endpoint: endpoints.LoadSession.url, endpoint:
payload: { endpoints.LoadSession.url + "?savedSessionId=" + savedSessionId?.toString(),
referralNumber: referralNumber?.toString(),
referralDate: referralDate,
referralCorrelationId: referralCorrelationId,
accountNumber: accountNumber?.toString(),
},
}) })
.then((response) => { .then((response) => {
// Flatten location and name properties // Flatten location and name properties
@ -1409,6 +1411,12 @@ function sortArrayOfObjectsByPropertyValue(arrayOfObjects, propertyName) {
function convertGlassPieceNamingForApi(glassArray) { function convertGlassPieceNamingForApi(glassArray) {
if (!glassArray) return []; if (!glassArray) return [];
// check if array already converted. (likely when a session has been saved previously and then reloaded)
if (glassArray[0].location !== undefined) {
return glassArray;
}
const converted = []; const converted = [];
glassArray.forEach((glass) => { glassArray.forEach((glass) => {
converted.push({ converted.push({

View file

@ -203,34 +203,65 @@ describe("Mutations", () => {
expect(storeState.applicationUser.pageData["vehicle-year"]).toEqual({}); expect(storeState.applicationUser.pageData["vehicle-year"]).toEqual({});
}); });
it("updateStateWithOrderInformation, should set order information in state", () => { it("updateStateWithSessonInformation, should set session information in state", () => {
// Arrange // Arrange
const storeState = state; const storeState = state;
// Act // Act
mutations.updateStateWithOrderInformation(storeState, { mutations.updateStateWithOrderInformation(storeState, {
referralNumber: 123, order: {
referralDate: new Date().toUTCString(), referralNumber: 123,
referralCorrelationId: "xxx-xxx-xxx", referralDate: new Date().toUTCString(),
vehicle: { referralCorrelationId: "xxx-xxx-xxx",
year: "2019", vehicle: {
make: "Acura", year: "2019",
model: "ILX", make: "Acura",
style: "4 DOOR SEDAN", model: "ILX",
carId: "C0000001", style: "4 DOOR SEDAN",
category: "CAR", carId: "C0000001",
registration: {}, category: "CAR",
registration: {},
},
damage: {
glassToReplace: ["Windshield"],
isRepair: false,
numberOfChips: 0,
},
lineItems: {
glassParts: null,
},
payment: {
insuranceCoverage: {
isVerified: false,
},
isInsurance: false,
},
parts: [],
accountNumber: "123456789",
insuranceInfo: {},
serviceLocation: {},
customer: {},
}, },
damage: { applicationUser: {
glassToReplace: ["Windshield"], experiments: [
isRepair: false, {
numberOfChips: 0, 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",
},
},
],
}, },
parts: [],
accountNumber: "123456789",
insuranceInfo: {},
serviceLocation: {},
customer: {},
}); });
// Assert // Assert
@ -640,9 +671,7 @@ describe("Actions", () => {
// Act // Act
const response = await actions.loadSession(context, { const response = await actions.loadSession(context, {
referralNumber: "123", savedSessionId: "",
referralDate: new Date().toUTCString(),
referralCorrelationId: "xxx-xxx-xxx",
}); });
// Assert // Assert
@ -667,9 +696,7 @@ describe("Actions", () => {
// Act // Act
const response = await actions.loadSession(context, { const response = await actions.loadSession(context, {
referralNumber: "123", savedSessionId: "",
referralDate: new Date().toUTCString(),
referralCorrelationId: "xxx-xxx-xxx",
}); });
// Assert // Assert
@ -694,9 +721,7 @@ describe("Actions", () => {
// Act // Act
const response = await actions.loadSession(context, { const response = await actions.loadSession(context, {
referralNumber: "123", savedSessionId: "",
referralDate: new Date().toUTCString(),
referralCorrelationId: "xxx-xxx-xxx",
}); });
// Assert // Assert