mirror of
https://github.com/kikootwo/ReadMeABook.git
synced 2026-06-02 20:30:10 +00:00
af0eaceb98
Introduce a provider-based notification system and wire it through the API and admin UI. Added INotificationProvider + notification service implementation and providers (apprise, discord, ntfy, pushover), plus a GET /api/admin/notifications/providers endpoint to expose provider metadata. Refactored code to use provider type strings (removed enum coupling), updated masking/encryption calls, and simplified the test notification endpoint to accept backendId or type+config and call sendToBackend directly. UI: NotificationsTab now fetches provider metadata and renders provider cards and dynamic config forms (fields driven by provider metadata). Added config field rendering, improved backend cards, and edit/delete actions. APIs: New providers route, updated admin notification CRUD routes to validate provider types dynamically, updated test route schema. Added download-client categories POST API to fetch categories from clients and wired postImportCategory handling in download-client routes. Other notable changes: BookDate now fetches Claude models dynamically from Anthropic's Models API; added paginated model fetch helper. Added ALLOW_WEAK_PASSWORD flag exposure to auth providers and password change logic. Doc updates and various tests added/updated. File-organization doc clarifies EPERM fix using stream-based copy.
85 lines
2.4 KiB
TypeScript
85 lines
2.4 KiB
TypeScript
/**
|
|
* Component: Setup Audiobookshelf Step Tests
|
|
* Documentation: documentation/setup-wizard.md
|
|
*/
|
|
|
|
// @vitest-environment jsdom
|
|
|
|
import React, { useState } from 'react';
|
|
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
|
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
import { AudiobookshelfStep } from '@/app/setup/steps/AudiobookshelfStep';
|
|
|
|
const AudiobookshelfHarness = ({
|
|
onNext,
|
|
onBack,
|
|
initialState,
|
|
}: {
|
|
onNext: () => void;
|
|
onBack: () => void;
|
|
initialState?: Partial<React.ComponentProps<typeof AudiobookshelfStep>>;
|
|
}) => {
|
|
const [state, setState] = useState({
|
|
absUrl: 'http://abs.local',
|
|
absApiToken: 'token',
|
|
absLibraryId: '',
|
|
absTriggerScanAfterImport: false,
|
|
absLibraries: [] as { id: string; name: string; itemCount: number }[],
|
|
...initialState,
|
|
});
|
|
|
|
return (
|
|
<AudiobookshelfStep
|
|
{...state}
|
|
onUpdate={(field, value) => setState((prev) => ({ ...prev, [field]: value }))}
|
|
onNext={onNext}
|
|
onBack={onBack}
|
|
/>
|
|
);
|
|
};
|
|
|
|
describe('AudiobookshelfStep', () => {
|
|
afterEach(() => {
|
|
vi.unstubAllGlobals();
|
|
});
|
|
|
|
it('requires library selection after successful test', async () => {
|
|
const fetchMock = vi.fn().mockResolvedValue({
|
|
ok: true,
|
|
json: async () => ({
|
|
success: true,
|
|
libraries: [{ id: 'lib-1', name: 'Main', itemCount: 10 }],
|
|
}),
|
|
});
|
|
vi.stubGlobal('fetch', fetchMock);
|
|
const onNext = vi.fn();
|
|
|
|
render(<AudiobookshelfHarness onNext={onNext} onBack={vi.fn()} />);
|
|
|
|
fireEvent.click(screen.getByRole('button', { name: 'Test Connection' }));
|
|
|
|
await waitFor(() => {
|
|
expect(fetchMock).toHaveBeenCalledWith('/api/setup/test-abs', expect.any(Object));
|
|
});
|
|
|
|
await screen.findByText('Connection successful!');
|
|
|
|
fireEvent.click(screen.getByRole('button', { name: 'Next' }));
|
|
expect(screen.getByText('Please select an audiobook library')).toBeInTheDocument();
|
|
expect(onNext).not.toHaveBeenCalled();
|
|
|
|
fireEvent.click(screen.getByRole('button', { name: 'Test Connection' }));
|
|
await screen.findByText('Connection successful!');
|
|
|
|
const librarySelect = await screen.findByRole('combobox');
|
|
fireEvent.change(librarySelect, { target: { value: 'lib-1' } });
|
|
|
|
await waitFor(() => {
|
|
expect(librarySelect).toHaveValue('lib-1');
|
|
});
|
|
|
|
fireEvent.click(screen.getByRole('button', { name: 'Next' }));
|
|
expect(onNext).toHaveBeenCalled();
|
|
});
|
|
});
|