fix(integrations): type unifi-os test fetch mocks for tsc

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
zacharyandClaude Opus 5 committed 2026-10-08 00:21:50 +02:00
1 parent ca1cc54623
commit 2d601279e3
2 files changed
+12 -6

No files matched your search

@@ -1,5 +1,5 @@
// @vitest-environment node
import { Response } from "undici";
import { Response, type RequestInit } from "undici";
import { describe, expect, test, vi } from "vitest";
vi.hoisted(() => {
@@ -32,7 +32,9 @@ const createApi = (handler: (url: string) => Promise<Response>) => {
describe("UnifiOsApi request shape", () => {
test("prefixes the integration path and sends the API key header", async () => {
const fetchAsync = vi.fn(async () => jsonResponse({ applicationVersion: "10.6.102" }));
const fetchAsync = vi.fn(async (_url: string, _init?: RequestInit) =>
jsonResponse({ applicationVersion: "10.6.102" }),
);
const api = new UnifiOsApi(ORIGIN, API_KEY, fetchAsync as never);
await api.getInfoAsync();
@@ -44,7 +46,9 @@ describe("UnifiOsApi request shape", () => {
});
test("does not double a slash when the origin has a trailing one", async () => {
const fetchAsync = vi.fn(async () => jsonResponse({ applicationVersion: "10.6.102" }));
const fetchAsync = vi.fn(async (_url: string, _init?: RequestInit) =>
jsonResponse({ applicationVersion: "10.6.102" }),
);
const api = new UnifiOsApi(`${ORIGIN}/`, API_KEY, fetchAsync as never);
await api.getInfoAsync();
@@ -1,5 +1,5 @@
// @vitest-environment node
import { Response } from "undici";
import { Response, type RequestInit } from "undici";
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
vi.hoisted(() => {
@@ -46,7 +46,7 @@ const metricsBody = (metricTime: string) => ({
});
const createApi = () => {
const fetchAsync = vi.fn(async (url: string) =>
const fetchAsync = vi.fn(async (url: string, _init?: RequestInit) =>
url.includes("isp-metrics") ? jsonResponse(metricsBody("2026-09-08T09:10:00Z")) : jsonResponse(sitesBody),
);
return { api: new UnifiSmApi("cloud-key", fetchAsync as never), fetchAsync };
@@ -130,7 +130,9 @@ describe("UnifiSmApi getIspMetricsAsync", () => {
});
test("returns null when the cloud rejects the key rather than propagating", async () => {
const fetchAsync = vi.fn(async () => jsonResponse({ message: "unauthorized" }, 401));
const fetchAsync = vi.fn(async (_url: string, _init?: RequestInit) =>
jsonResponse({ message: "unauthorized" }, 401),
);
const api = new UnifiSmApi("bad-key", fetchAsync as never);
expect(await api.getIspMetricsAsync(GATEWAY_MAC)).toBeNull();