Add RadarrClient

This commit is contained in:
2026-08-12 21:05:58 +02:00
parent 4e483557d7
commit 8e908408cd
5 changed files with 169 additions and 0 deletions

View File

@@ -0,0 +1,64 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { RadarrClient } from '../../../../src/app/clients/radarr/RadarrClient';
describe('RadarrClient', () => {
const fetchMock = vi.fn();
beforeEach(() => {
vi.stubGlobal('fetch', fetchMock);
fetchMock.mockReset();
});
afterEach(() => {
vi.unstubAllGlobals();
});
it('lookup resolves TMDb metadata and fills in client-configured fields', async () => {
fetchMock.mockResolvedValue({
ok: true,
status: 200,
text: async () => JSON.stringify({ title: 'Dune', tmdbId: 438631 }),
});
const client = new RadarrClient('http://radarr', 'radarr-key', 4, '/movies');
const movie = await client.lookup(438631);
expect(movie).toEqual({
title: 'Dune',
tmdbId: 438631,
qualityProfileId: 4,
rootFolderPath: '/movies',
monitored: true,
addOptions: { searchForMovie: true },
});
expect(fetchMock.mock.calls[0][1].headers['X-Api-Key']).toBe('radarr-key');
});
it('addMovie treats HTTP 400 (already exists) as success', async () => {
fetchMock.mockResolvedValue({ ok: false, status: 400, text: async () => '' });
const client = new RadarrClient('http://radarr', 'radarr-key', 4, '/movies');
await expect(
client.addMovie({
title: 'Dune',
tmdbId: 438631,
qualityProfileId: 4,
rootFolderPath: '/movies',
monitored: true,
addOptions: { searchForMovie: true },
})
).resolves.toBeUndefined();
});
it('getExisting returns the full Radarr library', async () => {
fetchMock.mockResolvedValue({
ok: true,
status: 200,
text: async () => JSON.stringify([{ title: 'Dune', tmdbId: 438631 }]),
});
const client = new RadarrClient('http://radarr', 'radarr-key', 4, '/movies');
const existing = await client.getExisting();
expect(existing[0].tmdbId).toBe(438631);
});
});