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);
|
||||
}
|
||||
|
||||
if (!store.getters.applicationUser.triggeredSiteEntry) {
|
||||
baseMixin.methods.dispatchStoreAction(storeActions.RUN_EXPERIMENTS_FOR_TRIGGER, {
|
||||
userId: getDeviceIdValue(),
|
||||
triggerEvent: experimentTriggers.SITE_ENTRY,
|
||||
triggerValue: applicationConfig.SITE_ENTRY_TRIGGER_VALUE
|
||||
})
|
||||
}
|
||||
baseMixin.methods.dispatchStoreAction(storeActions.RUN_EXPERIMENTS_FOR_TRIGGER, {
|
||||
userId: getDeviceIdValue(),
|
||||
triggerEvent: experimentTriggers.SITE_ENTRY,
|
||||
triggerValue: applicationConfig.SITE_ENTRY_TRIGGER_VALUE
|
||||
})
|
||||
|
||||
// If the saved session has timed out, clear the session, execute 404 logic.
|
||||
if (getFunnelCookie() !== null && !isSavedSessionStillActive()) {
|
||||
|
|
|
|||
|
|
@ -648,6 +648,11 @@ export const actions = {
|
|||
|
||||
runExperimentsForTrigger(context, { userId, triggerEvent, triggerValue }) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ import globalMethods from "@/global-methods";
|
|||
import { mutations, state, actions, getters } from "@/store";
|
||||
import { storeMutations } from "@/constants/store-mutations";
|
||||
import { storeActions } from "@/constants/store-actions";
|
||||
import { experimentTriggers } from "@/constants/experiments";
|
||||
|
||||
// Mock global method
|
||||
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", () => {
|
||||
// Arrange
|
||||
const storeState = state;
|
||||
|
|
@ -1183,7 +1265,7 @@ describe.only("Getters", () => {
|
|||
expect(getters.payment(storeState).insuranceCoverage.isVerified).toEqual(true);
|
||||
});
|
||||
|
||||
describe.only("experimentOrder", () => {
|
||||
describe("experimentOrder", () => {
|
||||
test("glassToReplace, glassParts, and otherParts are null > return correct experimentOrder values", () => {
|
||||
// Arrange
|
||||
const storeState = state;
|
||||
|
|
|
|||
Loading…
Reference in a new issue