Add series fields to audiobooks and update related logic

Introduces 'series' and 'seriesPart' fields to the Audiobook model and database schema. Updates API routes, file organization, and path template utilities to support series metadata. Enhances chapter merging logic, improves notification backend testing, and expands test coverage for admin and API routes.
This commit is contained in:
kikootwo
2026-01-22 15:56:55 -05:00
parent dc7e557694
commit 31bca0052f
105 changed files with 10384 additions and 75 deletions
+48 -1
View File
@@ -13,6 +13,7 @@ const requireAuthMock = vi.hoisted(() => vi.fn());
const requireAdminMock = vi.hoisted(() => vi.fn());
const configServiceMock = vi.hoisted(() => ({ get: vi.fn() }));
const qbittorrentMock = vi.hoisted(() => ({ getTorrent: vi.fn() }));
const sabnzbdMock = vi.hoisted(() => ({ getNZB: vi.fn() }));
vi.mock('@/lib/db', () => ({
prisma: prismaMock,
@@ -32,7 +33,7 @@ vi.mock('@/lib/integrations/qbittorrent.service', () => ({
}));
vi.mock('@/lib/integrations/sabnzbd.service', () => ({
getSABnzbdService: async () => ({ getNZB: vi.fn() }),
getSABnzbdService: async () => sabnzbdMock,
}));
describe('Admin downloads route', () => {
@@ -65,6 +66,52 @@ describe('Admin downloads route', () => {
expect(payload.downloads[0].speed).toBe(123);
expect(payload.downloads[0].torrentName).toBe('Torrent');
});
it('returns formatted active downloads for SABnzbd', async () => {
prismaMock.request.findMany.mockResolvedValueOnce([
{
id: 'req-2',
status: 'downloading',
progress: 20,
updatedAt: new Date(),
audiobook: { title: 'Title', author: 'Author' },
user: { plexUsername: 'user' },
downloadHistory: [{ nzbId: 'nzb-1', torrentName: 'NZB', downloadStatus: 'downloading' }],
},
]);
configServiceMock.get.mockResolvedValueOnce('sabnzbd');
sabnzbdMock.getNZB.mockResolvedValueOnce({ downloadSpeed: 555, timeLeft: 120 });
const { GET } = await import('@/app/api/admin/downloads/active/route');
const response = await GET({} as any);
const payload = await response.json();
expect(payload.downloads[0].speed).toBe(555);
expect(payload.downloads[0].eta).toBe(120);
});
it('returns defaults when download client lookup fails', async () => {
prismaMock.request.findMany.mockResolvedValueOnce([
{
id: 'req-3',
status: 'downloading',
progress: 80,
updatedAt: new Date(),
audiobook: { title: 'Title', author: 'Author' },
user: { plexUsername: 'user' },
downloadHistory: [{ torrentHash: 'hash', torrentName: 'Torrent', downloadStatus: 'downloading' }],
},
]);
configServiceMock.get.mockResolvedValueOnce('qbittorrent');
qbittorrentMock.getTorrent.mockRejectedValueOnce(new Error('client down'));
const { GET } = await import('@/app/api/admin/downloads/active/route');
const response = await GET({} as any);
const payload = await response.json();
expect(payload.downloads[0].speed).toBe(0);
expect(payload.downloads[0].eta).toBeNull();
});
});