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 });
  });
});
