jargonsdev / jargonsdev/jargons.dev

Implement Comprehensive Testing Strategy

Aperta
#170 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

:sparkles: enhancement maintainers-only
Lingua principale
MDX
Stelle
56
Fork
45
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

# πŸ§ͺ Testing Plan for jargons.dev

Related to #55

## Overview
The project is an Astro-based dictionary application with GitHub OAuth integration, word editing functionality, and API endpoints. Here's a prioritized testing strategy:

## πŸ“‹ Phase 1: Foundation Tests (High Priority)

### 1. **Utility Functions** (`src/lib/utils/`)
**Why start here**: Pure functions, no dependencies, easy to test and validate core logic.

#### `utils/index.js` - Core Utilities
- βœ… `resolveCookieExpiryDate()` - Date calculations
- βœ… `getRepoParts()` - String parsing for GitHub repos
- βœ… `normalizeAsUrl()` - URL slug generation
- βœ… `isObjectEmpty()` - Object validation
- βœ… `resolveEditorActionFromPathname()` - URL parsing
- βœ… `capitalizeText()` - Text formatting
- βœ… `generateBranchName()` - Git branch naming
- βœ… `buildStatsUrl()` - URL construction
- βœ… `buildWordPathname()` - Path generation
- βœ… `buildWordSlug()` - Slug creation

#### `utils/crypto.js` - Encryption/Decryption
- βœ… `encrypt()` - Data encryption
- βœ… `decrypt()` - Data decryption
- βœ… Encryption/decryption round-trip tests
- βœ… Error handling for invalid inputs

### 2. **Constants & Configuration**
**Why important**: Validates core configuration values used throughout app.

#### `constants.js`
- βœ… Validate all constants are properly defined
- βœ… GitHub repository details structure
- βœ… Labels configuration
- βœ… Environment-specific values

## πŸ“‹ Phase 2: Business Logic Tests (Medium Priority)

### 3. **Word Management** (`src/lib/`)
**Why critical**: Core functionality of the dictionary app.

#### `submit-word.js` - PR Creation Logic
- βœ… PR title generation (new vs edit)
- βœ… PR body template rendering
- βœ… Label assignment logic
- βœ… Error handling for GitHub API failures
- πŸ”„ Mock GitHub API calls

#### `word-editor.js` - Content Management
- βœ… New word creation
- βœ… Existing word updates
- βœ… File path generation
- βœ… Content formatting
- πŸ”„ Mock file operations

#### `branch.js` - Git Operations
- βœ… Branch creation logic
- βœ… Branch deletion logic
- βœ… Branch name validation
- πŸ”„ Mock GitHub API calls

#### `fork.js` - Repository Management
- βœ… Fork creation logic
- βœ… Fork validation
- βœ… Error handling
- πŸ”„ Mock GitHub API calls

## πŸ“‹ Phase 3: API Endpoint Tests (High Priority)

### 4. **API Routes** (`src/pages/api/`)
**Why critical**: External interface, user-facing functionality.

#### `api/dictionary.js` - Main Dictionary API
- βœ… POST endpoint (word submission)
- Authentication validation
- Input sanitization
- Word creation flow
- Word editing flow
- Error responses
- βœ… DELETE endpoint (branch cleanup)
- Authentication validation
- Branch deletion
- Error handling

#### `api/github/oauth/` - Authentication
- βœ… OAuth authorization flow
- βœ… Callback handling
- βœ… Token validation
- βœ… Error scenarios

#### `api/v1/browse/` - Browse Functionality
- βœ… Dictionary browsing endpoints
- βœ… Pagination logic
- βœ… Search functionality
- βœ… Error handling

## πŸ“‹ Phase 4: Component Tests (Medium Priority)

### 5. **React Components** (`src/components/islands/`)
**Why important**: User interface validation, but lower priority due to complexity.

#### Core Interactive Components
- βœ… `search.jsx` - Search functionality
- βœ… `word-editor.jsx` - Word editing interface
- βœ… `profile.jsx` - User profile display
- βœ… `recent-searches.jsx` - Search history

**Test Focus:**
- Component rendering
- User interactions
- State management
- Error boundaries

## πŸ“‹ Phase 5: Integration Tests (Lower Priority)

### 6. **End-to-End Workflows**
**Why later**: Complex setup, but validates complete user journeys.

#### Critical User Flows
- βœ… Complete word submission flow
- βœ… Word editing workflow
- βœ… Authentication flow
- βœ… Search and browse functionality

#### External Service Integration
- βœ… GitHub API integration
- βœ… OAuth flow with GitHub
- βœ… Repository operations

## πŸ› οΈ Testing Infrastructure Recommendations

### **Testing Framework Setup**
```bash
# Recommended testing stack
npm install --save-dev \
vitest \ # Fast unit testing
@testing-library/react \ # React component testing
@testing-library/jest-dom \ # DOM assertions
msw \ # API mocking
@vitest/ui # Testing UI
```

### **Test Configuration Structure**
```
tests/
β”œβ”€β”€ unit/
β”‚ β”œβ”€β”€ utils/
β”‚ β”‚ β”œβ”€β”€ index.test.js
β”‚ β”‚ └── crypto.test.js
β”‚ β”œβ”€β”€ word-management/
β”‚ β”‚ β”œβ”€β”€ submit-word.test.js
β”‚ β”‚ β”œβ”€β”€ word-editor.test.js
β”‚ β”‚ β”œβ”€β”€ branch.test.js
β”‚ β”‚ └── fork.test.js
β”‚ └── constants/
β”‚ └── constants.test.js
β”œβ”€β”€ integration/
β”‚ β”œβ”€β”€ api/
β”‚ β”‚ β”œβ”€β”€ dictionary.test.js
β”‚ β”‚ └── github-oauth.test.js
β”‚ └── components/
β”‚ β”œβ”€β”€ search.test.jsx
β”‚ └── word-editor.test.jsx
β”œβ”€β”€ e2e/
β”‚ β”œβ”€β”€ word-submission.test.js
β”‚ └── authentication.test.js
β”œβ”€β”€ fixtures/
β”‚ β”œβ”€β”€ sample-words.js
β”‚ └── mock-responses.js
└── __mocks__/
β”œβ”€β”€ github-api.js
└── crypto.js
```

### **Priority Implementation Order**
1. **Week 1**: Utility functions + Constants (Phase 1)
2. **Week 2**: Core business logic (Phase 2)
3. **Week 3**: API endpoints (Phase 3)
4. **Week 4**: Components + Integration (Phases 4-5)

### **Testing Best Practices for This Project**
- Mock all GitHub API calls to avoid rate limits
- Use test fixtures for consistent word content
- Test error scenarios (network failures, auth issues)
- Validate security aspects (encryption, token handling)
- Test cross-platform compatibility (Windows/Mac/Linux)

## 🎯 Success Criteria

### **Coverage Goals**
- 90%+ coverage for utility functions
- 80%+ coverage for core business logic
- 70%+ coverage for API endpoints
- 60%+ coverage for React components

### **Quality Gates**
- All tests must pass before merging
- No console errors during test runs
- Performance tests for critical paths
- Security validation for auth flows

### **Maintenance Strategy**
- Tests updated with each new feature
- Regular test suite performance reviews
- Automated test execution in CI/CD
- Test documentation kept current

This plan focuses on the most critical and testable parts first, building confidence in the core functionality before moving to more complex integration scenarios.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu β€” evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia esaminando gli entry point elencati in src/lib/utils/, src/lib/ e src/pages/api/, quindi determina se la configurazione proposta di Vitest esiste giΓ . Confronta le prioritΓ  delle fasi 1–5 con la struttura attuale dei test e gli script del progetto. L'attivitΓ  Γ¨ completata quando Γ¨ stato concordato l'ambito, sono stati implementati i test per le fasi selezionate e i quality gate vengono superati.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
github, javascript, nodejs, react
Ambito
api, authentication, frontend, testing-qa
Tipo di issue
FunzionalitΓ 
DifficoltΓ 
5/5
Tempo stimato
PiΓΉ di una settimana
Stato di attivitΓ 
Ferma
Chiarezza
Da chiarire
IdoneitΓ  per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.