mirror of
https://github.com/FJurmanovic/sugarr.git
synced 2026-11-11 07:41:08 +00:00
Add Health/Recommendations/Request/Webhook controllers
This commit is contained in:
36
test/app/controllers/RequestController.test.ts
Normal file
36
test/app/controllers/RequestController.test.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import Fastify from 'fastify';
|
||||
import { RequestController } from '../../../src/app/controllers/RequestController';
|
||||
import type { AppConfig } from '../../../src/app/config/AppConfig';
|
||||
import type { RadarrClient } from '../../../src/app/clients/radarr/RadarrClient';
|
||||
|
||||
describe('RequestController', () => {
|
||||
it('returns 400 when Radarr is not enabled', async () => {
|
||||
const app = Fastify();
|
||||
new RequestController({ RADARR_ENABLED: false } as AppConfig, undefined).register(app);
|
||||
|
||||
const res = await app.inject({ method: 'POST', url: '/recommendations/request', payload: { tmdb_id: 1 } });
|
||||
expect(res.statusCode).toBe(400);
|
||||
});
|
||||
|
||||
it('returns 400 when tmdb_id is missing', async () => {
|
||||
const app = Fastify();
|
||||
new RequestController({ RADARR_ENABLED: true } as AppConfig, {} as RadarrClient).register(app);
|
||||
|
||||
const res = await app.inject({ method: 'POST', url: '/recommendations/request', payload: {} });
|
||||
expect(res.statusCode).toBe(400);
|
||||
});
|
||||
|
||||
it('looks up and adds the movie, returning its title', async () => {
|
||||
const radarr = {
|
||||
lookup: vi.fn().mockResolvedValue({ title: 'Dune', tmdbId: 1 }),
|
||||
addMovie: vi.fn().mockResolvedValue(undefined),
|
||||
} as unknown as RadarrClient;
|
||||
const app = Fastify();
|
||||
new RequestController({ RADARR_ENABLED: true } as AppConfig, radarr).register(app);
|
||||
|
||||
const res = await app.inject({ method: 'POST', url: '/recommendations/request', payload: { tmdb_id: 1 } });
|
||||
expect(res.statusCode).toBe(200);
|
||||
expect(res.json()).toEqual({ requested: true, title: 'Dune' });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user