mirror of
https://github.com/kikootwo/ReadMeABook.git
synced 2026-06-02 20:30:10 +00:00
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:
@@ -110,6 +110,60 @@ describe('Request action routes', () => {
|
||||
expect(jobQueueMock.addSearchJob).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('returns 401 when manual search user is not authenticated', async () => {
|
||||
authRequest.user = null;
|
||||
|
||||
const { POST } = await import('@/app/api/requests/[id]/manual-search/route');
|
||||
const response = await POST({} as any, { params: Promise.resolve({ id: 'req-auth' }) });
|
||||
const payload = await response.json();
|
||||
|
||||
expect(response.status).toBe(401);
|
||||
expect(payload.error).toBe('Unauthorized');
|
||||
});
|
||||
|
||||
it('returns 404 when manual search request is missing', async () => {
|
||||
prismaMock.request.findUnique.mockResolvedValueOnce(null);
|
||||
|
||||
const { POST } = await import('@/app/api/requests/[id]/manual-search/route');
|
||||
const response = await POST({} as any, { params: Promise.resolve({ id: 'req-missing' }) });
|
||||
const payload = await response.json();
|
||||
|
||||
expect(response.status).toBe(404);
|
||||
expect(payload.error).toBe('NotFound');
|
||||
});
|
||||
|
||||
it('returns 403 when manual search request is not owned', async () => {
|
||||
prismaMock.request.findUnique.mockResolvedValueOnce({
|
||||
id: 'req-9',
|
||||
userId: 'user-2',
|
||||
status: 'failed',
|
||||
audiobook: { id: 'ab-1', title: 'Title', author: 'Author', audibleAsin: 'ASIN' },
|
||||
});
|
||||
|
||||
const { POST } = await import('@/app/api/requests/[id]/manual-search/route');
|
||||
const response = await POST({} as any, { params: Promise.resolve({ id: 'req-9' }) });
|
||||
const payload = await response.json();
|
||||
|
||||
expect(response.status).toBe(403);
|
||||
expect(payload.error).toBe('Forbidden');
|
||||
});
|
||||
|
||||
it('returns 400 when manual search status is not eligible', async () => {
|
||||
prismaMock.request.findUnique.mockResolvedValueOnce({
|
||||
id: 'req-10',
|
||||
userId: 'user-1',
|
||||
status: 'downloading',
|
||||
audiobook: { id: 'ab-1', title: 'Title', author: 'Author', audibleAsin: 'ASIN' },
|
||||
});
|
||||
|
||||
const { POST } = await import('@/app/api/requests/[id]/manual-search/route');
|
||||
const response = await POST({} as any, { params: Promise.resolve({ id: 'req-10' }) });
|
||||
const payload = await response.json();
|
||||
|
||||
expect(response.status).toBe(400);
|
||||
expect(payload.error).toBe('ValidationError');
|
||||
});
|
||||
|
||||
it('selects a torrent and queues download', async () => {
|
||||
authRequest.json.mockResolvedValue({ torrent: { title: 'Torrent', size: 100 } });
|
||||
prismaMock.request.findUnique.mockResolvedValueOnce({
|
||||
@@ -134,6 +188,134 @@ describe('Request action routes', () => {
|
||||
expect(jobQueueMock.addDownloadJob).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('returns 401 when user is not authenticated', async () => {
|
||||
authRequest.user = null;
|
||||
|
||||
const { POST } = await import('@/app/api/requests/[id]/select-torrent/route');
|
||||
const response = await POST({} as any, { params: Promise.resolve({ id: 'req-auth' }) });
|
||||
const payload = await response.json();
|
||||
|
||||
expect(response.status).toBe(401);
|
||||
expect(payload.error).toBe('Unauthorized');
|
||||
});
|
||||
|
||||
it('returns 400 when torrent data is missing', async () => {
|
||||
authRequest.json.mockResolvedValue({});
|
||||
|
||||
const { POST } = await import('@/app/api/requests/[id]/select-torrent/route');
|
||||
const response = await POST({} as any, { params: Promise.resolve({ id: 'req-missing-torrent' }) });
|
||||
const payload = await response.json();
|
||||
|
||||
expect(response.status).toBe(400);
|
||||
expect(payload.error).toBe('ValidationError');
|
||||
});
|
||||
|
||||
it('returns 404 when request is not found', async () => {
|
||||
authRequest.json.mockResolvedValue({ torrent: { title: 'Torrent', size: 100 } });
|
||||
prismaMock.request.findUnique.mockResolvedValueOnce(null);
|
||||
|
||||
const { POST } = await import('@/app/api/requests/[id]/select-torrent/route');
|
||||
const response = await POST({} as any, { params: Promise.resolve({ id: 'req-missing' }) });
|
||||
const payload = await response.json();
|
||||
|
||||
expect(response.status).toBe(404);
|
||||
expect(payload.error).toBe('NotFound');
|
||||
});
|
||||
|
||||
it('returns 403 when user does not own the request', async () => {
|
||||
authRequest.json.mockResolvedValue({ torrent: { title: 'Torrent', size: 100 } });
|
||||
prismaMock.request.findUnique.mockResolvedValueOnce({
|
||||
id: 'req-4',
|
||||
userId: 'user-2',
|
||||
status: 'awaiting_search',
|
||||
audiobook: { id: 'ab-2', title: 'Title', author: 'Author' },
|
||||
} as any);
|
||||
|
||||
const { POST } = await import('@/app/api/requests/[id]/select-torrent/route');
|
||||
const response = await POST({} as any, { params: Promise.resolve({ id: 'req-4' }) });
|
||||
const payload = await response.json();
|
||||
|
||||
expect(response.status).toBe(403);
|
||||
expect(payload.error).toBe('Forbidden');
|
||||
});
|
||||
|
||||
it('returns 403 when request is awaiting approval', async () => {
|
||||
authRequest.json.mockResolvedValue({ torrent: { title: 'Torrent', size: 100 } });
|
||||
prismaMock.request.findUnique.mockResolvedValueOnce({
|
||||
id: 'req-5',
|
||||
userId: 'user-1',
|
||||
status: 'awaiting_approval',
|
||||
audiobook: { id: 'ab-2', title: 'Title', author: 'Author' },
|
||||
} as any);
|
||||
|
||||
const { POST } = await import('@/app/api/requests/[id]/select-torrent/route');
|
||||
const response = await POST({} as any, { params: Promise.resolve({ id: 'req-5' }) });
|
||||
const payload = await response.json();
|
||||
|
||||
expect(response.status).toBe(403);
|
||||
expect(payload.error).toBe('AwaitingApproval');
|
||||
});
|
||||
|
||||
it('stores selected torrent when approval is required by global setting', async () => {
|
||||
authRequest.json.mockResolvedValue({ torrent: { title: 'Torrent', size: 100 } });
|
||||
configState.values.set('auto_approve_requests', 'false');
|
||||
prismaMock.request.findUnique.mockResolvedValueOnce({
|
||||
id: 'req-6',
|
||||
userId: 'user-1',
|
||||
status: 'awaiting_search',
|
||||
audiobook: { id: 'ab-3', title: 'Title', author: 'Author' },
|
||||
} as any);
|
||||
prismaMock.user.findUnique.mockResolvedValueOnce({
|
||||
id: 'user-1',
|
||||
role: 'user',
|
||||
autoApproveRequests: null,
|
||||
plexUsername: 'plexuser',
|
||||
} as any);
|
||||
prismaMock.request.update.mockResolvedValueOnce({
|
||||
id: 'req-6',
|
||||
status: 'awaiting_approval',
|
||||
audiobook: { title: 'Title', author: 'Author' },
|
||||
} as any);
|
||||
|
||||
const { POST } = await import('@/app/api/requests/[id]/select-torrent/route');
|
||||
const response = await POST({} as any, { params: Promise.resolve({ id: 'req-6' }) });
|
||||
const payload = await response.json();
|
||||
|
||||
expect(payload.success).toBe(true);
|
||||
expect(payload.message).toMatch(/approval/i);
|
||||
expect(jobQueueMock.addDownloadJob).not.toHaveBeenCalled();
|
||||
expect(jobQueueMock.addNotificationJob).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('auto-approves when global setting is missing and user has no preference', async () => {
|
||||
authRequest.json.mockResolvedValue({ torrent: { title: 'Torrent', size: 100 } });
|
||||
prismaMock.request.findUnique.mockResolvedValueOnce({
|
||||
id: 'req-7',
|
||||
userId: 'user-1',
|
||||
status: 'awaiting_search',
|
||||
audiobook: { id: 'ab-4', title: 'Title', author: 'Author' },
|
||||
} as any);
|
||||
prismaMock.user.findUnique.mockResolvedValueOnce({
|
||||
id: 'user-1',
|
||||
role: 'user',
|
||||
autoApproveRequests: null,
|
||||
plexUsername: 'plexuser',
|
||||
} as any);
|
||||
prismaMock.request.update.mockResolvedValueOnce({
|
||||
id: 'req-7',
|
||||
status: 'downloading',
|
||||
audiobook: { title: 'Title', author: 'Author' },
|
||||
} as any);
|
||||
|
||||
const { POST } = await import('@/app/api/requests/[id]/select-torrent/route');
|
||||
const response = await POST({} as any, { params: Promise.resolve({ id: 'req-7' }) });
|
||||
const payload = await response.json();
|
||||
|
||||
expect(payload.success).toBe(true);
|
||||
expect(jobQueueMock.addDownloadJob).toHaveBeenCalled();
|
||||
expect(jobQueueMock.addNotificationJob).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('returns error when ebook sidecar is disabled', async () => {
|
||||
configState.values.set('ebook_sidecar_enabled', 'false');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user