mirror of
https://github.com/kikootwo/ReadMeABook.git
synced 2026-06-03 12:50:09 +00:00
af0eaceb98
Introduce a provider-based notification system and wire it through the API and admin UI. Added INotificationProvider + notification service implementation and providers (apprise, discord, ntfy, pushover), plus a GET /api/admin/notifications/providers endpoint to expose provider metadata. Refactored code to use provider type strings (removed enum coupling), updated masking/encryption calls, and simplified the test notification endpoint to accept backendId or type+config and call sendToBackend directly. UI: NotificationsTab now fetches provider metadata and renders provider cards and dynamic config forms (fields driven by provider metadata). Added config field rendering, improved backend cards, and edit/delete actions. APIs: New providers route, updated admin notification CRUD routes to validate provider types dynamically, updated test route schema. Added download-client categories POST API to fetch categories from clients and wired postImportCategory handling in download-client routes. Other notable changes: BookDate now fetches Claude models dynamically from Anthropic's Models API; added paginated model fetch helper. Added ALLOW_WEAK_PASSWORD flag exposure to auth providers and password change logic. Doc updates and various tests added/updated. File-organization doc clarifies EPERM fix using stream-based copy.
129 lines
3.9 KiB
TypeScript
129 lines
3.9 KiB
TypeScript
/**
|
|
* Component: Search Indexers Processor Tests
|
|
* Documentation: documentation/backend/services/jobs.md
|
|
*/
|
|
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
import { createPrismaMock } from '../helpers/prisma';
|
|
import { createJobQueueMock } from '../helpers/job-queue';
|
|
|
|
const prismaMock = createPrismaMock();
|
|
const configMock = vi.hoisted(() => ({ get: vi.fn() }));
|
|
const jobQueueMock = createJobQueueMock();
|
|
const prowlarrMock = vi.hoisted(() => ({ search: vi.fn(), searchWithVariations: vi.fn() }));
|
|
|
|
vi.mock('@/lib/db', () => ({
|
|
prisma: prismaMock,
|
|
}));
|
|
|
|
vi.mock('@/lib/services/config.service', () => ({
|
|
getConfigService: () => configMock,
|
|
}));
|
|
|
|
vi.mock('@/lib/services/job-queue.service', () => ({
|
|
getJobQueueService: () => jobQueueMock,
|
|
}));
|
|
|
|
vi.mock('@/lib/integrations/prowlarr.service', () => ({
|
|
getProwlarrService: () => prowlarrMock,
|
|
}));
|
|
|
|
vi.mock('@/lib/integrations/audible.service', () => ({
|
|
getAudibleService: () => ({ getRuntime: vi.fn().mockResolvedValue(null) }),
|
|
}));
|
|
|
|
describe('processSearchIndexers', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
it('marks request awaiting_search when no results found', async () => {
|
|
configMock.get.mockImplementation(async (key: string) => {
|
|
if (key === 'prowlarr_indexers') {
|
|
return JSON.stringify([{ id: 1, name: 'Indexer', protocol: 'torrent', priority: 10, categories: [3030] }]);
|
|
}
|
|
return null;
|
|
});
|
|
prowlarrMock.searchWithVariations.mockResolvedValue([]);
|
|
prismaMock.request.update.mockResolvedValue({});
|
|
|
|
const { processSearchIndexers } = await import('@/lib/processors/search-indexers.processor');
|
|
const result = await processSearchIndexers({
|
|
requestId: 'req-1',
|
|
audiobook: { id: 'a1', title: 'Book', author: 'Author' },
|
|
jobId: 'job-1',
|
|
});
|
|
|
|
expect(result.success).toBe(false);
|
|
expect(prismaMock.request.update).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
data: expect.objectContaining({ status: 'awaiting_search' }),
|
|
})
|
|
);
|
|
});
|
|
|
|
it('queues download job when results are ranked', async () => {
|
|
configMock.get.mockImplementation(async (key: string) => {
|
|
if (key === 'prowlarr_indexers') {
|
|
return JSON.stringify([{ id: 1, name: 'Indexer', protocol: 'torrent', priority: 10, categories: [3030] }]);
|
|
}
|
|
if (key === 'indexer_flag_config') {
|
|
return JSON.stringify([]);
|
|
}
|
|
return null;
|
|
});
|
|
|
|
prowlarrMock.searchWithVariations.mockResolvedValue([
|
|
{
|
|
indexer: 'Indexer',
|
|
indexerId: 1,
|
|
title: 'Book - Author',
|
|
size: 50 * 1024 * 1024,
|
|
seeders: 10,
|
|
publishDate: new Date(),
|
|
downloadUrl: 'magnet:?xt=urn:btih:abc',
|
|
guid: 'guid-1',
|
|
format: 'M4B',
|
|
},
|
|
]);
|
|
|
|
prismaMock.request.update.mockResolvedValue({});
|
|
|
|
const { processSearchIndexers } = await import('@/lib/processors/search-indexers.processor');
|
|
const result = await processSearchIndexers({
|
|
requestId: 'req-2',
|
|
audiobook: { id: 'a2', title: 'Book', author: 'Author' },
|
|
jobId: 'job-2',
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
expect(jobQueueMock.addDownloadJob).toHaveBeenCalledWith(
|
|
'req-2',
|
|
{ id: 'a2', title: 'Book', author: 'Author' },
|
|
expect.objectContaining({ title: 'Book - Author' })
|
|
);
|
|
});
|
|
|
|
it('fails when no indexers are configured', async () => {
|
|
configMock.get.mockResolvedValue(null);
|
|
prismaMock.request.update.mockResolvedValue({});
|
|
|
|
const { processSearchIndexers } = await import('@/lib/processors/search-indexers.processor');
|
|
await expect(
|
|
processSearchIndexers({
|
|
requestId: 'req-3',
|
|
audiobook: { id: 'a3', title: 'Book', author: 'Author' },
|
|
jobId: 'job-3',
|
|
})
|
|
).rejects.toThrow('No indexers configured');
|
|
|
|
expect(prismaMock.request.update).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
data: expect.objectContaining({ status: 'failed' }),
|
|
})
|
|
);
|
|
});
|
|
});
|
|
|
|
|