mirror of
https://github.com/StanGirard/quivr.git
synced 2024-12-15 13:42:08 +03:00
68642afbb8
* feat: add chat api * refactor(MicButton): move related hook * feat: add nock http call example * test(useChatApi): add unit tests
29 lines
765 B
TypeScript
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 });
|
|
});
|
|
});
|