CSR-514 Fix tests

This commit is contained in:
Katie 2022-08-15 13:06:04 -04:00
parent 0dffdea153
commit faae9b9d36
2 changed files with 29 additions and 11 deletions

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) {
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 }) {

View file

@ -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"
}
]);
});
})
});