import { describe, expect, it, vi } from "vitest";
import { ApiError } from "../../api/client";
import { handleFetchError } from "../fetchError";

describe("utils/fetchError", () => {
  it("ignores AbortError errors", () => {
    const setError = vi.fn();
    handleFetchError(new DOMException("Aborted", "AbortError"), setError, "fallback");
    expect(setError).not.toHaveBeenCalled();
  });

  it("ignores auth errors", () => {
    const setError = vi.fn();
    handleFetchError(new ApiError(401, "Unauthorized"), setError, "fallback");
    expect(setError).not.toHaveBeenCalled();
  });

  it("sets fallback for normal errors", () => {
    const setError = vi.fn();
    handleFetchError(new Error("Oops"), setError, "fallback");
    expect(setError).toHaveBeenCalledWith("Oops");
  });
});
