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
@@ -0,0 +1,90 @@
/**
* Component: Protected Route Component Tests
* Documentation: documentation/frontend/routing-auth.md
*/
// @vitest-environment jsdom
import { beforeAll, describe, expect, it } from 'vitest';
import { screen, waitFor } from '@testing-library/react';
import { renderWithProviders } from '../../helpers/render';
import { routerMock } from '../../helpers/mock-next-navigation';
describe('ProtectedRoute', () => {
let ProtectedRoute: typeof import('@/components/auth/ProtectedRoute').ProtectedRoute;
beforeAll(async () => {
({ ProtectedRoute } = await import('@/components/auth/ProtectedRoute'));
});
it('shows loading state while auth is initializing', async () => {
renderWithProviders(
<ProtectedRoute>
<div>Protected Content</div>
</ProtectedRoute>,
{ auth: { isLoading: true } }
);
expect(screen.getByText(/Loading/i)).toBeInTheDocument();
expect(screen.queryByText('Protected Content')).not.toBeInTheDocument();
});
it('redirects unauthenticated users to login with return URL', async () => {
renderWithProviders(
<ProtectedRoute>
<div>Protected Content</div>
</ProtectedRoute>,
{ auth: { user: null, isLoading: false }, pathname: '/requests' }
);
await waitFor(() => {
expect(routerMock.push).toHaveBeenCalledWith('/login?redirect=%2Frequests');
});
expect(screen.queryByText('Protected Content')).not.toBeInTheDocument();
});
it('redirects non-admin users when admin access is required', async () => {
renderWithProviders(
<ProtectedRoute requireAdmin>
<div>Admin Content</div>
</ProtectedRoute>,
{
auth: {
user: {
id: 'user-1',
plexId: 'plex-1',
username: 'reader',
role: 'user',
},
isLoading: false,
},
}
);
await waitFor(() => {
expect(routerMock.push).toHaveBeenCalledWith('/');
});
expect(screen.queryByText('Admin Content')).not.toBeInTheDocument();
});
it('renders children for authenticated admins', async () => {
renderWithProviders(
<ProtectedRoute requireAdmin>
<div>Admin Content</div>
</ProtectedRoute>,
{
auth: {
user: {
id: 'admin-1',
plexId: 'plex-1',
username: 'admin',
role: 'admin',
},
isLoading: false,
},
}
);
expect(screen.getByText('Admin Content')).toBeInTheDocument();
});
});