feat: #333 load language from backend configuration (#377)

* 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>
This commit is contained in:
lenhanphung
2025-12-02 16:06:11 +07:00
committed by GitHub
parent 541a681e17
commit c408e1818f
7 changed files with 364 additions and 51 deletions
+56 -2
View File
@@ -1,12 +1,15 @@
import { clientConfig } from "../../../src/features/User/oidcAuth";
import { getOpenPaasUser } from "../../../src/features/User/userAPI";
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("getOpenPaasUserId", () => {
describe("getOpenPaasUser", () => {
it("should fetch and return user data", async () => {
const mockUser = { id: "123", name: "OpenPaas User" };
@@ -20,3 +23,54 @@ describe("getOpenPaasUserId", () => {
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 });
});
});