CSR-777 load session
This commit is contained in:
parent
18eb258240
commit
65207726cd
6 changed files with 120 additions and 96 deletions
|
|
@ -76,7 +76,7 @@ const endpoints = {
|
|||
},
|
||||
LoadSession: {
|
||||
url: "/order/api/v1/order/load-session",
|
||||
method: "POST",
|
||||
method: "GET",
|
||||
},
|
||||
ValidateZip: {
|
||||
url: "/location/api/v1/location/zip",
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ export function updateOrCreateFunnelCookie() {
|
|||
ReferralParentAccountNumber: store.getters.order.accountNumber,
|
||||
HasDelayedClaimRegistration: wasClaimRegistrationDelayed,
|
||||
SuppressConceptFunnel: shouldSuppressConceptFunnel,
|
||||
SavedSessionId: store.getters.applicationUser.savedSessionId,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,12 +17,8 @@ import { storeMutations } from "@/constants/store-mutations";
|
|||
export async function loadSessionIfPresent() {
|
||||
const funnelCookie = getFunnelCookie();
|
||||
|
||||
// Do nothing if there is no cookie, correlation id, or referral number.
|
||||
if (
|
||||
funnelCookie == null ||
|
||||
funnelCookie.ReferralCorrelationId == null ||
|
||||
!funnelCookie.ReferralNumber
|
||||
) {
|
||||
// Do nothing if there is no cookie or session to use for loading.
|
||||
if (funnelCookie == null || funnelCookie.SavedSessionId == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -33,15 +29,8 @@ export async function loadSessionIfPresent() {
|
|||
return null;
|
||||
}
|
||||
|
||||
// Load referral if there is a cookie, and it doesn't indicate it needs a state reset.
|
||||
return (
|
||||
await loadSession(
|
||||
funnelCookie.ReferralNumber,
|
||||
funnelCookie.ReferralDate,
|
||||
funnelCookie.ReferralCorrelationId,
|
||||
funnelCookie.ReferralParentAccountNumber
|
||||
)
|
||||
).data;
|
||||
// Loads session including referral if there is a cookie, and it doesn't indicate it needs a state reset.
|
||||
return (await loadSession(funnelCookie.SavedSessionId)).data;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -72,16 +61,13 @@ export async function saveSession() {
|
|||
Calls API to load session given the referral number, referralDate, and referralCorrelationId
|
||||
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 store.getters.applicationUser.saveSessionPromise;
|
||||
const response = await baseMixin.methods.dispatchStoreAction(
|
||||
storeActions.LOAD_SESSION,
|
||||
{
|
||||
referralNumber: referralNumber.toString(),
|
||||
referralDate: referralDate,
|
||||
referralCorrelationId: referralCorrelationId,
|
||||
accountNumber: accountNumber?.toString(),
|
||||
savedSessionId: savedSessionId?.toString(),
|
||||
},
|
||||
false
|
||||
);
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ describe("loadSessionIfPresent", () => {
|
|||
ShouldResetState: testShouldResetState,
|
||||
ReferralCorrelationId: "xxx",
|
||||
ReferralNumber: "12345",
|
||||
SavedSessionId: "aa115a05-e268-4eb4-a095-1d54b44f4a99"
|
||||
};
|
||||
|
||||
document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}=${JSON.stringify(
|
||||
|
|
@ -46,6 +47,7 @@ describe("loadSessionIfPresent", () => {
|
|||
ShouldResetState: true,
|
||||
ReferralCorrelationId: "xxx-xxx-xxx",
|
||||
ReferralNumber: "12345",
|
||||
SavedSessionId: "aa115a05-e268-4eb4-a095-1d54b44f4a99"
|
||||
});
|
||||
|
||||
const mockData = {
|
||||
|
|
@ -103,6 +105,7 @@ describe("loadSessionIfPresent", () => {
|
|||
ReferralNumber: 123456,
|
||||
ReferralCorrelationId: "yyy-yyy-yyyy",
|
||||
ReferralDate: new Date(),
|
||||
SavedSessionId: "aa115a05-e268-4eb4-a095-1d54b44f4a99"
|
||||
});
|
||||
|
||||
const mockData = {
|
||||
|
|
|
|||
|
|
@ -303,13 +303,13 @@ export const mutations = {
|
|||
state.applicationUser.saveSessionPromise = null;
|
||||
},
|
||||
// Misc Mutations
|
||||
updateStateWithOrderInformation(state, orderInformation) {
|
||||
state.order.referralNumber = orderInformation.referralNumber;
|
||||
state.order.referralDate = orderInformation.referralDate;
|
||||
state.order.referralCorrelationId = orderInformation.referralCorrelationId;
|
||||
state.order.eon = orderInformation.eon;
|
||||
updateStateWithOrderInformation(state, sessionInformation) {
|
||||
state.order.referralNumber = sessionInformation.order.referralNumber;
|
||||
state.order.referralDate = sessionInformation.order.referralDate;
|
||||
state.order.referralCorrelationId = sessionInformation.order.referralCorrelationId;
|
||||
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.VEHICLE_PARTS] = null;
|
||||
state.applicationUser.pageData[fmgPageValues.MOLDING_QUESTIONS] = null;
|
||||
|
|
@ -317,44 +317,52 @@ export const mutations = {
|
|||
}
|
||||
|
||||
state.order.vehicle = Object.assign(state.order.vehicle, {
|
||||
year: orderInformation.vehicle?.year,
|
||||
make: orderInformation.vehicle?.make,
|
||||
model: orderInformation.vehicle?.model,
|
||||
style: orderInformation.vehicle?.style,
|
||||
vin: orderInformation.vehicle?.vin,
|
||||
carId: orderInformation.vehicle?.carId,
|
||||
category: orderInformation.vehicle?.category,
|
||||
imageUrl: orderInformation.vehicle?.imageUrl,
|
||||
imageVifNumber: orderInformation.vehicle?.imageVifNumber,
|
||||
imageColor: orderInformation.vehicle?.imageVifColor,
|
||||
year: sessionInformation.order.vehicle?.year,
|
||||
make: sessionInformation.order.vehicle?.make,
|
||||
model: sessionInformation.order.vehicle?.model,
|
||||
style: sessionInformation.order.vehicle?.style,
|
||||
vin: sessionInformation.order.vehicle?.vin,
|
||||
carId: sessionInformation.order.vehicle?.carId,
|
||||
category: sessionInformation.order.vehicle?.category,
|
||||
imageUrl: sessionInformation.order.vehicle?.imageUrl,
|
||||
imageVifNumber: sessionInformation.order.vehicle?.imageVifNumber,
|
||||
imageColor: sessionInformation.order.vehicle?.imageVifColor,
|
||||
registration: {
|
||||
firstName: orderInformation.vehicle.registration.firstName,
|
||||
lastName: orderInformation.vehicle.registration.lastName,
|
||||
address: orderInformation.vehicle.registration.streetAddress,
|
||||
city: orderInformation.vehicle.registration.city,
|
||||
state: orderInformation.vehicle.registration.state,
|
||||
zipCode: orderInformation.vehicle.registration.zipCode,
|
||||
licensePlate: orderInformation.vehicle.registration.licensePlateNumber,
|
||||
firstName: sessionInformation.order.vehicle.registration.firstName,
|
||||
lastName: sessionInformation.order.vehicle.registration.lastName,
|
||||
address: sessionInformation.order.vehicle.registration.streetAddress,
|
||||
city: sessionInformation.order.vehicle.registration.city,
|
||||
state: sessionInformation.order.vehicle.registration.state,
|
||||
zipCode: sessionInformation.order.vehicle.registration.zipCode,
|
||||
licensePlate: sessionInformation.order.vehicle.registration.licensePlateNumber,
|
||||
},
|
||||
});
|
||||
|
||||
state.order.damage.glassToReplace = orderInformation.damage.glassToReplace;
|
||||
state.order.damage.isRepair = orderInformation.damage.isRepair;
|
||||
state.order.damage.numberOfChips = orderInformation.damage.numberOfChips;
|
||||
state.order.damage.glassToReplace = sessionInformation.order.damage.glassToReplace;
|
||||
state.order.damage.isRepair = sessionInformation.order.damage.isRepair;
|
||||
state.order.damage.numberOfChips = sessionInformation.order.damage.numberOfChips;
|
||||
|
||||
state.order.lineItems.glassParts = orderInformation.parts;
|
||||
state.order.accountNumber = orderInformation.accountNumber;
|
||||
(state.order.serviceLocation.address = orderInformation.serviceLocation.streetAddress),
|
||||
(state.order.serviceLocation.city = orderInformation.serviceLocation.city),
|
||||
(state.order.serviceLocation.state = orderInformation.serviceLocation.state),
|
||||
(state.order.serviceLocation.zipCode = orderInformation.serviceLocation.zipCode);
|
||||
state.order.lineItems.glassParts = sessionInformation.order.lineItems.parts;
|
||||
state.order.accountNumber = sessionInformation.order.accountNumber;
|
||||
state.order.providerNumber = sessionInformation.order.providerNumber;
|
||||
(state.order.serviceLocation.address =
|
||||
sessionInformation.order.serviceLocation.streetAddress),
|
||||
(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 =
|
||||
orderInformation?.insuranceInfo.coverageVerified;
|
||||
sessionInformation?.order.payment.insuranceCoverage.isVerified;
|
||||
|
||||
state.order.customer.emailAddress = sessionInformation.order.customer.emailAddress;
|
||||
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;
|
||||
|
||||
state.order.customer.emailAddress = orderInformation.customer.emailAddress;
|
||||
state.applicationUser.experiments = orderInformation.experiments;
|
||||
},
|
||||
updateExperiments(state, experiments) {
|
||||
state.applicationUser.experiments = experiments;
|
||||
|
|
@ -984,17 +992,12 @@ export const actions = {
|
|||
},
|
||||
});
|
||||
},
|
||||
loadSession(context, { referralNumber, referralDate, referralCorrelationId, accountNumber }) {
|
||||
loadSession(context, { savedSessionId }) {
|
||||
return globalMethods
|
||||
.callHttpClient({
|
||||
method: endpoints.LoadSession.method,
|
||||
endpoint: endpoints.LoadSession.url,
|
||||
payload: {
|
||||
referralNumber: referralNumber?.toString(),
|
||||
referralDate: referralDate,
|
||||
referralCorrelationId: referralCorrelationId,
|
||||
accountNumber: accountNumber?.toString(),
|
||||
},
|
||||
endpoint:
|
||||
endpoints.LoadSession.url + "?savedSessionId=" + savedSessionId?.toString(),
|
||||
})
|
||||
.then((response) => {
|
||||
// Flatten location and name properties
|
||||
|
|
@ -1409,6 +1412,12 @@ function sortArrayOfObjectsByPropertyValue(arrayOfObjects, propertyName) {
|
|||
|
||||
function convertGlassPieceNamingForApi(glassArray) {
|
||||
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 = [];
|
||||
glassArray.forEach((glass) => {
|
||||
converted.push({
|
||||
|
|
|
|||
|
|
@ -203,34 +203,65 @@ describe("Mutations", () => {
|
|||
expect(storeState.applicationUser.pageData["vehicle-year"]).toEqual({});
|
||||
});
|
||||
|
||||
it("updateStateWithOrderInformation, should set order information in state", () => {
|
||||
it("updateStateWithSessonInformation, should set session information in state", () => {
|
||||
// Arrange
|
||||
const storeState = state;
|
||||
|
||||
// Act
|
||||
mutations.updateStateWithOrderInformation(storeState, {
|
||||
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: {},
|
||||
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: {},
|
||||
},
|
||||
damage: {
|
||||
glassToReplace: ["Windshield"],
|
||||
isRepair: false,
|
||||
numberOfChips: 0,
|
||||
},
|
||||
lineItems: {
|
||||
"glassParts": null
|
||||
},
|
||||
payment: {
|
||||
"insuranceCoverage": {
|
||||
"isVerified": false
|
||||
},
|
||||
"isInsurance": false
|
||||
},
|
||||
parts: [],
|
||||
accountNumber: "123456789",
|
||||
insuranceInfo: {},
|
||||
serviceLocation: {},
|
||||
customer: {},
|
||||
},
|
||||
damage: {
|
||||
glassToReplace: ["Windshield"],
|
||||
isRepair: false,
|
||||
numberOfChips: 0,
|
||||
},
|
||||
parts: [],
|
||||
accountNumber: "123456789",
|
||||
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
|
||||
|
|
@ -640,9 +671,7 @@ describe("Actions", () => {
|
|||
|
||||
// Act
|
||||
const response = await actions.loadSession(context, {
|
||||
referralNumber: "123",
|
||||
referralDate: new Date().toUTCString(),
|
||||
referralCorrelationId: "xxx-xxx-xxx",
|
||||
savedSessionId: "",
|
||||
});
|
||||
|
||||
// Assert
|
||||
|
|
@ -667,9 +696,7 @@ describe("Actions", () => {
|
|||
|
||||
// Act
|
||||
const response = await actions.loadSession(context, {
|
||||
referralNumber: "123",
|
||||
referralDate: new Date().toUTCString(),
|
||||
referralCorrelationId: "xxx-xxx-xxx",
|
||||
savedSessionId: "",
|
||||
});
|
||||
|
||||
// Assert
|
||||
|
|
@ -694,9 +721,7 @@ describe("Actions", () => {
|
|||
|
||||
// Act
|
||||
const response = await actions.loadSession(context, {
|
||||
referralNumber: "123",
|
||||
referralDate: new Date().toUTCString(),
|
||||
referralCorrelationId: "xxx-xxx-xxx",
|
||||
savedSessionId: "",
|
||||
});
|
||||
|
||||
// Assert
|
||||
|
|
|
|||
Loading…
Reference in a new issue