CSR-1055 | Defer most await scenarios to saveSession call

This commit is contained in:
Scott Kiener 2023-01-16 12:09:50 -05:00
parent 2264acbdff
commit 941097a407
6 changed files with 13 additions and 11 deletions

View file

@ -46,7 +46,7 @@ export async function getPageToRouteExistingOrderTo(toRoute = {}, existingHerita
export async function navigateToHeritageFunnel({ shouldSaveSession = true, loadingModal }) {
// Create the order (or save existing order) when navigating to Heritage Funnel.
if (shouldSaveSession) {
await saveSession();
await saveSession({ shouldAwaitSaveSessionQueue: true });
}
if (loadingModal && loadingModal.showModal) {

View file

@ -50,9 +50,9 @@ export async function loadSessionIfPresent(isConceptInsurance) {
/*
Will call API to save existing order, or create new one depending where it's called from.
This will also set Referral information in the store after saving, and then
update the cookie.
update the cookie. To force synchronous behavior pass in 'true' for shouldAwaitSaveSessionQueue
*/
export async function saveSession() {
export async function saveSession({ shouldAwaitSaveSessionQueue = false }) {
var saveSessionPromise;
if (store.getters.applicationUser.saveSessionPromise) {
// queue newest request after current saveSessionPromise resolves
@ -66,7 +66,9 @@ export async function saveSession() {
}
store.commit(storeMutations.UPDATE_SAVE_SESSION_PROMISE, saveSessionPromise);
// await here to allow for a caller to await and make the function synchronous
await saveSessionPromise;
if (!store.getters.applicationUser.savedSessionId || shouldAwaitSaveSessionQueue) {
await saveSessionPromise;
}
}
// PRIVATE FUNCTIONS //

View file

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

View file

@ -223,8 +223,8 @@ export default {
} else if (this.$store.getters.order.referralNumber?.length === 6) {
await this.navigateForwardWithSingleCarMatch();
} else if (this.isRepair) {
// call saveSession here - navigateWithSaving only saves asynchronously
await saveSession();
// call saveSession here - navigateWithSaving saves too late in the flow
await saveSession({});
return this.$router.navigateWithoutSaving(
this.navigationScenarios.CLICKED_FORWARD_WITH_NO_QUESTIONS,
this.$route

View file

@ -8,7 +8,7 @@ export default {
async navigateForwardWithSingleCarMatch() {
// 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) {
await saveSession();
await saveSession({});
}
const result = await this.dispatchStoreAction(storeActions.GET_PARTS_OR_QUESTIONS);

View file

@ -160,7 +160,7 @@ const router = createRouter({
//---------------------------------------------------------- Router Functions ----------------------------------------------------------
router.afterEach((to, from) => {
router.afterEach(async (to, from) => {
// Update lastPageVisited in the store
store.commit(storeMutations.UPDATE_LAST_PAGE_VISITED, to.name);
@ -170,7 +170,7 @@ router.afterEach((to, from) => {
store.getters.applicationUser.savedSessionId ||
store.getters.order.customer?.emailAddress
) {
saveSession();
await saveSession({});
}
}