The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
import React from "react";
import { renderHook, waitFor } from "@testing-library/react";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { useDeletePolicyAttachment } from "./useDeletePolicyAttachment";
import { deletePolicyAttachmentCall } from "@/components/networking";
import { toast } from "@/lib/toast";
import { vi, describe, beforeEach, it, expect } from "vitest";
// Mock dependencies
vi.mock("@/components/networking", () => ({
deletePolicyAttachmentCall: vi.fn(),
}));
describe("useDeletePolicyAttachment", () => {
let queryClient: QueryClient;
beforeEach(() => {
queryClient = new QueryClient();
vi.clearAllMocks();
});
const wrapper = ({ children }: { children: React.ReactNode }) => (
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
);
it("should successfully delete a policy attachment and call onSuccess", async () => {
const mockOnSuccess = vi.fn();
(deletePolicyAttachmentCall as any).mockResolvedValue({});
const { result } = renderHook(
() =>
useDeletePolicyAttachment({
accessToken: "test-token",
onSuccess: mockOnSuccess,
}),
{ wrapper },
);
result.current.mutate("attachment-1");
await waitFor(() => {
expect(result.current.isSuccess).toBe(true);
});
expect(deletePolicyAttachmentCall).toHaveBeenCalledWith("test-token", "attachment-1");
expect(toast.success).toHaveBeenCalledWith("Attachment deleted successfully");
expect(mockOnSuccess).toHaveBeenCalled();
});
it("should handle error when deleting policy attachment", async () => {
const mockOnError = vi.fn();
const error = new Error("Delete failed");
(deletePolicyAttachmentCall as any).mockRejectedValue(error);
const { result } = renderHook(
() =>
useDeletePolicyAttachment({
accessToken: "test-token",
onError: mockOnError,
}),
{ wrapper },
);
result.current.mutate("attachment-1");
await waitFor(() => {
expect(result.current.isError).toBe(true);
});
expect(deletePolicyAttachmentCall).toHaveBeenCalledWith("test-token", "attachment-1");
expect(toast.error).toHaveBeenCalledWith("Failed to delete attachment");
expect(mockOnError).toHaveBeenCalledWith(error);
});
});