fix(integrations): type unifi-os test fetch mocks for tsc
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
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 { 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();
|
||||
|
||||
Reference in new issue
Block a user