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
+73 -5
View File
@@ -3,21 +3,89 @@
* Documentation: documentation/README.md
*/
import { beforeAll, afterAll, vi } from 'vitest';
import React from 'react';
import { afterAll, afterEach, beforeAll, vi } from 'vitest';
import '@testing-library/jest-dom';
import { cleanup } from '@testing-library/react';
vi.mock('next/link', () => ({
default: ({ href, children, ...props }: { href: string; children: React.ReactNode }) =>
React.createElement('a', { href, ...props }, children),
}));
vi.mock('next/image', () => ({
default: (props: { src: string | { src: string } }) => {
const resolvedSrc = typeof props.src === 'string' ? props.src : props.src?.src;
return React.createElement('img', { ...props, src: resolvedSrc });
},
}));
beforeAll(() => {
process.env.NODE_ENV = 'test';
process.env.TZ = 'UTC';
(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
if (!globalThis.fetch) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(globalThis as any).fetch = () => {
throw new Error('fetch was called without a mock in tests');
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(globalThis as any).fetch = () => {
throw new Error('fetch was called without a mock in tests');
};
if (!globalThis.requestAnimationFrame) {
globalThis.requestAnimationFrame = (callback: FrameRequestCallback) => {
return setTimeout(() => callback(Date.now()), 0) as unknown as number;
};
}
if (!globalThis.cancelAnimationFrame) {
globalThis.cancelAnimationFrame = (id: number) => {
clearTimeout(id as unknown as NodeJS.Timeout);
};
}
if (!globalThis.IntersectionObserver) {
globalThis.IntersectionObserver = class {
observe() {}
unobserve() {}
disconnect() {}
takeRecords() {
return [];
}
};
}
if (!globalThis.ResizeObserver) {
globalThis.ResizeObserver = class {
observe() {}
unobserve() {}
disconnect() {}
};
}
if (typeof window !== 'undefined') {
window.scrollTo = window.scrollTo || vi.fn();
window.open = window.open || vi.fn();
window.matchMedia = window.matchMedia || ((query: string) => ({
matches: false,
media: query,
addListener: vi.fn(),
removeListener: vi.fn(),
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
}));
}
if (typeof Element !== 'undefined' && !Element.prototype.scrollIntoView) {
Element.prototype.scrollIntoView = vi.fn();
}
});
afterAll(() => {
vi.restoreAllMocks();
});
afterEach(() => {
if (typeof document !== 'undefined') {
cleanup();
}
});