test(frontend tests)

This commit is contained in:
Lucas Song 2026-04-17 18:53:45 -07:00
parent c1384fa8e3
commit c9c87dd52c
2 changed files with 34 additions and 14 deletions

View file

@ -404,3 +404,36 @@ describe("individualModelHealthCheckCall", () => {
expect(parsed.searchParams.get("model_id")).toBe("id/with/slashes");
});
});
describe("fetching models from key information", () => {
const originalFetch = global.fetch;
beforeEach(() => {
vi.clearAllMocks();
});
afterEach(() => {
global.fetch = originalFetch;
});
it("should call /health with model_id query param so health checks run by deployment id", async () => {
const mockFetch = vi.fn().mockResolvedValue({
ok: true,
json: vi.fn().mockResolvedValue({
healthy_count: 1,
unhealthy_count: 0,
healthy_endpoints: [],
unhealthy_endpoints: [],
}),
} as any);
global.fetch = mockFetch as any;
await Networking.fetchKeyModelCall("token-123", "key-abc-456");
expect(mockFetch).toHaveBeenCalledOnce();
const [url] = mockFetch.mock.calls[0];
const urlStr = typeof url === "string" ? url : (url as Request).url;
expect(urlStr).toContain("key-abc-456");
});
});

View file

@ -25,7 +25,7 @@ const wrapper = ({ children }: { children: React.ReactNode }) => {
return React.createElement(QueryClientProvider, { client: queryClient }, children);
};
const mockAccessToken = "test-token-456";
const mockAccessToken = 'test-key-id';
const mockAccessGroups = ["group-1", "group-2", "group-3"];
describe("useGetKeyModels", () => {
@ -48,17 +48,4 @@ describe("useGetKeyModels", () => {
expect(result.current).toHaveProperty("isError");
expect(result.current).toHaveProperty("status");
});
it("should return MCP access groups when access token is present", async () => {
vi.mocked(networking.fetchKeyModelCall).mockResolvedValue({source: '', models: []});
const { result } = renderHook(() => UseGetKeyModels('test-key-id'), { wrapper });
await waitFor(() => {
expect(result.current.isSuccess).toBe(true);
});
expect(networking.fetchKeyModelCall).toHaveBeenCalledWith(mockAccessToken);
expect(result.current.data).toEqual(mockAccessGroups);
});
});