Priority
P3 - Low Priority
Category
Testing
Description
Server Actions lack comprehensive unit tests, making refactoring risky and bugs harder to catch early.
Current State
- Pins feature: 64 tests, 98.92% coverage ✅
- Other features: 0% coverage ❌
Testing Strategy
1. Test Structure
// features/characters/__tests__/update-character.test.ts
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { updateCharacter, toggleCharacterVisibility, reorderCharacters } from '../methods/update-character';
import { prisma } from '@/shared/lib/prisma';
describe('Character Methods', () => {
beforeEach(() => {
vi.clearAllMocks();
});
describe('updateCharacter', () => {
it('should update character with valid data', async () => {
const mockCharacter = { id: '1', name: 'Updated', userId: 'user1' };
vi.mocked(prisma.character.update).mockResolvedValue(mockCharacter);
// Test implementation
});
it('should reject invalid input', async () => {
await expect(
updateCharacter({ id: '', name: '' })
).rejects.toThrow();
});
it('should verify ownership before update', async () => {
// Test authorization
});
});
describe('toggleCharacterVisibility', () => {
it('should toggle visibility flag', async () => {
// Test implementation
});
});
describe('reorderCharacters', () => {
it('should verify ownership for all characters', async () => {
// Test authorization (P0 fix)
});
it('should reject if any character is not owned', async () => {
// Test security
});
});
});
2. Test Categories
- Unit Tests: Single function behavior
- Integration Tests: Database interactions
- Security Tests: Authorization checks
- Validation Tests: Input validation
3. Coverage Goals
| Feature |
Current |
Target |
| Characters |
0% |
80% |
| Lore |
0% |
80% |
| Gallery |
0% |
80% |
| Comments |
0% |
80% |
| Versions |
0% |
80% |
| Worlds |
0% |
80% |
Implementation Plan
- Set up test database fixtures
- Create test utilities (mock auth, mock prisma)
- Write tests for P0 security fixes first
- Add tests for new features
- Set up CI test reporting
Success Criteria
- All Server Actions have tests
- All authorization paths tested
- All validation rules tested
- Overall coverage > 80%
Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com
Priority
P3 - Low Priority
Category
Testing
Description
Server Actions lack comprehensive unit tests, making refactoring risky and bugs harder to catch early.
Current State
Testing Strategy
1. Test Structure
2. Test Categories
3. Coverage Goals
Implementation Plan
Success Criteria
Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com