mirror of
https://github.com/f/awesome-chatgpt-prompts.git
synced 2026-02-12 07:42:47 +00:00
113 lines
2.4 KiB
TypeScript
113 lines
2.4 KiB
TypeScript
import "@testing-library/jest-dom";
|
|
import { vi, beforeAll, afterAll } from "vitest";
|
|
|
|
// Suppress console.error and console.log during tests to reduce noise
|
|
// These are expected outputs from error handling tests
|
|
const originalConsoleError = console.error;
|
|
const originalConsoleLog = console.log;
|
|
|
|
beforeAll(() => {
|
|
console.error = vi.fn();
|
|
console.log = vi.fn();
|
|
});
|
|
|
|
afterAll(() => {
|
|
console.error = originalConsoleError;
|
|
console.log = originalConsoleLog;
|
|
});
|
|
|
|
// 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: () => {
|
|
return new URLSearchParams();
|
|
},
|
|
usePathname: () => "/",
|
|
useParams: () => ({}),
|
|
redirect: vi.fn(),
|
|
notFound: vi.fn(),
|
|
}));
|
|
|
|
// Mock next/headers
|
|
vi.mock("next/headers", () => {
|
|
const getCookieMock = vi.fn().mockReturnValue(null);
|
|
const setCookieMock = vi.fn();
|
|
const deleteCookieMock = vi.fn();
|
|
|
|
return {
|
|
cookies: () => ({
|
|
get: getCookieMock,
|
|
set: setCookieMock,
|
|
delete: deleteCookieMock,
|
|
}),
|
|
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: {},
|
|
})
|
|
),
|
|
}));
|