Add Unit and Integration Tests for Core Features
Description
The project currently has no automated test suite. Adding tests is critical for maintaining code quality, preventing regressions, and enabling confident refactoring as the project grows.
What Needs to Be Done
1. Setup Testing Infrastructure
- Install testing dependencies:
vitest, @vitejs/plugin-react, jsdom, @testing-library/react, @testing-library/jest-dom
- Configure
vitest.config.ts for Next.js
- Add test scripts to
package.json: "test": "vitest", "test:coverage": "vitest --coverage"
2. Priority Test Areas
API Routes (Integration Tests)
src/app/api/generate/route.ts — Test flashcard generation with mocked Gemini API
src/app/api/decks/route.ts — Test CRUD operations
src/app/api/decks/save/route.ts — Test saving flashcards to deck
src/app/api/study/start/route.ts — Test study session creation
Service Layer (Unit Tests)
src/lib/services/flashcard.service.ts — Test CRUD and spaced repetition logic
src/lib/services/subscription.service.ts — Test plan limit checking
src/lib/services/payment.service.ts — Test order creation and verification
Components (Component Tests)
src/components/study/StudyMode.tsx — Test card flip, navigation, difficulty tracking
src/components/flashcards/FlashcardViewer.tsx — Test card display and interaction
src/components/Navbar.tsx — Test navigation links and responsive behavior
3. CI Integration
- Add test step to existing GitHub Actions workflows
- Ensure tests run on every PR
Files to Create
vitest.config.ts
src/__tests__/ directory structure mirroring src/
- Test files:
*.test.ts or *.test.tsx
Acceptance Criteria
Add Unit and Integration Tests for Core Features
Description
The project currently has no automated test suite. Adding tests is critical for maintaining code quality, preventing regressions, and enabling confident refactoring as the project grows.
What Needs to Be Done
1. Setup Testing Infrastructure
vitest,@vitejs/plugin-react,jsdom,@testing-library/react,@testing-library/jest-domvitest.config.tsfor Next.jspackage.json:"test": "vitest","test:coverage": "vitest --coverage"2. Priority Test Areas
API Routes (Integration Tests)
src/app/api/generate/route.ts— Test flashcard generation with mocked Gemini APIsrc/app/api/decks/route.ts— Test CRUD operationssrc/app/api/decks/save/route.ts— Test saving flashcards to decksrc/app/api/study/start/route.ts— Test study session creationService Layer (Unit Tests)
src/lib/services/flashcard.service.ts— Test CRUD and spaced repetition logicsrc/lib/services/subscription.service.ts— Test plan limit checkingsrc/lib/services/payment.service.ts— Test order creation and verificationComponents (Component Tests)
src/components/study/StudyMode.tsx— Test card flip, navigation, difficulty trackingsrc/components/flashcards/FlashcardViewer.tsx— Test card display and interactionsrc/components/Navbar.tsx— Test navigation links and responsive behavior3. CI Integration
Files to Create
vitest.config.tssrc/__tests__/directory structure mirroringsrc/*.test.tsor*.test.tsxAcceptance Criteria