- Implement release update detection, asset preloading, and frontend version management. - Add unit and E2E tests for release update workflows, widget behavior, and failure scenarios. - Introduce new services for handling release ping, error reporting, and update installation workflows. - Extend i18n for release-related components and error report localization. - Add `ReleaseFrontendVersionBadge.vue` and related styles to display frontend update statuses.
83 lines
2.0 KiB
JavaScript
83 lines
2.0 KiB
JavaScript
// @vitest-environment jsdom
|
|
|
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import { pingApiServer } from "@/services/apiHealth.js";
|
|
|
|
describe("apiHealth", () => {
|
|
afterEach(() => {
|
|
vi.useRealTimers();
|
|
});
|
|
|
|
it("treats a 2xx ping response as healthy", async () => {
|
|
const fetchImpl = vi.fn().mockResolvedValue({
|
|
ok: true,
|
|
status: 200,
|
|
});
|
|
|
|
const result = await pingApiServer({ fetchImpl });
|
|
|
|
expect(result).toMatchObject({
|
|
ok: true,
|
|
status: 200,
|
|
error: null,
|
|
});
|
|
expect(result.url).toContain("/ping");
|
|
expect(fetchImpl).toHaveBeenCalledWith(
|
|
expect.stringContaining("/ping"),
|
|
expect.objectContaining({
|
|
method: "GET",
|
|
cache: "no-store",
|
|
mode: "cors",
|
|
})
|
|
);
|
|
});
|
|
|
|
it("treats a non-2xx ping response as unhealthy", async () => {
|
|
const fetchImpl = vi.fn().mockResolvedValue({
|
|
ok: false,
|
|
status: 503,
|
|
});
|
|
|
|
const result = await pingApiServer({ fetchImpl });
|
|
|
|
expect(result).toMatchObject({
|
|
ok: false,
|
|
status: 503,
|
|
error: null,
|
|
});
|
|
});
|
|
|
|
it("returns an unhealthy result when ping fetch rejects", async () => {
|
|
const error = new Error("Network unavailable");
|
|
const fetchImpl = vi.fn().mockRejectedValue(error);
|
|
|
|
const result = await pingApiServer({ fetchImpl });
|
|
|
|
expect(result).toMatchObject({
|
|
ok: false,
|
|
status: null,
|
|
error,
|
|
});
|
|
});
|
|
|
|
it("returns an unhealthy result when ping times out", async () => {
|
|
vi.useFakeTimers();
|
|
|
|
const fetchImpl = vi.fn((_url, options) => {
|
|
return new Promise((_resolve, reject) => {
|
|
options.signal.addEventListener("abort", () => {
|
|
reject(new DOMException("Aborted", "AbortError"));
|
|
});
|
|
});
|
|
});
|
|
|
|
const ping = pingApiServer({ fetchImpl, timeoutMs: 25 });
|
|
await vi.advanceTimersByTimeAsync(25);
|
|
const result = await ping;
|
|
|
|
expect(result.ok).toBe(false);
|
|
expect(result.status).toBeNull();
|
|
expect(result.error?.name).toBe("AbortError");
|
|
});
|
|
});
|