import { Prisma } from '@prisma/client' export const mockPrisma = { user: { findFirst: jest.fn(), findUnique: jest.fn(), create: jest.fn(), update: jest.fn(), delete: jest.fn(), }, account: { findMany: jest.fn(), findUnique: jest.fn(), create: jest.fn(), update: jest.fn(), delete: jest.fn(), }, security: { findMany: jest.fn(), findUnique: jest.fn(), create: jest.fn(), update: jest.fn(), delete: jest.fn(), }, transaction: { findMany: jest.fn(), findUnique: jest.fn(), create: jest.fn(), update: jest.fn(), delete: jest.fn(), count: jest.fn(), }, position: { findMany: jest.fn(), findUnique: jest.fn(), create: jest.fn(), update: jest.fn(), delete: jest.fn(), }, exchangeRate: { findMany: jest.fn(), findUnique: jest.fn(), create: jest.fn(), update: jest.fn(), delete: jest.fn(), }, $transaction: jest.fn((callback) => callback(mockPrisma)), $connect: jest.fn(), $disconnect: jest.fn(), } export const resetMockPrisma = () => { Object.values(mockPrisma).forEach((module) => { if (typeof module === 'object') { Object.values(module).forEach((fn) => { if (typeof fn === 'function') { ;(fn as jest.Mock).mockReset() } }) } }) } export const createMockPosition = (overrides: Partial<{ id: string accountId: string symbol: string quantity: Prisma.Decimal averageCost: Prisma.Decimal currency: string }> = {}) => ({ id: 'pos-1', accountId: 'acc-1', symbol: 'AAPL', quantity: new Prisma.Decimal('10'), averageCost: new Prisma.Decimal('150'), currency: 'USD', updatedAt: new Date(), ...overrides, }) export const createMockAccount = (overrides: Partial<{ id: string userId: string name: string marketType: 'US' | 'CN' | 'HK' | 'CRYPTO' baseCurrency: string balance: Prisma.Decimal }> = {}) => ({ id: 'acc-1', userId: 'user-1', name: 'Test Account', marketType: 'US' as const, baseCurrency: 'USD', balance: new Prisma.Decimal('10000'), createdAt: new Date(), updatedAt: new Date(), ...overrides, }) export const createMockTransaction = (overrides: Partial<{ id: string accountId: string type: 'BUY' | 'SELL' | 'DEPOSIT' | 'WITHDRAW' | 'DIVIDEND' symbol: string | null quantity: Prisma.Decimal | null price: Prisma.Decimal | null amount: Prisma.Decimal fee: Prisma.Decimal currency: string }> = {}) => ({ id: 'txn-1', accountId: 'acc-1', type: 'BUY' as const, symbol: 'AAPL', quantity: new Prisma.Decimal('10'), price: new Prisma.Decimal('150'), amount: new Prisma.Decimal('1500'), fee: new Prisma.Decimal('1'), networkFee: null, currency: 'USD', exchangeRate: null, notes: null, executedAt: new Date(), createdAt: new Date(), ...overrides, })