mirror of
https://github.com/FJurmanovic/sugarr.git
synced 2026-11-11 15:51:09 +00:00
Add JellyfinClient
This commit is contained in:
72
test/app/clients/jellyfin/JellyfinClient.test.ts
Normal file
72
test/app/clients/jellyfin/JellyfinClient.test.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
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');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user