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
+61
View File
@@ -6,6 +6,7 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';
import {
absRequest,
deleteABSItem,
getABSLibraries,
getABSLibraryItems,
getABSRecentItems,
@@ -56,6 +57,21 @@ describe('Audiobookshelf API client', () => {
expect(fetchMock).toHaveBeenCalledWith('http://abs/api/status', expect.any(Object));
});
it('throws when ABS responds with an error status', async () => {
configServiceMock.get.mockImplementation(async (key: string) => {
if (key === 'audiobookshelf.server_url') return 'http://abs';
if (key === 'audiobookshelf.api_token') return 'token';
return null;
});
fetchMock.mockResolvedValue({
ok: false,
status: 401,
statusText: 'Unauthorized',
});
await expect(absRequest('/status')).rejects.toThrow('ABS API error: 401 Unauthorized');
});
it('maps library responses and search queries', async () => {
configServiceMock.get.mockImplementation(async (key: string) => {
if (key === 'audiobookshelf.server_url') return 'http://abs';
@@ -91,6 +107,20 @@ describe('Audiobookshelf API client', () => {
expect(fetchMock.mock.calls[3][0]).toBe('http://abs/api/libraries/lib-1/search?q=hello%20world');
});
it('returns an empty array when search results are missing', async () => {
configServiceMock.get.mockImplementation(async (key: string) => {
if (key === 'audiobookshelf.server_url') return 'http://abs';
if (key === 'audiobookshelf.api_token') return 'token';
return null;
});
fetchMock.mockResolvedValue({
ok: true,
json: async () => ({}),
});
expect(await searchABSItems('lib-1', 'missing')).toEqual([]);
});
it('triggers library scan using plain text responses', async () => {
configServiceMock.get.mockImplementation(async (key: string) => {
if (key === 'audiobookshelf.server_url') return 'http://abs';
@@ -144,4 +174,35 @@ describe('Audiobookshelf API client', () => {
await expect(triggerABSItemMatch('item-1', 'ASIN123')).resolves.toBeUndefined();
});
it('deletes a library item successfully', async () => {
configServiceMock.get.mockImplementation(async (key: string) => {
if (key === 'audiobookshelf.server_url') return 'http://abs';
if (key === 'audiobookshelf.api_token') return 'token';
return null;
});
fetchMock.mockResolvedValue({
ok: true,
});
await expect(deleteABSItem('item-1')).resolves.toBeUndefined();
expect(fetchMock).toHaveBeenCalledWith('http://abs/api/items/item-1', expect.objectContaining({
method: 'DELETE',
}));
});
it('throws when delete fails', async () => {
configServiceMock.get.mockImplementation(async (key: string) => {
if (key === 'audiobookshelf.server_url') return 'http://abs';
if (key === 'audiobookshelf.api_token') return 'token';
return null;
});
fetchMock.mockResolvedValue({
ok: false,
status: 500,
statusText: 'Boom',
});
await expect(deleteABSItem('item-1')).rejects.toThrow('ABS API error: 500 Boom');
});
});