quivr/frontend/lib/api/user/__tests__/useUserApi.test.ts
Mamadou DICKO 7532b558c7
feat: add user level open ai key management (#805)
* feat: add user user identity table

* feat: add user openai api key input

* feat: add encryption missing message

* chore: log more details about 422 errors

* docs(API): update api creation path

* feat: use user openai key if defined
2023-08-01 09:24:57 +02:00

49 lines
1.3 KiB
TypeScript

import { renderHook } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { useUserApi } from "../useUserApi";
import { UserIdentityUpdatableProperties } from "../user";
const axiosPutMock = vi.fn(() => ({}));
const axiosGetMock = vi.fn(() => ({}));
vi.mock("@/lib/hooks", () => ({
useAxios: () => ({
axiosInstance: {
put: axiosPutMock,
get: axiosGetMock,
},
}),
}));
describe("useUserApi", () => {
it("should call updateUserIdentity with the correct parameters", async () => {
const {
result: {
current: { updateUserIdentity },
},
} = renderHook(() => useUserApi());
const userUpdatableProperties: UserIdentityUpdatableProperties = {
openai_api_key: "sk-xxx",
};
await updateUserIdentity(userUpdatableProperties);
expect(axiosPutMock).toHaveBeenCalledTimes(1);
expect(axiosPutMock).toHaveBeenCalledWith(
`/user/identity`,
userUpdatableProperties
);
});
it("should call getUserIdentity with the correct parameters", async () => {
const {
result: {
current: { getUserIdentity },
},
} = renderHook(() => useUserApi());
await getUserIdentity();
expect(axiosGetMock).toHaveBeenCalledTimes(1);
expect(axiosGetMock).toHaveBeenCalledWith(`/user/identity`);
});
});