mirror of
https://github.com/outline/outline.git
synced 2026-06-13 11:25:03 +03:00
7f88ab55fb
* Initial plan * Add error handling for Installation.info endpoint in isolated environments * Return -1 for versionsBehind when network request fails Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com>
83 lines
2.1 KiB
TypeScript
83 lines
2.1 KiB
TypeScript
import fetchMock from "jest-fetch-mock";
|
|
import { getVersionInfo, getVersion } from "./getInstallationInfo";
|
|
|
|
beforeEach(() => {
|
|
fetchMock.resetMocks();
|
|
});
|
|
|
|
describe("getVersion", () => {
|
|
it("should return the current version", () => {
|
|
const version = getVersion();
|
|
expect(version).toBeDefined();
|
|
expect(typeof version).toBe("string");
|
|
});
|
|
});
|
|
|
|
describe("getVersionInfo", () => {
|
|
const currentVersion = "0.80.0";
|
|
|
|
it("should return version info when Docker Hub is accessible", async () => {
|
|
fetchMock.mockResponseOnce(
|
|
JSON.stringify({
|
|
results: [
|
|
{ name: "0.81.0" },
|
|
{ name: "0.80.0" },
|
|
{ name: "0.79.0" },
|
|
],
|
|
next: null,
|
|
})
|
|
);
|
|
|
|
const result = await getVersionInfo(currentVersion);
|
|
|
|
expect(result).toEqual({
|
|
latestVersion: "0.81.0",
|
|
versionsBehind: 1,
|
|
});
|
|
});
|
|
|
|
it("should return fallback values when Docker Hub is unreachable", async () => {
|
|
fetchMock.mockRejectOnce(new Error("Network request failed"));
|
|
|
|
const result = await getVersionInfo(currentVersion);
|
|
|
|
expect(result).toEqual({
|
|
latestVersion: currentVersion,
|
|
versionsBehind: -1,
|
|
});
|
|
});
|
|
|
|
it("should return fallback values when fetch times out", async () => {
|
|
fetchMock.mockRejectOnce(new Error("Request timeout after 10000ms"));
|
|
|
|
const result = await getVersionInfo(currentVersion);
|
|
|
|
expect(result).toEqual({
|
|
latestVersion: currentVersion,
|
|
versionsBehind: -1,
|
|
});
|
|
});
|
|
|
|
it("should return fallback values when DNS lookup fails", async () => {
|
|
fetchMock.mockRejectOnce(new Error("DNS lookup failed"));
|
|
|
|
const result = await getVersionInfo(currentVersion);
|
|
|
|
expect(result).toEqual({
|
|
latestVersion: currentVersion,
|
|
versionsBehind: -1,
|
|
});
|
|
});
|
|
|
|
it("should return fallback values when response is not JSON", async () => {
|
|
fetchMock.mockResponseOnce("Not JSON");
|
|
|
|
const result = await getVersionInfo(currentVersion);
|
|
|
|
expect(result).toEqual({
|
|
latestVersion: currentVersion,
|
|
versionsBehind: -1,
|
|
});
|
|
});
|
|
});
|