import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import { JellyfinClient } from '../../../../src/app/clients/jellyfin/JellyfinClient'; describe('JellyfinClient', () => { const fetchMock = vi.fn(); beforeEach(() => { vi.stubGlobal('fetch', fetchMock); fetchMock.mockReset(); fetchMock.mockResolvedValue({ ok: true, status: 200, text: async () => JSON.stringify({ Items: [ { Name: 'Dune', ProductionYear: 2021, ProviderIds: { Imdb: 'tt1160419', Tmdb: '438631' }, Genres: ['Sci-Fi'], CommunityRating: 8.0, UserData: { IsFavorite: true, PlayCount: 2 }, }, ], }), }); }); afterEach(() => { vi.unstubAllGlobals(); }); it('getFavoriteMovies requests favorites and maps the response to Movie[]', async () => { const client = new JellyfinClient('http://jellyfin', 'jf-key', 'user-1'); const movies = await client.getFavoriteMovies(); expect(movies).toEqual([ { name: 'Dune', year: 2021, imdbId: 'tt1160419', tmdbId: '438631', genres: ['Sci-Fi'], communityRating: 8.0, isFavorite: true, playCount: 2, }, ]); const [url, init] = fetchMock.mock.calls[0]; expect(url).toContain('/Users/user-1/Items'); expect(url).toContain('IsFavorite=true'); expect(init.headers.Authorization).toBe('MediaBrowser Token="jf-key"'); }); it('getRecentlyWatched requests played items sorted by date', async () => { const client = new JellyfinClient('http://jellyfin', 'jf-key', 'user-1'); await client.getRecentlyWatched(); const [url] = fetchMock.mock.calls[0]; expect(url).toContain('Filters=IsPlayed'); expect(url).toContain('SortBy=DatePlayed'); }); it('getAllMovies requests the full library', async () => { const client = new JellyfinClient('http://jellyfin', 'jf-key', 'user-1'); await client.getAllMovies(); const [url] = fetchMock.mock.calls[0]; expect(url).toContain('Limit=10000'); }); });