# Testing ## Current State **No tests exist yet.** The codebase has zero test files — no Go tests, no frontend component tests, no E2E tests. CLAUDE.md references test commands but the infrastructure is not set up. ## Planned Frameworks (from CLAUDE.md) ### Backend (Go) - **Framework**: Go standard library `testing` package - **Command**: `cd backend && go test ./...` - **Package-level**: `cd backend && go test ./internal/api/...` - **No test files exist** (`*_test.go`) ### Frontend - **Unit/Component Testing**: Vitest - Command: `cd frontend && bun vitest` - Not yet installed (missing from `package.json` devDependencies) - **E2E Testing**: Playwright - Command: `cd frontend && bun playwright test` - Not yet installed ## Dependencies Needed ### Frontend (not yet in package.json) ```json { "devDependencies": { "vitest": "^x.x.x", "@testing-library/react": "^x.x.x", "@testing-library/jest-dom": "^x.x.x", "@playwright/test": "^x.x.x" } } ``` ### Backend No additional dependencies needed — Go's `testing` package is built-in. ## Configuration Files Needed | File | Purpose | |------|---------| | `frontend/vitest.config.ts` | Vitest configuration | | `frontend/src/setupTests.ts` | Test environment setup | | `frontend/playwright.config.ts` | E2E test configuration | ## Recommended Test Structure ### Backend ``` backend/ internal/ api/ handlers_test.go # Handler tests (HTTP request/response) router_test.go # Route registration tests auth/ auth_test.go # JWT and bcrypt tests db/ queries_test.go # Database query tests (integration) ``` ### Frontend ``` frontend/ src/ components/ BudgetSetup.test.tsx BillsTracker.test.tsx ... pages/ DashboardPage.test.tsx LoginPage.test.tsx ... hooks/ useAuth.test.ts useBudgets.test.ts lib/ api.test.ts format.test.ts e2e/ auth.spec.ts budget.spec.ts ``` ## Testing Patterns (Inferred from Architecture) ### Backend - **HTTP handler testing**: Use `net/http/httptest` with Chi router - **Database testing**: Integration tests against PostgreSQL (pgxpool can be mocked or use test DB) - **Auth testing**: Test JWT generation/validation, bcrypt hashing - **Context-based**: All handlers use `context.Context` for user ID propagation ### Frontend - **Component testing**: Vitest + React Testing Library - **Hook testing**: `renderHook` from Testing Library - **API mocking**: Mock fetch or use MSW for `/api/*` endpoints - **i18n in tests**: Wrap components with i18next provider ## Priority Test Areas ### Backend (High Priority) 1. Auth flow (register, login, JWT validation, password hashing) 2. Category CRUD (user isolation) 3. Budget operations (carryover calculations, item copying) 4. Database query correctness 5. Middleware (auth required, CORS) ### Frontend (High Priority) 1. Auth flow (login/register forms, state management) 2. Budget selection & display 3. Budget item CRUD 4. Currency formatting 5. i18n language switching 6. Form validation