Files
OpenHands/frontend/__tests__/hooks/mutation/use-remove-member.test.tsx
sp.wack cd2d0ee9a5 feat(frontend): Organizational support (#9496)
Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: Hiep Le <69354317+hieptl@users.noreply.github.com>
Co-authored-by: Abhay Mishra <grabhaymishra@gmail.com>
Co-authored-by: Hyun Han <62870362+smosco@users.noreply.github.com>
Co-authored-by: Nhan Nguyen <nhan13574@gmail.com>
Co-authored-by: Bharath A V <avbharath1221@gmail.com>
Co-authored-by: hieptl <hieptl.developer@gmail.com>
Co-authored-by: Chloe <chloe@openhands.com>
Co-authored-by: HeyItsChloe <54480367+HeyItsChloe@users.noreply.github.com>
2026-03-13 23:38:54 +07:00

46 lines
1.4 KiB
TypeScript

import { renderHook, waitFor } from "@testing-library/react";
import { describe, expect, it, vi, beforeEach } from "vitest";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { useRemoveMember } from "#/hooks/mutation/use-remove-member";
import { useSelectedOrganizationStore } from "#/stores/selected-organization-store";
// Mock the useRevalidator hook from react-router
vi.mock("react-router", () => ({
useRevalidator: () => ({
revalidate: vi.fn(),
}),
}));
describe("useRemoveMember", () => {
beforeEach(() => {
useSelectedOrganizationStore.setState({ organizationId: null });
});
it("should throw an error when organizationId is null", async () => {
const queryClient = new QueryClient({
defaultOptions: {
mutations: {
retry: false,
},
},
});
const { result } = renderHook(() => useRemoveMember(), {
wrapper: ({ children }) => (
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
),
});
// Attempt to mutate without organizationId
result.current.mutate({ userId: "user-123" });
// Should fail with an error about missing organizationId
await waitFor(() => {
expect(result.current.isError).toBe(true);
});
expect(result.current.error).toBeInstanceOf(Error);
expect(result.current.error?.message).toBe("Organization ID is required");
});
});