import { beforeEach, describe, expect, it, vi } from "vitest";
import type { Mock } from "vitest";
import { ENDPOINTS } from "../endpoints";
import { fetchBansByCountry } from "../map";
import { get } from "../client";

vi.mock("../client", () => ({
  get: vi.fn(),
}));

const mockedGet = get as Mock;

describe("fetchBansByCountry", () => {
  beforeEach(() => {
    mockedGet.mockReset();
    mockedGet.mockResolvedValue({ countries: {}, country_names: {}, bans: [], total: 0 });
  });

  it("appends country_code when provided", async () => {
    await fetchBansByCountry("24h", "all", "fail2ban", "US");

    expect(get).toHaveBeenCalledWith(
      `${ENDPOINTS.dashboardBansByCountry}?range=24h&country_code=US`
    );
  });

  it("does not append country_code when undefined", async () => {
    await fetchBansByCountry("24h", "all", "fail2ban");

    expect(get).toHaveBeenCalledWith(
      `${ENDPOINTS.dashboardBansByCountry}?range=24h`
    );
  });
});
