CSR-514 Refactor a bit, add tests
This commit is contained in:
parent
e592f55a67
commit
137b5d9621
3 changed files with 94 additions and 9 deletions
|
|
@ -37,13 +37,11 @@ const routes = [
|
||||||
return next(false);
|
return next(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!store.getters.applicationUser.triggeredSiteEntry) {
|
baseMixin.methods.dispatchStoreAction(storeActions.RUN_EXPERIMENTS_FOR_TRIGGER, {
|
||||||
baseMixin.methods.dispatchStoreAction(storeActions.RUN_EXPERIMENTS_FOR_TRIGGER, {
|
userId: getDeviceIdValue(),
|
||||||
userId: getDeviceIdValue(),
|
triggerEvent: experimentTriggers.SITE_ENTRY,
|
||||||
triggerEvent: experimentTriggers.SITE_ENTRY,
|
triggerValue: applicationConfig.SITE_ENTRY_TRIGGER_VALUE
|
||||||
triggerValue: applicationConfig.SITE_ENTRY_TRIGGER_VALUE
|
})
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the saved session has timed out, clear the session, execute 404 logic.
|
// If the saved session has timed out, clear the session, execute 404 logic.
|
||||||
if (getFunnelCookie() !== null && !isSavedSessionStillActive()) {
|
if (getFunnelCookie() !== null && !isSavedSessionStillActive()) {
|
||||||
|
|
|
||||||
|
|
@ -648,6 +648,11 @@ export const actions = {
|
||||||
|
|
||||||
runExperimentsForTrigger(context, { userId, triggerEvent, triggerValue }) {
|
runExperimentsForTrigger(context, { userId, triggerEvent, triggerValue }) {
|
||||||
if (triggerEvent == experimentTriggers.SITE_ENTRY) {
|
if (triggerEvent == experimentTriggers.SITE_ENTRY) {
|
||||||
|
// If site entry event was already triggered, don't rerun experiments
|
||||||
|
if (context.getters.applicationUser.triggeredSiteEntry) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
context.commit(storeMutations.UPDATE_TRIGGERED_SITE_ENTRY, true);
|
context.commit(storeMutations.UPDATE_TRIGGERED_SITE_ENTRY, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ import globalMethods from "@/global-methods";
|
||||||
import { mutations, state, actions, getters } from "@/store";
|
import { mutations, state, actions, getters } from "@/store";
|
||||||
import { storeMutations } from "@/constants/store-mutations";
|
import { storeMutations } from "@/constants/store-mutations";
|
||||||
import { storeActions } from "@/constants/store-actions";
|
import { storeActions } from "@/constants/store-actions";
|
||||||
|
import { experimentTriggers } from "@/constants/experiments";
|
||||||
|
|
||||||
// Mock global method
|
// Mock global method
|
||||||
globalMethods.callHttpClient = jest.fn();
|
globalMethods.callHttpClient = jest.fn();
|
||||||
|
|
||||||
|
|
@ -1086,10 +1088,90 @@ describe("Actions", () => {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("runExperimentsForTrigger", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
mutations.resetState(state);
|
||||||
|
globalMethods.callHttpClient = jest.fn();
|
||||||
|
})
|
||||||
|
|
||||||
|
test("triggerEvent is SiteEntry => set triggeredSiteEntry to true in store", () => {
|
||||||
|
// Arrange
|
||||||
|
const context = state;
|
||||||
|
context.commit = jest.fn().mockImplementation((storeMutation, value) => mutations[storeMutation](context, value));
|
||||||
|
context.getters = {
|
||||||
|
...getters,
|
||||||
|
applicationUser: getters.applicationUser(context)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Act
|
||||||
|
actions.runExperimentsForTrigger(context, {
|
||||||
|
triggerEvent: experimentTriggers.SITE_ENTRY,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(context.commit).toHaveBeenCalledWith(storeMutations.UPDATE_TRIGGERED_SITE_ENTRY, true);
|
||||||
|
expect(context.getters.applicationUser.triggeredSiteEntry).toBe(true);
|
||||||
|
expect(globalMethods.callHttpClient).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("runExperimentsForTrigger is called twice with triggerEvent == SiteEntry => only update store's triggeredSiteEntry value once", () => {
|
||||||
|
// Arrange
|
||||||
|
const context = state;
|
||||||
|
context.commit = jest.fn().mockImplementation((storeMutation, value) => mutations[storeMutation](context, value));
|
||||||
|
context.getters = {
|
||||||
|
...getters,
|
||||||
|
applicationUser: getters.applicationUser(context)
|
||||||
|
};
|
||||||
|
expect(context.commit).toHaveBeenCalledTimes(0);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
actions.runExperimentsForTrigger(context, {
|
||||||
|
triggerEvent: experimentTriggers.SITE_ENTRY,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(context.commit).toHaveBeenCalledTimes(1);
|
||||||
|
expect(context.commit).toHaveBeenCalledWith(storeMutations.UPDATE_TRIGGERED_SITE_ENTRY, true);
|
||||||
|
expect(context.getters.applicationUser.triggeredSiteEntry).toBe(true);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
actions.runExperimentsForTrigger(context, {
|
||||||
|
triggerEvent: experimentTriggers.SITE_ENTRY,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(context.commit).toHaveBeenCalledTimes(1);
|
||||||
|
expect(context.getters.applicationUser.triggeredSiteEntry).toBe(true);
|
||||||
|
|
||||||
|
expect(globalMethods.callHttpClient).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("triggerEvent is not SiteEntry => triggeredSiteEntry is false in store", () => {
|
||||||
|
// Arrange
|
||||||
|
const context = state;
|
||||||
|
context.commit = jest.fn().mockImplementation((storeMutation, value) => mutations[storeMutation](context, value));
|
||||||
|
context.getters = {
|
||||||
|
...getters,
|
||||||
|
applicationUser: getters.applicationUser(context)
|
||||||
|
};
|
||||||
|
expect(context.commit).toHaveBeenCalledTimes(0);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
actions.runExperimentsForTrigger(context, {
|
||||||
|
triggerEvent: "NotSiteEntry",
|
||||||
|
});
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(context.commit).not.toHaveBeenCalled();
|
||||||
|
expect(context.getters.applicationUser.triggeredSiteEntry).toBe(false);
|
||||||
|
|
||||||
|
expect(globalMethods.callHttpClient).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
describe.only("Getters", () => {
|
describe("Getters", () => {
|
||||||
it("Vehicle getter, should return vehicle data", () => {
|
it("Vehicle getter, should return vehicle data", () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const storeState = state;
|
const storeState = state;
|
||||||
|
|
@ -1183,7 +1265,7 @@ describe.only("Getters", () => {
|
||||||
expect(getters.payment(storeState).insuranceCoverage.isVerified).toEqual(true);
|
expect(getters.payment(storeState).insuranceCoverage.isVerified).toEqual(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe.only("experimentOrder", () => {
|
describe("experimentOrder", () => {
|
||||||
test("glassToReplace, glassParts, and otherParts are null > return correct experimentOrder values", () => {
|
test("glassToReplace, glassParts, and otherParts are null > return correct experimentOrder values", () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const storeState = state;
|
const storeState = state;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue