Standardize API response envelopes: use items for collection responses and update tests
This commit is contained in:
25
frontend/src/api/__tests__/jails.test.ts
Normal file
25
frontend/src/api/__tests__/jails.test.ts
Normal 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 });
|
||||
});
|
||||
});
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user