jargonsdev / jargonsdev/jargons.dev

Implement Comprehensive Testing Strategy

Open
#170 0 comments 0 reactions 0 assignees View on GitHub
:sparkles: enhancement maintainers-only
Dominant language
MDX
Stars
56
Forks
45
PR merge metrics
No merged PRs in 30d

Description

# πŸ§ͺ 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.

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the listed entry points in src/lib/utils/, src/lib/, and src/pages/api/, then determine whether the proposed Vitest setup already exists. Compare the Phase 1–5 priorities with the current test structure and project scripts. Done means an agreed scope, implemented tests for the selected phases, and passing quality gates.

Written by the indexing model from the issue text.

Assessment

Tech stack
github, javascript, nodejs, react
Domain
api, authentication, frontend, testing-qa
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.