Files
outline/server/utils/getInstallationInfo.test.ts
T
Copilot 7f88ab55fb Handle network failures in installation.info endpoint for isolated environments (#11546)
* 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>
2026-02-24 15:20:48 -05:00

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,
});
});
});