Save/Load Session

This commit is contained in:
Chloe Herd 2023-09-20 11:16:45 -04:00
parent 5c38498a23
commit fed47a13e9
10 changed files with 62 additions and 32 deletions

View file

@ -45,10 +45,10 @@ export async function getPageToRouteExistingOrderTo(toRoute = {}) {
Used to navigate to the heritage funnel with the correct query string and url. Used to navigate to the heritage funnel with the correct query string and url.
*/ */
export async function navigateToHeritageFunnel({ shouldSaveSession, loadingModal }) { export async function navigateToHeritageFunnel({ shouldSaveSession, pageNameToLog, loadingModal }) {
// Create the order (or save existing order) when navigating to Heritage Funnel. // Create the order (or save existing order) when navigating to Heritage Funnel.
if (shouldSaveSession) { if (shouldSaveSession) {
await saveSession({ shouldAwaitSaveSessionQueue: true }); await saveSession({ pageNameToLog: pageNameToLog, shouldAwaitSaveSessionQueue: true });
} }
if (loadingModal && loadingModal.showModal) { if (loadingModal && loadingModal.showModal) {

View file

@ -14,7 +14,7 @@ import { storeMutations } from "@/constants/store-mutations";
it will reset the state and go back to the start of the funnel. it will reset the state and go back to the start of the funnel.
*/ */
export async function loadSessionIfPresent(isConceptInsurance) { export async function loadSessionIfPresent(isConceptInsurance, pageNameToLog) {
const funnelCookie = getFunnelCookie(); const funnelCookie = getFunnelCookie();
// Do nothing if there is no cookie or session to use for loading. // Do nothing if there is no cookie or session to use for loading.
@ -42,7 +42,8 @@ export async function loadSessionIfPresent(isConceptInsurance) {
funnelCookie.ReferralDate, funnelCookie.ReferralDate,
funnelCookie.ReferralParentAccountNumber, funnelCookie.ReferralParentAccountNumber,
funnelCookie.ReferralCorrelationId, funnelCookie.ReferralCorrelationId,
isConceptInsurance isConceptInsurance,
pageNameToLog
) )
)?.data; )?.data;
} }
@ -52,17 +53,17 @@ export async function loadSessionIfPresent(isConceptInsurance) {
This will also set Referral information in the store after saving, and then This will also set Referral information in the store after saving, and then
update the cookie. To force synchronous behavior pass in 'true' for shouldAwaitSaveSessionQueue update the cookie. To force synchronous behavior pass in 'true' for shouldAwaitSaveSessionQueue
*/ */
export async function saveSession({ shouldAwaitSaveSessionQueue = false }) { export async function saveSession({ pageNameToLog, shouldAwaitSaveSessionQueue = false }) {
var saveSessionPromise; var saveSessionPromise;
if (store.getters.applicationUser.saveSessionPromise) { if (store.getters.applicationUser.saveSessionPromise) {
// queue newest request after current saveSessionPromise resolves // queue newest request after current saveSessionPromise resolves
saveSessionPromise = store.getters.applicationUser.saveSessionPromise.then(() => { saveSessionPromise = store.getters.applicationUser.saveSessionPromise.then(() => {
// get a new saveSessionPromise // get a new saveSessionPromise
return saveSessionHelper(); return saveSessionHelper(pageNameToLog);
}); });
} else { } else {
// create an initial saveSessionPromise // create an initial saveSessionPromise
saveSessionPromise = saveSessionHelper(); saveSessionPromise = saveSessionHelper(pageNameToLog);
} }
store.commit(storeMutations.UPDATE_SAVE_SESSION_PROMISE, saveSessionPromise); store.commit(storeMutations.UPDATE_SAVE_SESSION_PROMISE, saveSessionPromise);
// await here to allow for a caller to await and make the function synchronous // await here to allow for a caller to await and make the function synchronous
@ -83,12 +84,13 @@ async function loadSession(
referralDate, referralDate,
parentAccountNumber, parentAccountNumber,
referralCorrelationId, referralCorrelationId,
isConceptInsurance isConceptInsurance,
pageNameToLog
) { ) {
// 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.dispatchStoreActionWithLogging(
storeActions.LOAD_SESSION, storeActions.LOAD_SESSION,
{ {
savedSessionId: savedSessionId?.toString(), savedSessionId: savedSessionId?.toString(),
@ -98,6 +100,7 @@ async function loadSession(
parentAccountNumber, parentAccountNumber,
isConceptInsurance, isConceptInsurance,
}, },
pageNameToLog,
false false
); );
@ -107,8 +110,12 @@ async function loadSession(
/* /*
Encapsulates asynchronous Save Session logic inside a promise to allow for Save Session queuing Encapsulates asynchronous Save Session logic inside a promise to allow for Save Session queuing
*/ */
async function saveSessionHelper() { async function saveSessionHelper(pageNameToLog) {
const savedSessionInfo = await baseMixin.methods.dispatchStoreAction(storeActions.SAVE_SESSION); const savedSessionInfo = await baseMixin.methods.dispatchStoreActionWithLogging(
storeActions.SAVE_SESSION,
null,
pageNameToLog
);
// Update the store with information received from the saveSession response // Update the store with information received from the saveSession response
await baseMixin.methods.dispatchStoreAction( await baseMixin.methods.dispatchStoreAction(
storeActions.UPDATE_STORE_WITH_SAVE_SESSION_RESPONSE, storeActions.UPDATE_STORE_WITH_SAVE_SESSION_RESPONSE,

View file

@ -170,11 +170,13 @@ describe("saveSession", () => {
const mocks = setupMocksForJsFiles(mockData); const mocks = setupMocksForJsFiles(mockData);
// Act // Act
await saveSession({}); await saveSession({ pageNameToLog: "test" });
// Assert // Assert
expect(mocks.baseMixin.methods.dispatchStoreAction).toHaveBeenCalledWith( expect(mocks.baseMixin.methods.dispatchStoreActionWithLogging).toHaveBeenCalledWith(
storeActions.SAVE_SESSION storeActions.SAVE_SESSION,
null,
"test"
); );
expect(mocks.baseMixin.methods.dispatchStoreAction).toHaveBeenCalledWith( expect(mocks.baseMixin.methods.dispatchStoreAction).toHaveBeenCalledWith(
storeActions.UPDATE_STORE_WITH_SAVE_SESSION_RESPONSE, storeActions.UPDATE_STORE_WITH_SAVE_SESSION_RESPONSE,
@ -231,7 +233,7 @@ describe("saveSession", () => {
setupCookies({ funnelCookieValue: JSON.stringify(testCookieValue) }); setupCookies({ funnelCookieValue: JSON.stringify(testCookieValue) });
// Act // Act
await saveSession({}); await saveSession({ pageNameToLog: "test" });
// Assert // Assert
expect(cookieHelper.getFunnelCookie().DidHeritageFunnelUpdateLast).toEqual(false); expect(cookieHelper.getFunnelCookie().DidHeritageFunnelUpdateLast).toEqual(false);

View file

@ -260,6 +260,7 @@ export default {
if (vehicleChangedDuringPolicyLookupInHeritage) { if (vehicleChangedDuringPolicyLookupInHeritage) {
navigateToHeritageFunnel({ navigateToHeritageFunnel({
shouldSaveSession: true, shouldSaveSession: true,
pageNameToLog: "estimate",
loadingModal: this.$refs.loadingModal, loadingModal: this.$refs.loadingModal,
}); });
} else if (this.$store.getters.order.referralNumber?.length === 6) { } else if (this.$store.getters.order.referralNumber?.length === 6) {
@ -287,7 +288,7 @@ export default {
); );
// call saveSession here - navigateWithSaving saves too late in the flow // call saveSession here - navigateWithSaving saves too late in the flow
await saveSession({}); await saveSession({ pageNameToLog: "estimate" });
return this.$router.navigateWithSaving( return this.$router.navigateWithSaving(
this.navigationScenarios.CLICKED_FORWARD_WITH_NO_QUESTIONS, this.navigationScenarios.CLICKED_FORWARD_WITH_NO_QUESTIONS,
this.$route this.$route

View file

@ -236,6 +236,7 @@ export default {
if (payment.isInsurance) { if (payment.isInsurance) {
navigateToHeritageFunnel({ navigateToHeritageFunnel({
shouldSaveSession: true, shouldSaveSession: true,
pageNameToLog: "quote",
loadingModal: this.$refs.loadingModal, loadingModal: this.$refs.loadingModal,
}); });
} else { } else {

View file

@ -449,11 +449,13 @@ export default {
if (store.getters.order.referralNumber?.length === 6) { if (store.getters.order.referralNumber?.length === 6) {
navigateToHeritageFunnel({ navigateToHeritageFunnel({
shouldSaveSession: true, shouldSaveSession: true,
pageNameToLog: this.$options.name,
loadingModal: self.$refs.loadingModal, loadingModal: self.$refs.loadingModal,
}); });
} else if (payment.isInsurance && payment.insuranceCoverage.isVerified) { } else if (payment.isInsurance && payment.insuranceCoverage.isVerified) {
navigateToHeritageFunnel({ navigateToHeritageFunnel({
shouldSaveSession: true, shouldSaveSession: true,
pageNameToLog: this.$options.name,
loadingModal: self.$refs.loadingModal, loadingModal: self.$refs.loadingModal,
}); });
} else { } else {

View file

@ -6,13 +6,13 @@ import { saveSession } from "@/helpers/heritage-integration/order-helper.js";
export default { export default {
methods: { methods: {
async navigateForwardWithSingleCarMatch() { async navigateForwardWithSingleCarMatch() {
const pageName = this.$options?.name;
// If we have not already saved a session, we need to save one now before the lengthy call to getPartsOrQuestions // If we have not already saved a session, we need to save one now before the lengthy call to getPartsOrQuestions
if (!store.getters.applicationUser.savedSessionId) { if (!store.getters.applicationUser.savedSessionId) {
await saveSession({}); await saveSession({ pageNameToLog: pageName });
} }
const pageName = this.$options?.name;
const result = await this.dispatchStoreAction(storeActions.GET_PARTS_OR_QUESTIONS, { const result = await this.dispatchStoreAction(storeActions.GET_PARTS_OR_QUESTIONS, {
pageNameToLog: pageName, pageNameToLog: pageName,
}); });

View file

@ -72,7 +72,8 @@ const routes = [
? to.query.isInsurance == "true" ? to.query.isInsurance == "true"
? true ? true
: false : false
: null : null,
to.query.fmgPage
); );
const pageToRedirectTo = await getPageToRouteExistingOrderTo(to); const pageToRedirectTo = await getPageToRouteExistingOrderTo(to);
@ -172,7 +173,7 @@ router.afterEach(async (to, from) => {
store.getters.applicationUser.savedSessionId || store.getters.applicationUser.savedSessionId ||
store.getters.order.customer?.emailAddress store.getters.order.customer?.emailAddress
) { ) {
await saveSession({}); await saveSession({ pageNameToLog: to.query.fmgPage });
} }
} }

View file

@ -1460,7 +1460,7 @@ export const actions = {
}, },
// Session API Actions // Session API Actions
saveSession(context) { saveSession(context, { pageNameToLog }) {
const vehicle = context.getters.vehicle; const vehicle = context.getters.vehicle;
const damage = context.getters.damage; const damage = context.getters.damage;
const order = context.state.order; const order = context.state.order;
@ -1566,6 +1566,8 @@ export const actions = {
eon: order.eon, eon: order.eon,
}, },
}, },
logApiCall: true,
pageNameToLog: pageNameToLog,
additionalSuccessEventDataHandler: (response) => additionalSuccessEventDataHandler: (response) =>
"Email provided: " + (order.customer.emailAddress ? "true" : "false"), "Email provided: " + (order.customer.emailAddress ? "true" : "false"),
}); });
@ -1574,12 +1576,15 @@ export const actions = {
loadSession( loadSession(
context, context,
{ {
savedSessionId, payload: {
referralNumber, savedSessionId,
referralDate, referralNumber,
parentAccountNumber, referralDate,
referralCorrelationId, parentAccountNumber,
isConceptInsurance, referralCorrelationId,
isConceptInsurance,
},
pageNameToLog,
} }
) { ) {
const order = context.state.order; const order = context.state.order;
@ -1595,6 +1600,8 @@ export const actions = {
parentAccountNumber: parentAccountNumber, parentAccountNumber: parentAccountNumber,
referralCorrelationId: referralCorrelationId, referralCorrelationId: referralCorrelationId,
}, },
logApiCall: true,
pageNameToLog: pageNameToLog,
}) })
.then( .then(
async (response) => { async (response) => {

View file

@ -763,7 +763,7 @@ describe("Actions", () => {
}); });
// Act // Act
const response = await actions.saveSession(context); const response = await actions.saveSession(context, { pageNameToLog: "test" });
// Assert // Assert
expect(response.data).toEqual({ referralNumber: 123 }); expect(response.data).toEqual({ referralNumber: 123 });
@ -783,7 +783,10 @@ describe("Actions", () => {
// Act // Act
const response = await actions.loadSession(context, { const response = await actions.loadSession(context, {
savedSessionId: "", payload: {
savedSessionId: "",
},
pageNameToLog: "test",
}); });
// Assert // Assert
@ -809,7 +812,10 @@ describe("Actions", () => {
// Act // Act
const response = await actions.loadSession(context, { const response = await actions.loadSession(context, {
savedSessionId: "", payload: {
savedSessionId: "",
},
pageNameToLog: "test",
}); });
// Assert // Assert
@ -834,7 +840,10 @@ describe("Actions", () => {
// Act // Act
const response = await actions.loadSession(context, { const response = await actions.loadSession(context, {
savedSessionId: "", payload: {
savedSessionId: "",
},
pageNameToLog: "test",
}); });
// Assert // Assert