From 51c4ecbf4ee0786c9b4d6e43f317399c576748fb Mon Sep 17 00:00:00 2001 From: Ho Ngoc Hai Date: Sun, 12 Apr 2026 20:15:33 +0700 Subject: [PATCH] fix(web): resolve 7 TypeScript errors and 2 failing test files Add vitest/globals types to web tsconfig to fix TS2593 errors in 7 test files. Fix pricing and subscription test mocks to include all required lucide-react icons and module dependencies (payment-api, auth-store, next-intl, i18n/navigation). All 66 test files now pass (593 tests), typecheck clean, lint clean. Co-Authored-By: Paperclip --- .../dashboard/__tests__/subscription.spec.tsx | 34 +++++++++++++++++++ .../(public)/__tests__/pricing.spec.tsx | 19 ++++++++++- apps/web/tsconfig.json | 1 + 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/apps/web/app/[locale]/(dashboard)/dashboard/__tests__/subscription.spec.tsx b/apps/web/app/[locale]/(dashboard)/dashboard/__tests__/subscription.spec.tsx index 2d922ca..318105d 100644 --- a/apps/web/app/[locale]/(dashboard)/dashboard/__tests__/subscription.spec.tsx +++ b/apps/web/app/[locale]/(dashboard)/dashboard/__tests__/subscription.spec.tsx @@ -32,6 +32,30 @@ const mockBilling = { payments: [], }; +vi.mock('next-intl', () => ({ + useTranslations: () => (key: string) => key, + useLocale: () => 'vi', + NextIntlClientProvider: ({ children }: { children: React.ReactNode }) => children, +})); + +vi.mock('@/i18n/navigation', () => ({ + Link: ({ children, href, ...props }: { children: React.ReactNode; href: string; [key: string]: unknown }) => ( + {children} + ), + useRouter: () => ({ push: vi.fn(), replace: vi.fn() }), + usePathname: () => '/dashboard/subscription', + redirect: vi.fn(), +})); + +vi.mock('lucide-react', () => ({ + AlertCircle: () => , + Check: () => , + CreditCard: () => , + Loader2: () => , + Smartphone: () => , + Wallet: () => , +})); + vi.mock('@/lib/hooks/use-subscription', () => ({ usePlans: vi.fn(() => ({ data: mockPlans, isLoading: false })), useBillingHistory: vi.fn(() => ({ data: mockBilling, isLoading: false })), @@ -43,9 +67,19 @@ vi.mock('@/lib/subscription-api', () => ({ subscriptionApi: { createSubscription: vi.fn(), upgradeSubscription: vi.fn(), + createCheckout: vi.fn(), }, })); +vi.mock('@/lib/payment-api', () => ({ + createPayment: vi.fn(), + getPaymentMethods: vi.fn(() => []), +})); + +vi.mock('@/lib/auth-store', () => ({ + useAuthStore: vi.fn(() => ({ user: null, token: null })), +})); + vi.mock('@tanstack/react-query', async (importOriginal) => { const actual = (await importOriginal()) as Record; return { diff --git a/apps/web/app/[locale]/(public)/__tests__/pricing.spec.tsx b/apps/web/app/[locale]/(public)/__tests__/pricing.spec.tsx index f6ffd77..30c0abd 100644 --- a/apps/web/app/[locale]/(public)/__tests__/pricing.spec.tsx +++ b/apps/web/app/[locale]/(public)/__tests__/pricing.spec.tsx @@ -43,10 +43,15 @@ vi.mock('@/i18n/navigation', () => ({ })); vi.mock('lucide-react', () => ({ + AlertCircle: () => , Check: () => , + CreditCard: () => , Crown: () => , + Loader2: () => , Rocket: () => , Shield: () => , + Smartphone: () => , + Wallet: () => , X: () => , Zap: () => , })); @@ -78,9 +83,21 @@ const mockPlans = [ vi.mock('@/lib/hooks/use-subscription', () => ({ usePlans: vi.fn(() => ({ data: mockPlans, isLoading: false, error: null })), + useBillingHistory: vi.fn(() => ({ data: [], isLoading: false, error: null })), })); -vi.mock('@/lib/subscription-api', () => ({})); +vi.mock('@/lib/subscription-api', () => ({ + subscriptionApi: { createCheckout: vi.fn() }, +})); + +vi.mock('@/lib/payment-api', () => ({ + createPayment: vi.fn(), + getPaymentMethods: vi.fn(() => []), +})); + +vi.mock('@/lib/auth-store', () => ({ + useAuthStore: vi.fn(() => ({ user: null, token: null })), +})); import PricingPage from '../pricing/page'; diff --git a/apps/web/tsconfig.json b/apps/web/tsconfig.json index 14d2bcf..c37324c 100644 --- a/apps/web/tsconfig.json +++ b/apps/web/tsconfig.json @@ -12,6 +12,7 @@ "name": "next" } ], + "types": ["vitest/globals"], "paths": { "@/*": ["./*"] },