mirror of
https://github.com/outline/outline.git
synced 2026-06-13 11:25:03 +03:00
091346dfe8
* wip * Remove obsolete snapshots * simplify * chore(test): Convert mocks to TypeScript and tighten fetch mock types Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * Remove unneccessary patches * Migrate to msw instead of custom fetch mock * Address PR review comments - Split chained vi.useFakeTimers().setSystemTime() into separate calls. - Switch test setup to dynamic imports so EventEmitter.defaultMaxListeners assignment runs before module init (static imports were hoisted above it). - Drop redundant NODE_ENV guard in monkeyPatchSequelizeErrorsForJest; its sole caller already gates on env.isTest. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
86 lines
2.2 KiB
TypeScript
86 lines
2.2 KiB
TypeScript
import { http, HttpResponse } from "msw";
|
|
import { server } from "@server/test/msw";
|
|
import { getVersionInfo, getVersion } from "./getInstallationInfo";
|
|
|
|
const dockerHubUrl =
|
|
"https://hub.docker.com/v2/repositories/outlinewiki/outline/tags";
|
|
|
|
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 () => {
|
|
server.use(
|
|
http.get(dockerHubUrl, () =>
|
|
HttpResponse.json({
|
|
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 () => {
|
|
server.use(http.get(dockerHubUrl, () => HttpResponse.error()));
|
|
|
|
const result = await getVersionInfo(currentVersion);
|
|
|
|
expect(result).toEqual({
|
|
latestVersion: currentVersion,
|
|
versionsBehind: -1,
|
|
});
|
|
});
|
|
|
|
it("should return fallback values when fetch times out", async () => {
|
|
server.use(http.get(dockerHubUrl, () => HttpResponse.error()));
|
|
|
|
const result = await getVersionInfo(currentVersion);
|
|
|
|
expect(result).toEqual({
|
|
latestVersion: currentVersion,
|
|
versionsBehind: -1,
|
|
});
|
|
});
|
|
|
|
it("should return fallback values when DNS lookup fails", async () => {
|
|
server.use(http.get(dockerHubUrl, () => HttpResponse.error()));
|
|
|
|
const result = await getVersionInfo(currentVersion);
|
|
|
|
expect(result).toEqual({
|
|
latestVersion: currentVersion,
|
|
versionsBehind: -1,
|
|
});
|
|
});
|
|
|
|
it("should return fallback values when response is not JSON", async () => {
|
|
server.use(
|
|
http.get(
|
|
dockerHubUrl,
|
|
() => new HttpResponse("Not JSON", { status: 200 })
|
|
)
|
|
);
|
|
|
|
const result = await getVersionInfo(currentVersion);
|
|
|
|
expect(result).toEqual({
|
|
latestVersion: currentVersion,
|
|
versionsBehind: -1,
|
|
});
|
|
});
|
|
});
|