import { describe, expect, it } from "vitest";

import { isAbortError } from "@/utils/abort";
import { Result } from "@/utils/result";

describe("isAbortError", () => {
  it("recognizes cancellation after Result normalizes the error", async () => {
    const result = await Result.wrap(async () => {
      throw new DOMException("This operation was aborted", "AbortError");
    });

    expect(Result.isErr(result) && isAbortError(result.error)).toBe(true);
  });

  it("does not treat request timeouts as actor cancellation", () => {
    expect(isAbortError(new DOMException("Timed out", "TimeoutError"))).toBe(
      false,
    );
  });
});
