Files
karma/ui/src/Common/Fetch.test.js
Łukasz Mierzwa 80c30f1879 fix(ui): pass configured alertmanager headers when making requests from the browser
Right now configured headers are only set on requests made from the backend to alertmanager API.
With this change fetch() calls in the browser will use those headers if proxy mode is not enabled.
2019-09-26 20:37:23 +01:00

41 lines
1.1 KiB
JavaScript

import { FetchWithCredentials } from "./Fetch";
beforeEach(() => {
fetch.resetMocks();
});
afterEach(() => {
jest.restoreAllMocks();
});
describe("FetchWithCredentials", () => {
it("fetch passes '{credentials: include}' to all requests", async () => {
const request = FetchWithCredentials("http://example.com", {});
await expect(request).resolves.toBeUndefined();
expect(fetch).toHaveBeenCalledWith("http://example.com", {
credentials: "include"
});
});
it("custom keys are merged with defaults", async () => {
const request = FetchWithCredentials("http://example.com", {
foo: "bar"
});
await expect(request).resolves.toBeUndefined();
expect(fetch).toHaveBeenCalledWith("http://example.com", {
credentials: "include",
foo: "bar"
});
});
it("custom credentials are used when passed", async () => {
const request = FetchWithCredentials("http://example.com", {
credentials: "none"
});
await expect(request).resolves.toBeUndefined();
expect(fetch).toHaveBeenCalledWith("http://example.com", {
credentials: "none"
});
});
});