From 42272f358fa6fce1440468d37e75a1e150fd0477 Mon Sep 17 00:00:00 2001 From: Martavis Parker <47053705+martavis@users.noreply.github.com> Date: Tue, 22 Jun 2021 16:44:40 -0700 Subject: [PATCH] #1108 send users to manage queries if error (#1154) * #1108 send users to manage queries if error * #1108 fixed tests and lint * #1108 fixed more tests * #1108 new clause to show different error message * #1108 fixed logic --- .../queries/QueryPageWrapper/helpers.js | 9 +++++-- .../queries/QueryPageWrapper/helpers.tests.js | 24 ++++++++++++++----- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/frontend/components/queries/QueryPageWrapper/helpers.js b/frontend/components/queries/QueryPageWrapper/helpers.js index 11606cfa6f..1025f2a163 100644 --- a/frontend/components/queries/QueryPageWrapper/helpers.js +++ b/frontend/components/queries/QueryPageWrapper/helpers.js @@ -7,9 +7,14 @@ import { renderFlash } from "redux/nodes/notifications/actions"; export const fetchQuery = (dispatch, queryID) => { return dispatch(queryActions.load(queryID)).catch((errors) => { - const errorMessage = join(values(omit(errors, "http_status")), ", "); + const { MANAGE_QUERIES } = PATHS; + let errorMessage = join(values(omit(errors, "http_status")), ", "); - dispatch(push(PATHS.NEW_QUERY)); + if (errorMessage.includes("no rows in result set")) { + errorMessage = "The query you requested does not exist in Fleet."; + } + + dispatch(push(MANAGE_QUERIES)); dispatch(renderFlash("error", errorMessage)); return false; diff --git a/frontend/components/queries/QueryPageWrapper/helpers.tests.js b/frontend/components/queries/QueryPageWrapper/helpers.tests.js index e8b218b523..30f17735f7 100644 --- a/frontend/components/queries/QueryPageWrapper/helpers.tests.js +++ b/frontend/components/queries/QueryPageWrapper/helpers.tests.js @@ -39,7 +39,7 @@ describe("QueryPageWrapper - helpers", () => { }); describe("when the API call is unsuccessful", () => { - it("pushes to the new query page", (done) => { + it("pushes to the manage queries page", (done) => { queryMocks.load.invalid(bearerToken, queryID); const mockStore = reduxMockStore(); @@ -51,7 +51,7 @@ describe("QueryPageWrapper - helpers", () => { expect(locationChangeAction).toBeTruthy(); expect(locationChangeAction.payload).toEqual({ method: "push", - args: ["/queries/new"], + args: ["/queries/manage"], }); done(); @@ -70,10 +70,22 @@ describe("QueryPageWrapper - helpers", () => { }); expect(flashMessageAction).toBeTruthy(); - expect(flashMessageAction.payload).toMatchObject({ - alertType: "error", - message: "Resource not found", - }); + + if ( + flashMessageAction.payload.message.includes( + "no rows in result set" + ) + ) { + expect(flashMessageAction.payload).toMatchObject({ + alertType: "error", + message: "The query you requested does not exist in Fleet.", + }); + } else { + expect(flashMessageAction.payload).toMatchObject({ + alertType: "error", + message: "Resource not found", + }); + } done(); })