Merge pull request #658 from Safelite/feature/CSR-514

CSR-514 Save experiments
This commit is contained in:
katieoh-safelite 2022-08-15 13:16:52 -04:00 committed by GitHub
commit b7ced3bdf8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 10 deletions

View file

@ -6,7 +6,7 @@ const applicationConfig = {
SAVED_SESSION_TIMEOUT_DAYS: 45, SAVED_SESSION_TIMEOUT_DAYS: 45,
COOKIE_PATH: "/", COOKIE_PATH: "/",
CURRENT_ENVIRONMENT: process.env.VUE_APP_CURRENT_ENVIRONMENT, // "Localhost", "Dev", "QA", and "Prod" CURRENT_ENVIRONMENT: process.env.VUE_APP_CURRENT_ENVIRONMENT, // "Localhost", "Dev", "QA", and "Prod"
APPLICATION_NAME: "SafeliteDotCom", APPLICATION_NAME: "FixMyGlass",
SITE_ENTRY_TRIGGER_VALUE: "FixMyGlass" SITE_ENTRY_TRIGGER_VALUE: "FixMyGlass"
}; };

View file

@ -646,7 +646,7 @@ export const actions = {
}); });
}, },
runExperimentsForTrigger(context, { userId, triggerEvent, triggerValue }) { async runExperimentsForTrigger(context, { userId, triggerEvent, triggerValue }) {
if (triggerEvent == experimentTriggers.SITE_ENTRY) { if (triggerEvent == experimentTriggers.SITE_ENTRY) {
context.commit(storeMutations.UPDATE_TRIGGERED_SITE_ENTRY, true); context.commit(storeMutations.UPDATE_TRIGGERED_SITE_ENTRY, true);
} }
@ -659,11 +659,13 @@ export const actions = {
experimentOrder: context.getters.experimentOrder experimentOrder: context.getters.experimentOrder
}; };
globalMethods.callHttpClient({ const response = await globalMethods.callHttpClient({
method: endpoints.RunExperimentsForTrigger.method, method: endpoints.RunExperimentsForTrigger.method,
endpoint: endpoints.RunExperimentsForTrigger.url, endpoint: endpoints.RunExperimentsForTrigger.url,
payload: payload, payload: payload,
}); });
context.commit(storeMutations.UPDATE_EXPERIMENTS, response.data.experiments);
}, },
getEvoxImage(context, { relativeUrl }) { getEvoxImage(context, { relativeUrl }) {

View file

@ -1091,10 +1091,18 @@ describe("Actions", () => {
describe("runExperimentsForTrigger", () => { describe("runExperimentsForTrigger", () => {
beforeEach(() => { beforeEach(() => {
mutations.resetState(state); 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 // Arrange
const context = state; const context = state;
context.commit = jest.fn().mockImplementation((storeMutation, value) => mutations[storeMutation](context, value)); context.commit = jest.fn().mockImplementation((storeMutation, value) => mutations[storeMutation](context, value));
@ -1104,17 +1112,22 @@ describe("Actions", () => {
}; };
// Act // Act
actions.runExperimentsForTrigger(context, { await actions.runExperimentsForTrigger(context, {
triggerEvent: experimentTriggers.SITE_ENTRY, triggerEvent: experimentTriggers.SITE_ENTRY,
}); });
// Assert // 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(context.getters.applicationUser.triggeredSiteEntry).toBe(true);
expect(globalMethods.callHttpClient).toHaveBeenCalled(); 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 // Arrange
const context = state; const context = state;
context.commit = jest.fn().mockImplementation((storeMutation, value) => mutations[storeMutation](context, value)); context.commit = jest.fn().mockImplementation((storeMutation, value) => mutations[storeMutation](context, value));
@ -1125,15 +1138,20 @@ describe("Actions", () => {
expect(context.commit).toHaveBeenCalledTimes(0); expect(context.commit).toHaveBeenCalledTimes(0);
// Act // Act
actions.runExperimentsForTrigger(context, { await actions.runExperimentsForTrigger(context, {
triggerEvent: "NotSiteEntry", triggerEvent: "NotSiteEntry",
}); });
// Assert // 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(context.getters.applicationUser.triggeredSiteEntry).toBe(false);
expect(globalMethods.callHttpClient).toHaveBeenCalledTimes(1); expect(globalMethods.callHttpClient).toHaveBeenCalledTimes(1);
expect(context.commit).toHaveBeenNthCalledWith(1, storeMutations.UPDATE_EXPERIMENTS, [
{
mockProperty: "mockValue"
}
]);
}); });
}) })
}); });