From c19309a8284f92ec84986e7a9bd15ff2651cbcef Mon Sep 17 00:00:00 2001 From: gnezim Date: Fri, 17 Apr 2026 00:16:21 +0300 Subject: [PATCH] Add getAppSettings API function --- src/shared/api/appSettings.test.ts | 24 ++++++++++++++++++++++++ src/shared/api/appSettings.ts | 27 +++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 src/shared/api/appSettings.test.ts create mode 100644 src/shared/api/appSettings.ts diff --git a/src/shared/api/appSettings.test.ts b/src/shared/api/appSettings.test.ts new file mode 100644 index 00000000..7e9174da --- /dev/null +++ b/src/shared/api/appSettings.test.ts @@ -0,0 +1,24 @@ +import { describe, it, expect, vi } from "vitest"; +import { getAppSettings } from "./appSettings.js"; +import type { ApiClient } from "./client.js"; + +describe("getAppSettings", () => { + it("calls /appSettings endpoint", async () => { + const mockResponse = { + uiOptions: { + filter: { + onlineboard: { searchFrom: "2d", searchTo: "14d" }, + schedule: { searchFrom: "30d", searchTo: "30d" }, + }, + }, + }; + const client = { + get: vi.fn().mockResolvedValue(mockResponse), + } as unknown as ApiClient; + + const result = await getAppSettings(client); + + expect(client.get).toHaveBeenCalledWith("/appSettings"); + expect(result).toEqual(mockResponse); + }); +}); diff --git a/src/shared/api/appSettings.ts b/src/shared/api/appSettings.ts new file mode 100644 index 00000000..e0c6d1ca --- /dev/null +++ b/src/shared/api/appSettings.ts @@ -0,0 +1,27 @@ +import type { ApiClient } from "./client.js"; + +export interface AppSettingsFilterOptions { + searchFrom?: string; + searchTo?: string; + timeStep?: string; +} + +export interface AppSettingsResponse { + showDebugVersion?: string; + uiOptions?: { + isTestVersion?: string; + filter?: { + onlineboard?: AppSettingsFilterOptions; + schedule?: AppSettingsFilterOptions; + }; + buttons?: Record; + }; +} + +/** + * Fetch the global UI configuration from the backend. Includes date range + * limits for online-board and schedule searches. + */ +export async function getAppSettings(client: ApiClient): Promise { + return client.get("/appSettings"); +}