2.2 KiB
Refactoring Plan for Firehose Blog Controller Tests
Context
Based on context.md, we have a Phoenix blog controller with repetitive validation tests that need refactoring.
Goals
- Extract test helpers to reduce code duplication
- Standardize test naming conventions
- Reorganize tests to follow defensive programming flow
- Add missing negative test coverage
- Create separate contexts for different refactorings
Recommended Planner Agents
1. TestHelperExtractor Agent
Purpose: Handle Smell 1 (Repetitive Validation Tests) and Smell 4 (Redundant Layout Assertions)
Tasks:
- Extract page validation test logic into
test_page_fallback/2helper - Create
assert_has_app_layout/1helper for layout assertions - Move helpers to support module or test case
Context Isolation: This can run in a separate test context without affecting controller logic.
2. TestOrganizer Agent
Purpose: Handle Smell 5 (Test Order) and Smell 3 (Inconsistent Naming)
Tasks:
- Reorder test blocks: validation first, then success cases, then edge cases
- Standardize all test descriptions to follow pattern: "GET /blog/:type/:slug returns [result]"
- Rename describe blocks to follow semantic order
Context Isolation: Pure test organization, no production code changes.
3. CoverageExpander Agent
Purpose: Handle Smell 2 (Missing Negative Tests) and Smell 8 (Edge Cases)
Tasks:
- Add test for unknown blog_id (
/blog/invalid) - Add test for empty page parameter (
?page=) - Add test for very large page numbers
- Add test for invalid blog halt behavior (Smell 6)
Context Isolation: Adds new tests without modifying existing logic.
4. ResponseHelperCreator Agent
Purpose: Handle Smell 7 (Mixed Response Types)
Tasks:
- Create
assert_html/2andassert_json/2helpers - Ensure proper content-type verification
- Update existing tests to use new helpers
Execution Strategy
Run each agent in isolated contexts:
- TestHelperExtractor → creates helper functions
- ResponseHelperCreator → builds response assertions
- TestOrganizer → reorganizes existing structure
- CoverageExpander → adds new test cases
This keeps the main thread clean and allows focused changes per agent.