mirror of
https://github.com/f/awesome-chatgpt-prompts.git
synced 2026-02-12 15:52:47 +00:00
Add comprehensive testing infrastructure with vitest, React Testing Library, and jsdom. Includes tests for: - Utility functions (cn, isChromeBrowser, date formatting, JSON utils) - Variable detection module (7 pattern types, conversion, false positives) - API routes (health check, user registration with validation/auth) 127 tests passing covering critical functionality.
90 lines
1.9 KiB
TypeScript
90 lines
1.9 KiB
TypeScript
import "@testing-library/jest-dom";
|
|
import { vi } from "vitest";
|
|
|
|
// Mock environment variables
|
|
process.env.NEXTAUTH_SECRET = "test-secret";
|
|
process.env.NEXTAUTH_URL = "http://localhost:3000";
|
|
process.env.DATABASE_URL = "postgresql://test:test@localhost:5432/test";
|
|
|
|
// Mock next/navigation
|
|
vi.mock("next/navigation", () => ({
|
|
useRouter: () => ({
|
|
push: vi.fn(),
|
|
replace: vi.fn(),
|
|
refresh: vi.fn(),
|
|
back: vi.fn(),
|
|
forward: vi.fn(),
|
|
prefetch: vi.fn(),
|
|
}),
|
|
useSearchParams: () => new URLSearchParams(),
|
|
usePathname: () => "/",
|
|
useParams: () => ({}),
|
|
redirect: vi.fn(),
|
|
notFound: vi.fn(),
|
|
}));
|
|
|
|
// Mock next/headers
|
|
vi.mock("next/headers", () => ({
|
|
cookies: () => ({
|
|
get: vi.fn(),
|
|
set: vi.fn(),
|
|
delete: vi.fn(),
|
|
}),
|
|
headers: () => new Headers(),
|
|
}));
|
|
|
|
// Mock next-intl
|
|
vi.mock("next-intl", () => ({
|
|
useTranslations: () => (key: string) => key,
|
|
useLocale: () => "en",
|
|
getTranslations: () => Promise.resolve((key: string) => key),
|
|
}));
|
|
|
|
// Mock Prisma client
|
|
vi.mock("@/lib/db", () => ({
|
|
db: {
|
|
user: {
|
|
findUnique: vi.fn(),
|
|
findFirst: vi.fn(),
|
|
findMany: vi.fn(),
|
|
create: vi.fn(),
|
|
update: vi.fn(),
|
|
delete: vi.fn(),
|
|
count: vi.fn(),
|
|
},
|
|
prompt: {
|
|
findUnique: vi.fn(),
|
|
findFirst: vi.fn(),
|
|
findMany: vi.fn(),
|
|
create: vi.fn(),
|
|
update: vi.fn(),
|
|
delete: vi.fn(),
|
|
count: vi.fn(),
|
|
},
|
|
category: {
|
|
findUnique: vi.fn(),
|
|
findFirst: vi.fn(),
|
|
findMany: vi.fn(),
|
|
create: vi.fn(),
|
|
update: vi.fn(),
|
|
delete: vi.fn(),
|
|
},
|
|
$queryRaw: vi.fn(),
|
|
$executeRaw: vi.fn(),
|
|
$transaction: vi.fn(),
|
|
},
|
|
}));
|
|
|
|
// Mock config
|
|
vi.mock("@/lib/config", () => ({
|
|
getConfig: vi.fn(() =>
|
|
Promise.resolve({
|
|
auth: {
|
|
allowRegistration: true,
|
|
providers: [],
|
|
},
|
|
features: {},
|
|
})
|
|
),
|
|
}));
|