mirror of
https://github.com/kikootwo/ReadMeABook.git
synced 2026-06-02 20:30:10 +00:00
94dbaf073b
Introduced a Vitest-based backend unit testing framework with supporting scripts, helpers, and GitHub Actions integration. Refactored the admin settings page to a modular architecture, splitting monolithic logic into feature-specific tabs and hooks for improved maintainability and testability. Updated documentation to reflect the new testing setup and settings architecture, and added new dependencies for testing utilities.
63 lines
1.8 KiB
TypeScript
63 lines
1.8 KiB
TypeScript
/**
|
|
* Component: Library Service Factory Tests
|
|
* Documentation: documentation/features/audiobookshelf-integration.md
|
|
*/
|
|
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
import { clearLibraryServiceCache, getLibraryService } from '@/lib/services/library';
|
|
|
|
const MockPlexService = vi.hoisted(() => class MockPlexService {});
|
|
const MockAbsService = vi.hoisted(() => class MockAbsService {});
|
|
|
|
const configServiceMock = vi.hoisted(() => ({
|
|
getBackendMode: vi.fn(),
|
|
}));
|
|
|
|
vi.mock('@/lib/services/config.service', () => ({
|
|
getConfigService: () => configServiceMock,
|
|
}));
|
|
|
|
vi.mock('@/lib/services/library/PlexLibraryService', () => ({
|
|
PlexLibraryService: MockPlexService,
|
|
}));
|
|
|
|
vi.mock('@/lib/services/library/AudiobookshelfLibraryService', () => ({
|
|
AudiobookshelfLibraryService: MockAbsService,
|
|
}));
|
|
|
|
describe('Library service factory', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
clearLibraryServiceCache();
|
|
});
|
|
|
|
it('returns Plex service when backend mode is plex', async () => {
|
|
configServiceMock.getBackendMode.mockResolvedValue('plex');
|
|
|
|
const service = await getLibraryService();
|
|
|
|
expect(service).toBeInstanceOf(MockPlexService);
|
|
});
|
|
|
|
it('returns cached service when mode is unchanged', async () => {
|
|
configServiceMock.getBackendMode.mockResolvedValue('plex');
|
|
|
|
const first = await getLibraryService();
|
|
const second = await getLibraryService();
|
|
|
|
expect(first).toBe(second);
|
|
});
|
|
|
|
it('switches to Audiobookshelf service when mode changes', async () => {
|
|
configServiceMock.getBackendMode
|
|
.mockResolvedValueOnce('plex')
|
|
.mockResolvedValueOnce('audiobookshelf');
|
|
|
|
const first = await getLibraryService();
|
|
const second = await getLibraryService();
|
|
|
|
expect(first).toBeInstanceOf(MockPlexService);
|
|
expect(second).toBeInstanceOf(MockAbsService);
|
|
});
|
|
});
|