mirror of
https://github.com/QuivrHQ/quivr.git
synced 2024-12-25 16:13:47 +03:00
7532b558c7
* 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
49 lines
1.3 KiB
TypeScript
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`);
|
|
});
|
|
});
|