From 0dffdea153667d785b020e6cca10c9cba784f681 Mon Sep 17 00:00:00 2001 From: Katie Date: Mon, 15 Aug 2022 12:22:38 -0400 Subject: [PATCH 1/2] CSR-514 Save experiments --- src/constants/application-config.js | 2 +- src/store/index.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/constants/application-config.js b/src/constants/application-config.js index 3f1979f83..f42a2c183 100644 --- a/src/constants/application-config.js +++ b/src/constants/application-config.js @@ -6,7 +6,7 @@ const applicationConfig = { SAVED_SESSION_TIMEOUT_DAYS: 45, COOKIE_PATH: "/", CURRENT_ENVIRONMENT: process.env.VUE_APP_CURRENT_ENVIRONMENT, // "Localhost", "Dev", "QA", and "Prod" - APPLICATION_NAME: "SafeliteDotCom", + APPLICATION_NAME: "FixMyGlass", SITE_ENTRY_TRIGGER_VALUE: "FixMyGlass" }; diff --git a/src/store/index.js b/src/store/index.js index 6aeca59eb..08df46cb2 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -663,6 +663,8 @@ export const actions = { method: endpoints.RunExperimentsForTrigger.method, endpoint: endpoints.RunExperimentsForTrigger.url, payload: payload, + }).then(response => { + context.commit(storeMutations.UPDATE_EXPERIMENTS, response.data.experiments) }); }, From faae9b9d360653af6b5b5accfc66f694d6c7e597 Mon Sep 17 00:00:00 2001 From: Katie Date: Mon, 15 Aug 2022 13:06:04 -0400 Subject: [PATCH 2/2] CSR-514 Fix tests --- src/store/index.js | 8 ++++---- src/store/store.spec.js | 32 +++++++++++++++++++++++++------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/store/index.js b/src/store/index.js index 08df46cb2..76abf60db 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -646,7 +646,7 @@ export const actions = { }); }, - runExperimentsForTrigger(context, { userId, triggerEvent, triggerValue }) { + async runExperimentsForTrigger(context, { userId, triggerEvent, triggerValue }) { if (triggerEvent == experimentTriggers.SITE_ENTRY) { context.commit(storeMutations.UPDATE_TRIGGERED_SITE_ENTRY, true); } @@ -659,13 +659,13 @@ export const actions = { experimentOrder: context.getters.experimentOrder }; - globalMethods.callHttpClient({ + const response = await globalMethods.callHttpClient({ method: endpoints.RunExperimentsForTrigger.method, endpoint: endpoints.RunExperimentsForTrigger.url, payload: payload, - }).then(response => { - context.commit(storeMutations.UPDATE_EXPERIMENTS, response.data.experiments) }); + + context.commit(storeMutations.UPDATE_EXPERIMENTS, response.data.experiments); }, getEvoxImage(context, { relativeUrl }) { diff --git a/src/store/store.spec.js b/src/store/store.spec.js index a30635b24..a69be855b 100644 --- a/src/store/store.spec.js +++ b/src/store/store.spec.js @@ -1091,10 +1091,18 @@ describe("Actions", () => { describe("runExperimentsForTrigger", () => { beforeEach(() => { mutations.resetState(state); - globalMethods.callHttpClient = jest.fn(); + globalMethods.callHttpClient = jest.fn().mockReturnValue({ + data: { + experiments: [ + { + mockProperty: "mockValue" + } + ] + } + }); }) - test("triggerEvent is SiteEntry => set triggeredSiteEntry to true in store", () => { + 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)); @@ -1104,17 +1112,22 @@ describe("Actions", () => { }; // Act - actions.runExperimentsForTrigger(context, { + await actions.runExperimentsForTrigger(context, { triggerEvent: experimentTriggers.SITE_ENTRY, }); // Assert - expect(context.commit).toHaveBeenCalledWith(storeMutations.UPDATE_TRIGGERED_SITE_ENTRY, true); + 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", () => { + 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)); @@ -1125,15 +1138,20 @@ describe("Actions", () => { expect(context.commit).toHaveBeenCalledTimes(0); // Act - actions.runExperimentsForTrigger(context, { + await actions.runExperimentsForTrigger(context, { triggerEvent: "NotSiteEntry", }); // Assert - expect(context.commit).not.toHaveBeenCalled(); + 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" + } + ]); }); }) });