c408e1818f
* feat: #333 load language from backend configuration * feat(settings): sync language with user configs api * Update __test__/features/Settings/SettingsPage.test.tsx Co-authored-by: Lê Nhân Phụng <lenhanphung@Phung-Mac-M4.local> Co-authored-by: Benoit TELLIER <btellier@linagora.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
77 lines
2.0 KiB
TypeScript
77 lines
2.0 KiB
TypeScript
import { clientConfig } from "../../../src/features/User/oidcAuth";
|
|
import {
|
|
getOpenPaasUser,
|
|
updateUserConfigurations,
|
|
} from "../../../src/features/User/userAPI";
|
|
import { api } from "../../../src/utils/apiUtils";
|
|
|
|
jest.mock("../../../src/utils/apiUtils");
|
|
|
|
clientConfig.url = "https://example.com";
|
|
|
|
describe("getOpenPaasUser", () => {
|
|
it("should fetch and return user data", async () => {
|
|
const mockUser = { id: "123", name: "OpenPaas User" };
|
|
|
|
(api.get as jest.Mock).mockReturnValue({
|
|
json: jest.fn().mockResolvedValue(mockUser),
|
|
});
|
|
|
|
const result = await getOpenPaasUser();
|
|
|
|
expect(api.get).toHaveBeenCalledWith("api/user");
|
|
expect(result).toEqual(mockUser);
|
|
});
|
|
});
|
|
|
|
describe("updateUserConfigurations", () => {
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
});
|
|
|
|
it("should PATCH configurations with language update", async () => {
|
|
const mockResponse = { status: 204 };
|
|
(api.patch as jest.Mock).mockResolvedValue(mockResponse);
|
|
|
|
await updateUserConfigurations({ language: "vi" });
|
|
|
|
expect(api.patch).toHaveBeenCalledWith("api/configurations?scope=user", {
|
|
json: [
|
|
{
|
|
name: "core",
|
|
configurations: [{ name: "language", value: "vi" }],
|
|
},
|
|
],
|
|
});
|
|
});
|
|
|
|
it("should PATCH configurations with multiple updates", async () => {
|
|
const mockResponse = { status: 204 };
|
|
(api.patch as jest.Mock).mockResolvedValue(mockResponse);
|
|
|
|
await updateUserConfigurations({
|
|
language: "fr",
|
|
timezone: "Europe/Paris",
|
|
});
|
|
|
|
expect(api.patch).toHaveBeenCalledWith("api/configurations?scope=user", {
|
|
json: [
|
|
{
|
|
name: "core",
|
|
configurations: [
|
|
{ name: "language", value: "fr" },
|
|
{ name: "timezone", value: "Europe/Paris" },
|
|
],
|
|
},
|
|
],
|
|
});
|
|
});
|
|
|
|
it("should handle empty updates without calling API", async () => {
|
|
const result = await updateUserConfigurations({});
|
|
|
|
expect(api.patch).not.toHaveBeenCalled();
|
|
expect(result).toEqual({ status: 204 });
|
|
});
|
|
});
|