mirror of
https://github.com/kikootwo/ReadMeABook.git
synced 2026-06-03 04:40:09 +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:
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Component: Auth Context Test Mock
|
||||
* Documentation: documentation/frontend/routing-auth.md
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { vi } from 'vitest';
|
||||
|
||||
export interface MockUser {
|
||||
id: string;
|
||||
plexId: string;
|
||||
username: string;
|
||||
role: string;
|
||||
email?: string;
|
||||
avatarUrl?: string;
|
||||
authProvider?: string | null;
|
||||
}
|
||||
|
||||
const authState = vi.hoisted(() => ({
|
||||
user: null as MockUser | null,
|
||||
accessToken: null as string | null,
|
||||
isLoading: false,
|
||||
login: vi.fn(),
|
||||
logout: vi.fn(),
|
||||
refreshToken: vi.fn(),
|
||||
setAuthData: vi.fn(),
|
||||
}));
|
||||
|
||||
export const setMockAuthState = (overrides: Partial<typeof authState>) => {
|
||||
Object.assign(authState, overrides);
|
||||
};
|
||||
|
||||
export const resetMockAuthState = () => {
|
||||
authState.user = null;
|
||||
authState.accessToken = null;
|
||||
authState.isLoading = false;
|
||||
authState.login.mockReset();
|
||||
authState.logout.mockReset();
|
||||
authState.refreshToken.mockReset();
|
||||
authState.setAuthData.mockReset();
|
||||
};
|
||||
|
||||
vi.mock('@/contexts/AuthContext', () => ({
|
||||
useAuth: () => authState,
|
||||
AuthProvider: ({ children }: { children: React.ReactNode }) =>
|
||||
React.createElement(React.Fragment, null, children),
|
||||
}));
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Component: Next Navigation Test Mock
|
||||
* Documentation: documentation/frontend/routing-auth.md
|
||||
*/
|
||||
|
||||
import { vi } from 'vitest';
|
||||
|
||||
const router = vi.hoisted(() => ({
|
||||
push: vi.fn(),
|
||||
replace: vi.fn(),
|
||||
prefetch: vi.fn(),
|
||||
refresh: vi.fn(),
|
||||
back: vi.fn(),
|
||||
forward: vi.fn(),
|
||||
}));
|
||||
|
||||
let pathname = '/';
|
||||
let searchParams = new URLSearchParams();
|
||||
|
||||
export const routerMock = router;
|
||||
|
||||
export const setMockPathname = (value: string) => {
|
||||
pathname = value;
|
||||
};
|
||||
|
||||
export const setMockSearchParams = (value: string | URLSearchParams) => {
|
||||
searchParams = typeof value === 'string' ? new URLSearchParams(value) : value;
|
||||
};
|
||||
|
||||
export const resetMockRouter = () => {
|
||||
router.push.mockReset();
|
||||
router.replace.mockReset();
|
||||
router.prefetch.mockReset();
|
||||
router.refresh.mockReset();
|
||||
router.back.mockReset();
|
||||
router.forward.mockReset();
|
||||
pathname = '/';
|
||||
searchParams = new URLSearchParams();
|
||||
};
|
||||
|
||||
vi.mock('next/navigation', () => ({
|
||||
useRouter: () => router,
|
||||
usePathname: () => pathname,
|
||||
useSearchParams: () => searchParams,
|
||||
redirect: vi.fn(),
|
||||
notFound: vi.fn(),
|
||||
}));
|
||||
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* Component: Frontend Test Render Helpers
|
||||
* Documentation: documentation/frontend/components.md
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { render, RenderOptions } from '@testing-library/react';
|
||||
import { SWRConfig, type SWRConfiguration } from 'swr';
|
||||
import { resetMockAuthState, setMockAuthState, type MockUser } from './mock-auth';
|
||||
import { resetMockRouter, setMockPathname, setMockSearchParams } from './mock-next-navigation';
|
||||
|
||||
type RenderWithProvidersOptions = Omit<RenderOptions, 'wrapper'> & {
|
||||
auth?: Partial<{
|
||||
user: MockUser | null;
|
||||
accessToken: string | null;
|
||||
isLoading: boolean;
|
||||
login: (pinId: number) => Promise<void>;
|
||||
logout: () => void;
|
||||
refreshToken: () => Promise<void>;
|
||||
setAuthData: (user: MockUser, accessToken: string) => void;
|
||||
}>;
|
||||
pathname?: string;
|
||||
searchParams?: string | URLSearchParams;
|
||||
swr?: SWRConfiguration;
|
||||
wrapper?: React.ComponentType<{ children: React.ReactNode }>;
|
||||
};
|
||||
|
||||
const createWrapper = (
|
||||
swr: SWRConfiguration | undefined,
|
||||
Wrapper: RenderWithProvidersOptions['wrapper']
|
||||
) => {
|
||||
return function WrapperComponent({ children }: { children: React.ReactNode }) {
|
||||
const content = Wrapper ? <Wrapper>{children}</Wrapper> : children;
|
||||
|
||||
return (
|
||||
<SWRConfig value={{ provider: () => new Map(), dedupingInterval: 0, ...swr }}>
|
||||
{content}
|
||||
</SWRConfig>
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
export const renderWithProviders = (
|
||||
ui: React.ReactElement,
|
||||
options: RenderWithProvidersOptions = {}
|
||||
) => {
|
||||
resetMockAuthState();
|
||||
resetMockRouter();
|
||||
|
||||
if (options.auth) {
|
||||
setMockAuthState(options.auth);
|
||||
}
|
||||
|
||||
if (options.pathname) {
|
||||
setMockPathname(options.pathname);
|
||||
}
|
||||
|
||||
if (options.searchParams) {
|
||||
setMockSearchParams(options.searchParams);
|
||||
}
|
||||
|
||||
const { wrapper, swr, ...renderOptions } = options;
|
||||
|
||||
return render(ui, {
|
||||
wrapper: createWrapper(swr, wrapper),
|
||||
...renderOptions,
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user