13 KiB
Backend Test Plan
Overview
This test plan is designed for iterative execution using sub-agents, with each sub-agent handling a specific phase to avoid exceeding the 300,000 token context limit. Each phase focuses on a distinct subsystem and includes specific test cases and verification steps.
Test Phases
Phase 1: Database & Migration Tests
Scope: Alembic migrations, database schema, model relationships Sub-agent Task: Verify all migrations run correctly and database schema is consistent
Test Cases:
-
Migration 000 (Empty)
- Verify migration exists and is empty
- Check downgrade/upgrade functions exist
-
Migration 001 (Initial User Schema)
- Run migration upgrade
- Verify all 16 tables created:
mtgonline_users(base table)mtgonline_decklist_files(base table)mtgonline_rooms(base table)user_sessionsdeck_versionsgame_replaysreplay_playersgame_outcomesuser_statisticsuser_card_collectioncard_wishlistuser_groupsgroup_membersgroup_chat_messagesuser_networksnetwork_membersuser_preferencesuser_activity_log
- Verify foreign key constraints
- Verify indexes created
- Verify unique constraints
- Run migration downgrade
- Verify all tables dropped
-
Migration 002 (User Deck Building Tables)
- Run migration upgrade
- Verify tables created:
mtgonline_decklist_cardsmtgonline_decklist_precedentsmtgonline_decklist_suggestions
- Verify foreign keys to
mtgonline_decklist_files - Run migration downgrade
- Verify tables dropped
-
Migration 003 (MTG Cards Table)
- Run migration upgrade
- Verify
mtgonline_cardstable created - Verify columns and indexes
- Run migration downgrade
- Verify table dropped
-
Migration 004 (Card Import Table)
- Run migration upgrade
- Verify
mtgonline_card_importstable created - Verify foreign key to
mtgonline_users - Run migration downgrade
- Verify table dropped
-
Schema Consistency Checks
- Verify all foreign keys reference existing tables
- Verify no circular dependencies
- Verify all tables have proper indexes
- Verify unique constraints are valid
Verification: All migrations run successfully in order, schema is consistent, no orphaned foreign keys.
Phase 2: Model Layer Tests
Scope: SQLAlchemy models, relationships, validation Sub-agent Task: Verify all model definitions are correct and consistent
Test Cases:
-
User Data Models (
app/models/user_data.py)- Verify
Usermodel matchesmtgonline_userstable - Verify all columns defined
- Verify relationships defined
- Check for missing fields
- Verify
-
User Deck Models (
app/models/user_deck.py)- Verify
DecklistFile,DecklistCard,DecklistPrecedent,DecklistSuggestionmodels - Verify foreign key relationships
- Verify cascade delete behavior
- Check for missing fields
- Verify
-
Card Import Models (
app/models/user_card_import.py)- Verify
CardImportmodel - Verify foreign key to
mtgonline_users - Check for missing fields
- Verify
-
Game Models (
app/models/game.py)- Verify
Game,GamePlayer,GameCard,GameAction,GameLogmodels - Verify relationships
- Check for missing fields
- Verify
-
MTG Card Models (
app/models/mtg_card.py)- Verify
MtgonlineCard,CardPriceHistorymodels - Verify relationships
- Check for missing fields
- Verify
-
Model Consistency
- Verify all models have proper
__tablename__ - Verify all foreign keys reference correct tables
- Verify all relationships are bidirectional where needed
- Check for missing imports
- Verify model imports in
app/models/__init__.py
- Verify all models have proper
Verification: All models compile without errors, relationships are correct, no missing fields.
Phase 3: Schema Layer Tests
Scope: Pydantic schemas, request/response validation Sub-agent Task: Verify all schema definitions are correct
Test Cases:
-
User Data Schemas (
app/schemas/user_data_schemas.py)- Verify
UserCreate,UserUpdate,UserResponseschemas - Verify all required fields
- Check for missing validation
- Verify
-
User Deck Schemas (
app/schemas/user_deck_schemas.py)- Verify
DecklistFileCreate,DecklistFileUpdate,DecklistFileResponse - Verify
DecklistCardCreate,DecklistCardUpdate,DecklistCardResponse - Verify
DecklistPrecedentCreate,DecklistPrecedentUpdate,DecklistPrecedentResponse - Verify
DecklistSuggestionCreate,DecklistSuggestionUpdate,DecklistSuggestionResponse - Check for missing fields
- Verify
-
Card Import Schemas (
app/schemas/card_import_schemas.py)- Verify
CardImportCreate,CardImportResponse - Verify
CardImportStatusResponse,CardImportSummaryResponse - Check for missing fields
- Verify
-
Game Schemas (
app/schemas/game_schemas.py)- Verify
GameCreate,GameUpdate,GameResponse - Verify
GamePlayerCreate,GamePlayerResponse - Verify
GameCardCreate,GameCardResponse - Verify
GameActionCreate,GameActionResponse - Verify
GameLogCreate,GameLogResponse - Check for missing fields
- Verify
-
MTG Card Schemas (
app/schemas/mtg_card_schemas.py)- Verify
MtgonlineCardCreate,MtgonlineCardUpdate,MtgonlineCardResponse - Verify
CardPriceHistoryCreate,CardPriceHistoryResponse - Check for missing fields
- Verify
-
Schema Consistency
- Verify all schemas have proper
model_config - Verify required vs optional fields
- Check for missing imports
- Verify schema imports in
app/schemas/__init__.py
- Verify all schemas have proper
Verification: All schemas compile without errors, validation rules are correct, no missing fields.
Phase 4: Router Layer Tests
Scope: FastAPI routers, endpoint definitions, dependencies Sub-agent Task: Verify all router definitions are correct
Test Cases:
-
User Data Router (
app/routers/user_data.py)- Verify all endpoints defined
- Verify request/response schemas
- Verify dependencies (auth, etc.)
- Check for missing endpoints
-
Deck Router (
app/routers/decks.py)- Verify all endpoints defined
- Verify request/response schemas
- Verify dependencies
- Check for missing endpoints
-
Card Import Router (
app/routers/card_import.py)- Verify all endpoints defined
- Verify request/response schemas
- Verify dependencies
- Check for missing endpoints
-
Game Router (
app/routers/game.py)- Verify all endpoints defined
- Verify request/response schemas
- Verify dependencies
- Check for missing endpoints
-
MTG Card Router (
app/routers/mtg_card.py)- Verify all endpoints defined
- Verify request/response schemas
- Verify dependencies
- Check for missing endpoints
-
Router Consistency
- Verify all routers imported in
app/main.py - Verify prefix paths are correct
- Verify tag assignments
- Check for missing imports
- Verify all routers imported in
Verification: All routers compile without errors, endpoints are properly defined, no missing imports.
Phase 5: Service Layer Tests
Scope: Business logic, service functions Sub-agent Task: Verify all service implementations are correct
Test Cases:
-
User Service (
app/services/user_service.py)- Verify all functions defined
- Verify function signatures
- Check for missing implementations
-
Deck Service (
app/services/deck_service.py)- Verify all functions defined
- Verify function signatures
- Check for missing implementations
-
Card Import Service (
app/services/card_import_service.py)- Verify all functions defined
- Verify function signatures
- Check for missing implementations
-
Game Service (
app/services/game_service.py)- Verify all functions defined
- Verify function signatures
- Check for missing implementations
-
MTG Card Service (
app/services/mtg_card_service.py)- Verify all functions defined
- Verify function signatures
- Check for missing implementations
-
Service Consistency
- Verify all services imported where needed
- Verify function calls match implementations
- Check for missing imports
Verification: All services compile without errors, functions are properly implemented, no missing imports.
Phase 6: Utility & Helper Tests
Scope: Utility functions, helpers, constants Sub-agent Task: Verify all utility implementations are correct
Test Cases:
-
Auth Utilities (
app/utils/auth.py)- Verify all functions defined
- Verify function signatures
- Check for missing implementations
-
Database Utilities (
app/utils/database.py)- Verify all functions defined
- Verify function signatures
- Check for missing implementations
-
Error Handlers (
app/utils/errors.py)- Verify all exception classes defined
- Verify error codes
- Check for missing exceptions
-
Constants (
app/utils/constants.py)- Verify all constants defined
- Verify constant values
- Check for missing constants
-
Utility Consistency
- Verify all utilities imported where needed
- Verify function calls match implementations
- Check for missing imports
Verification: All utilities compile without errors, functions are properly implemented, no missing imports.
Phase 7: Configuration & Environment Tests
Scope: Settings, environment variables, configuration Sub-agent Task: Verify all configuration is correct
Test Cases:
-
Settings (
app/core/settings.py)- Verify all settings defined
- Verify default values
- Check for missing settings
-
Database Configuration (
app/core/database.py)- Verify database URL configuration
- Verify async/sync engine setup
- Check for missing configuration
-
App Configuration (
app/main.py)- Verify FastAPI app initialization
- Verify middleware setup
- Verify CORS configuration
- Check for missing configuration
-
Environment Consistency
- Verify all settings used in code
- Verify environment variables match settings
- Check for missing configuration
Verification: All configuration compiles without errors, settings are properly defined, no missing configuration.
Phase 8: Integration Tests
Scope: Cross-component integration, API consistency Sub-agent Task: Verify all components work together correctly
Test Cases:
-
Router-Service Integration
- Verify routers call correct service functions
- Verify service functions return correct types
- Check for integration issues
-
Service-Model Integration
- Verify services use correct models
- Verify model operations are correct
- Check for integration issues
-
Schema-Router Integration
- Verify routers use correct schemas
- Verify schemas match request/response
- Check for integration issues
-
Database-Model Integration
- Verify models match database schema
- Verify migrations create correct tables
- Check for integration issues
-
Overall Consistency
- Verify all imports are correct
- Verify all function calls are valid
- Check for circular dependencies
- Verify no orphaned code
Verification: All components integrate correctly, no circular dependencies, all imports valid.
Execution Strategy
Sub-Agent Execution Order:
- Phase 1: Database & Migration Tests
- Phase 2: Model Layer Tests
- Phase 3: Schema Layer Tests
- Phase 4: Router Layer Tests
- Phase 5: Service Layer Tests
- Phase 6: Utility & Helper Tests
- Phase 7: Configuration & Environment Tests
- Phase 8: Integration Tests
Context Management:
- Each sub-agent handles one phase at a time
- Sub-agents return only findings and issues
- Main agent aggregates results and coordinates fixes
- Maximum context usage per sub-agent: ~50,000 tokens
Verification Criteria:
- All files compile without syntax errors
- All imports resolve correctly
- All function signatures match across components
- All foreign keys reference existing tables
- All schemas have proper validation
- All routers have proper dependencies
- No circular dependencies
- No orphaned code
Issue Reporting:
Each sub-agent should report:
- Critical Issues: Missing files, broken imports, syntax errors
- Consistency Issues: Mismatched types, missing fields, incorrect references
- Recommendations: Improvements, missing features, best practices
Summary
This test plan provides a systematic approach to verifying the entire backend system by breaking it down into 8 manageable phases. Each phase can be executed by a sub-agent independently, ensuring comprehensive coverage while staying within context limits. The plan focuses on consistency, correctness, and completeness of the codebase.