Files
ReadMeABook/tests/helpers/prisma.ts
T
kikootwo 94dbaf073b Add backend unit test framework and modularize settings UI
Introduced a Vitest-based backend unit testing framework with supporting scripts, helpers, and GitHub Actions integration. Refactored the admin settings page to a modular architecture, splitting monolithic logic into feature-specific tabs and hooks for improved maintainability and testability. Updated documentation to reflect the new testing setup and settings architecture, and added new dependencies for testing utilities.
2026-01-28 11:41:59 -05:00

51 lines
1.3 KiB
TypeScript

/**
* Component: Prisma Mock Factory
* Documentation: documentation/backend/database.md
*/
import { vi } from 'vitest';
type PrismaModelMock = {
findMany: ReturnType<typeof vi.fn>;
findFirst: ReturnType<typeof vi.fn>;
findUnique: ReturnType<typeof vi.fn>;
create: ReturnType<typeof vi.fn>;
update: ReturnType<typeof vi.fn>;
updateMany: ReturnType<typeof vi.fn>;
upsert: ReturnType<typeof vi.fn>;
delete: ReturnType<typeof vi.fn>;
deleteMany: ReturnType<typeof vi.fn>;
count: ReturnType<typeof vi.fn>;
};
const createModelMock = (): PrismaModelMock => ({
findMany: vi.fn(),
findFirst: vi.fn(),
findUnique: vi.fn(),
create: vi.fn(() => Promise.resolve({})),
update: vi.fn(),
updateMany: vi.fn(),
upsert: vi.fn(),
delete: vi.fn(),
deleteMany: vi.fn(),
count: vi.fn(),
});
export const createPrismaMock = () => ({
configuration: createModelMock(),
user: createModelMock(),
request: createModelMock(),
audiobook: createModelMock(),
downloadHistory: createModelMock(),
plexLibrary: createModelMock(),
audibleCache: createModelMock(),
job: createModelMock(),
jobEvent: createModelMock(),
scheduledJob: createModelMock(),
bookDateConfig: createModelMock(),
bookDateRecommendation: createModelMock(),
bookDateSwipe: createModelMock(),
$queryRaw: vi.fn(),
$disconnect: vi.fn(),
});