#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
This commit is contained in:
Martavis Parker 2021-06-22 16:44:40 -07:00 committed by GitHub
parent 4800856bf7
commit 42272f358f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 8 deletions

View file

@ -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;

View file

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