Files
ReadMeABook/tests/processors/retry-missing-torrents.processor.test.ts
T
kikootwo 94dbaf073b Add backend unit test framework and modularize settings UI
Introduced a Vitest-based backend unit testing framework with supporting scripts, helpers, and GitHub Actions integration. Refactored the admin settings page to a modular architecture, splitting monolithic logic into feature-specific tabs and hooks for improved maintainability and testability. Updated documentation to reflect the new testing setup and settings architecture, and added new dependencies for testing utilities.
2026-01-28 11:41:59 -05:00

46 lines
1.3 KiB
TypeScript

/**
* Component: Retry Missing Torrents Processor Tests
* Documentation: documentation/backend/services/scheduler.md
*/
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { createPrismaMock } from '../helpers/prisma';
import { createJobQueueMock } from '../helpers/job-queue';
const prismaMock = createPrismaMock();
const jobQueueMock = createJobQueueMock();
vi.mock('@/lib/db', () => ({
prisma: prismaMock,
}));
vi.mock('@/lib/services/job-queue.service', () => ({
getJobQueueService: () => jobQueueMock,
}));
describe('processRetryMissingTorrents', () => {
beforeEach(() => {
vi.clearAllMocks();
});
it('queues search jobs for awaiting_search requests', async () => {
prismaMock.request.findMany.mockResolvedValue([
{
id: 'req-1',
audiobook: { id: 'a1', title: 'Book', author: 'Author', audibleAsin: 'ASIN1' },
},
]);
const { processRetryMissingTorrents } = await import('@/lib/processors/retry-missing-torrents.processor');
const result = await processRetryMissingTorrents({ jobId: 'job-1' });
expect(result.success).toBe(true);
expect(jobQueueMock.addSearchJob).toHaveBeenCalledWith(
'req-1',
expect.objectContaining({ id: 'a1', title: 'Book', author: 'Author' })
);
});
});