quivr/frontend/lib/api/chat/__tests__/useChatApi.http.test.ts
Mamadou DICKO 68642afbb8
Frontend/test/chat 2 (#516)
* feat: add chat api

* refactor(MicButton): move related hook

* feat: add nock http call example

* test(useChatApi): add unit tests
2023-07-05 13:33:26 +02:00

29 lines
765 B
TypeScript

import { renderHook } from "@testing-library/react";
import { describe, expect, it } from "vitest";
import { getNock } from "../../tests/getNock";
import { useChatApi } from "../useChatApi";
getNock().options("/chat").reply(200);
describe("useChatApi", () => {
it("should make http request while creating chat", async () => {
const chatName = "Test Chat";
const scope = getNock().post("/chat").reply(200, { chat_name: chatName });
const {
result: {
current: { createChat },
},
} = renderHook(() => useChatApi());
const createdChat = await createChat(chatName);
//Check that the endpoint was called
expect(scope.isDone()).toBe(true);
expect(createdChat).toMatchObject({ chat_name: chatName });
});
});