mirror of
https://github.com/teamhanko/hanko.git
synced 2025-10-28 06:37:57 +08:00
39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
import { ConfigClient, TechnicalError } from "../../../src";
|
|
import { Response } from "../../../src/lib/client/HttpClient";
|
|
|
|
let configClient: ConfigClient;
|
|
|
|
beforeEach(() => {
|
|
configClient = new ConfigClient("http://test.api");
|
|
});
|
|
|
|
describe("configClient.get()", () => {
|
|
it("should call well-known config endpoint and return config", async () => {
|
|
const response = new Response(new XMLHttpRequest());
|
|
response.ok = true;
|
|
response._decodedJSON = { password: { enabled: true } };
|
|
|
|
jest.spyOn(configClient.client, "get").mockResolvedValue(response);
|
|
const config = await configClient.get();
|
|
expect(configClient.client.get).toHaveBeenCalledWith("/.well-known/config");
|
|
expect(config).toEqual(response._decodedJSON);
|
|
});
|
|
|
|
it("should throw technical error when API response is not ok", async () => {
|
|
const response = new Response(new XMLHttpRequest());
|
|
configClient.client.get = jest.fn().mockResolvedValue(response);
|
|
|
|
const config = configClient.get();
|
|
await expect(config).rejects.toThrow(TechnicalError);
|
|
});
|
|
|
|
it("should throw error on API communication failure", async () => {
|
|
configClient.client.get = jest
|
|
.fn()
|
|
.mockRejectedValue(new Error("Test error"));
|
|
|
|
const config = configClient.get();
|
|
await expect(config).rejects.toThrowError("Test error");
|
|
});
|
|
});
|