Standardize API response envelopes: use items for collection responses and update tests

This commit is contained in:
2026-04-28 20:48:00 +02:00
parent 1c673d600c
commit b27765928a
23 changed files with 186 additions and 104 deletions

View File

@@ -0,0 +1,25 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import type { Mock } from "vitest";
import { ENDPOINTS } from "../endpoints";
import { fetchIgnoreList } from "../jails";
import { get } from "../client";
vi.mock("../client", () => ({
get: vi.fn(),
}));
const mockedGet = get as Mock;
describe("fetchIgnoreList", () => {
beforeEach(() => {
mockedGet.mockReset();
mockedGet.mockResolvedValue({ items: ["127.0.0.1"], total: 1 });
});
it("requests the jail ignore list endpoint and returns the wrapped response", async () => {
const response = await fetchIgnoreList("sshd");
expect(get).toHaveBeenCalledWith(ENDPOINTS.jailIgnoreIp("sshd"));
expect(response).toEqual({ items: ["127.0.0.1"], total: 1 });
});
});

View File

@@ -9,6 +9,7 @@ import { del, get, post } from "./client";
import { ENDPOINTS } from "./endpoints";
import type {
ActiveBanListResponse,
IgnoreListResponse,
IpLookupResponse,
JailBannedIpsResponse,
JailCommandResponse,
@@ -112,11 +113,11 @@ export async function reloadAllJails(): Promise<JailCommandResponse> {
* Return the ignore list for a jail.
*
* @param name - Jail name.
* @returns Array of IP addresses / CIDR networks on the ignore list.
* @returns The {@link IgnoreListResponse} wrapper containing the ignore list.
* @throws {ApiError} On non-2xx responses.
*/
export async function fetchIgnoreList(name: string): Promise<string[]> {
return get<string[]>(ENDPOINTS.jailIgnoreIp(name));
export async function fetchIgnoreList(name: string): Promise<IgnoreListResponse> {
return get<IgnoreListResponse>(ENDPOINTS.jailIgnoreIp(name));
}
/**