// Copyright (c) 2026 Gordon Bolton. MIT License. /** * @vitest-environment jsdom * Tests for client/src/state.js * * Verifies the structure and initial values of the state object. * This ensures the Ombi-related state fields are properly defined. */ import { state } from '../../client/src/state.js'; describe('state object', () => { it('has ombiBaseUrl field initialized to null', () => { expect(state).toHaveProperty('ombiBaseUrl'); expect(state.ombiBaseUrl).toBeNull(); }); it('has ombiRequests field initialized to null', () => { expect(state).toHaveProperty('ombiRequests'); expect(state.ombiRequests).toBeNull(); }); it('has ombiWebhook field with correct structure', () => { expect(state).toHaveProperty('ombiWebhook'); expect(state.ombiWebhook).toEqual({ enabled: false, triggers: { requestAvailable: false, requestApproved: false, requestDeclined: false, requestPending: false, requestProcessing: false }, stats: null }); }); it('has ombiWebhook triggers with all required fields', () => { const { triggers } = state.ombiWebhook; expect(triggers).toHaveProperty('requestAvailable'); expect(triggers).toHaveProperty('requestApproved'); expect(triggers).toHaveProperty('requestDeclined'); expect(triggers).toHaveProperty('requestPending'); expect(triggers).toHaveProperty('requestProcessing'); }); it('has all Ombi trigger fields initialized to false', () => { const { triggers } = state.ombiWebhook; expect(triggers.requestAvailable).toBe(false); expect(triggers.requestApproved).toBe(false); expect(triggers.requestDeclined).toBe(false); expect(triggers.requestPending).toBe(false); expect(triggers.requestProcessing).toBe(false); }); it('has ombiWebhook stats initialized to null', () => { expect(state.ombiWebhook.stats).toBeNull(); }); it('has ombiWebhook enabled initialized to false', () => { expect(state.ombiWebhook.enabled).toBe(false); }); }); // --------------------------------------------------------------------------- // Skipped tests with explanations // --------------------------------------------------------------------------- describe.skip('frontend API functions (enableOmbiWebhook, testOmbiWebhook)', () => { it('enableOmbiWebhook makes POST request to /api/ombi/webhook/enable', () => { // Skipped because: // 1. These functions make actual fetch calls to backend endpoints // 2. They depend on the global state object (csrfToken) // 3. The backend endpoints are already tested in tests/integration/ombi.test.js // 4. Testing would require mocking fetch and state, which adds complexity // TODO: Could be added later with proper mocking infrastructure }); it('testOmbiWebhook makes POST request to /api/ombi/webhook/test', () => { // Same reasoning as above }); }); describe.skip('frontend UI functions (webhooks.js Ombi functions)', () => { it('renderWebhookStatus renders Ombi webhook status correctly', () => { // Skipped because: // 1. The renderWebhookStatus function is tightly coupled to the DOM // 2. It requires extensive DOM setup (multiple elements with specific IDs) // 3. It depends on the global state object // 4. The logic is straightforward (conditional rendering based on state) // 5. Integration testing via E2E would be more appropriate // TODO: Could be added later with proper DOM mocking or E2E tests }); it('enableOmbiWebhook UI handler calls API and updates state', () => { // Same reasoning as above }); it('testOmbiWebhook UI handler calls API and updates state', () => { // Same reasoning as above }); });