193c1a7166
* [#337] added timezone loading from backend * [#337] changed data structure to allow patching timezone while keeping other datetime params value * [#337] fixed gap, event create modale sync with settings and added checkbox * [#337] isBrowserDefaultTimezone is set to true when API return null timezone Co-authored-by: Camille Moussu <cmoussu@linagora.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: "datetime", value: { timeZone: "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 });
|
|
});
|
|
});
|