diff --git a/web/src/components/automation/PolicyChecksTab.vue b/web/src/components/automation/PolicyChecksTab.vue index d22a744f..9b776c6a 100644 --- a/web/src/components/automation/PolicyChecksTab.vue +++ b/web/src/components/automation/PolicyChecksTab.vue @@ -249,6 +249,7 @@ export default { methods: { checkAlert(id, alert_type, action) { const data = {}; + if (alert_type === "Email") { data.email_alert = action; } else { @@ -258,7 +259,7 @@ export default { const act = action ? "enabled" : "disabled"; const color = action ? "positive" : "warning"; this.$store - .dispatch("editCheckAlert", id, data) + .dispatch("editCheckAlert", { pk: id, data }) .then(r => { this.$q.notify({ color: color, diff --git a/web/src/store/store.js b/web/src/store/store.js index b1c389a8..35226f82 100644 --- a/web/src/store/store.js +++ b/web/src/store/store.js @@ -159,7 +159,7 @@ export const store = new Vuex.Store({ loadAgentServices(context, agentpk) { return axios.get(`/services/${agentpk}/services/`); }, - editCheckAlert(context, pk, data) { + editCheckAlert(context, {pk, data}) { return axios.patch(`/checks/${pk}/check/`, data); }, deleteCheck(context, pk) { diff --git a/web/tests/unit/automation/policycheckstab.spec.js b/web/tests/unit/automation/policycheckstab.spec.js index 67e58741..93e1c374 100644 --- a/web/tests/unit/automation/policycheckstab.spec.js +++ b/web/tests/unit/automation/policycheckstab.spec.js @@ -190,7 +190,6 @@ describe("PolicyChecksTab.vue with policy selected and checks", () => { // Runs before every test beforeEach(() => { - // Create the Test store // Create the Test store state = { checks: [ @@ -219,7 +218,7 @@ describe("PolicyChecksTab.vue with policy selected and checks", () => { }; rootActions = { - editCheckAlertAction: jest.fn(), + editCheckAlert: jest.fn(), deleteCheck: jest.fn() }; @@ -330,7 +329,7 @@ describe("PolicyChecksTab.vue with policy selected and checks", () => { //Get OK button on confirmation dialog and click it await bodyWrapper.findAll(".q-btn").wrappers[1].trigger("click"); - expect(rootActions.deleteCheck).toHaveBeenCalledWith(expect.anything(), {pk: 1, checktype:"diskspace"}); + expect(rootActions.deleteCheck).toHaveBeenCalledWith(expect.anything(), 1); expect(actions.loadPolicyChecks).toHaveBeenCalled(); }); @@ -343,22 +342,29 @@ describe("PolicyChecksTab.vue with policy selected and checks", () => { //Enable Text Alert await row.trigger("click"); - expect(rootActions.editCheckAlertAction).toHaveBeenCalledWith(expect.anything(), { - alertType: "text", - checkid: 1, - category: "diskspace", - action: "enabled" - }); + expect(rootActions.editCheckAlert).toHaveBeenCalledWith( + expect.anything(), + { + pk: 1, + data: { + text_alert: true + } + } + ); //Disable Text Alert await row.trigger("click"); - expect(rootActions.editCheckAlertAction).toHaveBeenCalledWith(expect.anything(), { - alertType: "text", - checkid: 1, - category: "diskspace", - action: "disabled" - }); + expect(rootActions.editCheckAlert).toHaveBeenCalledWith( + expect.anything(), + { + pk: 1, + data: { + text_alert: false + } + } + ); + }); it("enables and disables email alerts for check", async () => { @@ -369,22 +375,28 @@ describe("PolicyChecksTab.vue with policy selected and checks", () => { //Enable Text Alert await row.trigger("click"); - expect(rootActions.editCheckAlertAction).toHaveBeenCalledWith(expect.anything(), { - alertType: "email", - checkid: 1, - category: "diskspace", - action: "enabled" - }); + expect(rootActions.editCheckAlert).toHaveBeenCalledWith( + expect.anything(), + { + pk: 1, + data: { + email_alert: true + } + } + ); //Disable Text Alert await row.trigger("click"); - expect(rootActions.editCheckAlertAction).toHaveBeenCalledWith(expect.anything(), { - alertType: "email", - checkid: 1, - category: "diskspace", - action: "disabled" - }); + expect(rootActions.editCheckAlert).toHaveBeenCalledWith( + expect.anything(), + { + pk: 1, + data: { + email_alert: false + } + } + ); }); /* TODO: test @close and @hide events */