Skip to content

Add Unit and Integration Tests for Core Features #119

Description

@Suraj-kumar00

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

  • Testing framework (Vitest) configured and working
  • At least 3 API route tests
  • At least 3 service layer unit tests
  • At least 2 component tests
  • Tests pass in CI pipeline
  • Test coverage report available

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesttestingAdding or improving automated tests

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions