fix(ui): follow redirects when fetching alerts from the UI

This commit is contained in:
Łukasz Mierzwa
2019-11-14 13:20:45 +00:00
parent d46ff69619
commit 09f31e172b
3 changed files with 13 additions and 6 deletions

View File

@@ -1,6 +1,9 @@
import merge from "lodash.merge";
const FetchWithCredentials = async (uri, options) =>
await fetch(uri, merge({}, { credentials: "include" }, options));
await fetch(
uri,
merge({}, { credentials: "include", redirect: "follow" }, options)
);
export { FetchWithCredentials };

View File

@@ -13,7 +13,8 @@ describe("FetchWithCredentials", () => {
const request = FetchWithCredentials("http://example.com", {});
await expect(request).resolves.toBeUndefined();
expect(fetch).toHaveBeenCalledWith("http://example.com", {
credentials: "include"
credentials: "include",
redirect: "follow"
});
});
@@ -24,17 +25,20 @@ describe("FetchWithCredentials", () => {
await expect(request).resolves.toBeUndefined();
expect(fetch).toHaveBeenCalledWith("http://example.com", {
credentials: "include",
redirect: "follow",
foo: "bar"
});
});
it("custom credentials are used when passed", async () => {
const request = FetchWithCredentials("http://example.com", {
credentials: "none"
credentials: "none",
redirect: "follow"
});
await expect(request).resolves.toBeUndefined();
expect(fetch).toHaveBeenCalledWith("http://example.com", {
credentials: "none"
credentials: "none",
redirect: "follow"
});
});
});

View File

@@ -89,7 +89,7 @@ describe("<SilencePreview />", () => {
fetch
).toHaveBeenCalledWith(
"./alerts.json?q=foo%3Dbar&q=%40alertmanager%3D~%5E%28amValue%29%24",
{ credentials: "include" }
{ credentials: "include", redirect: "follow" }
);
});
@@ -105,7 +105,7 @@ describe("<SilencePreview />", () => {
fetch
).toHaveBeenCalledWith(
"./alerts.json?q=foo%3Dbar&q=%40alertmanager%3D~%5E%28am1%7Cam2%29%24",
{ credentials: "include" }
{ credentials: "include", redirect: "follow" }
);
});