Add comprehensive draft services test suite and API fixes (v2.23.0)

- Fix DraftPickService to send full model body on PATCH (API requirement)
- Fix DraftListService to use client-side sorting (API doesn't support sort param)
- Fix parameter names: round_start/end -> pick_round_start/end
- Add 53 tests covering DraftService, DraftPickService, DraftListService
- Add draft model tests for DraftData, DraftPick, DraftList
- Add OpenAPI spec URL to CLAUDE.md for API reference

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Cal Corum 2025-12-09 15:11:51 -06:00
parent d44685e2c5
commit 5a5da37c9c
5 changed files with 1460 additions and 7 deletions

View File

@ -32,6 +32,12 @@ This file provides comprehensive guidance to Claude Code (claude.ai/code) when w
- **[commands/voice/CLAUDE.md](commands/voice/CLAUDE.md)** - Voice channel management commands (/voice-channel) - **[commands/voice/CLAUDE.md](commands/voice/CLAUDE.md)** - Voice channel management commands (/voice-channel)
- **[commands/help/CLAUDE.md](commands/help/CLAUDE.md)** - Help system commands (/help, /help-create, /help-edit, /help-delete, /help-list) - **[commands/help/CLAUDE.md](commands/help/CLAUDE.md)** - Help system commands (/help, /help-create, /help-edit, /help-delete, /help-list)
### API Reference
- **SBA Database API OpenAPI Spec**: https://sba.manticorum.com/api/openapi.json
- Use `WebFetch` to retrieve current endpoint definitions
- ~80+ endpoints covering players, teams, stats, transactions, draft, etc.
- Always fetch fresh rather than relying on cached/outdated specs
## 🏗️ Project Overview ## 🏗️ Project Overview
**Discord Bot v2.0** is a comprehensive Discord bot for managing a Strat-o-Matic Baseball Association (SBA) fantasy league. Built with discord.py and modern async Python patterns. **Discord Bot v2.0** is a comprehensive Discord bot for managing a Strat-o-Matic Baseball Association (SBA) fantasy league. Built with discord.py and modern async Python patterns.

View File

@ -1 +1 @@
2.22.0 2.23.0

View File

@ -85,11 +85,15 @@ class DraftListService(BaseService[DraftList]):
try: try:
params = [ params = [
('season', str(season)), ('season', str(season)),
('team_id', str(team_id)), ('team_id', str(team_id))
('sort', 'rank-asc') # Order by priority # NOTE: API does not support 'sort' param - results must be sorted client-side
] ]
entries = await self.get_all_items(params=params) entries = await self.get_all_items(params=params)
# Sort by rank client-side (API doesn't support sort parameter)
entries.sort(key=lambda e: e.rank)
logger.debug(f"Found {len(entries)} draft list entries for team {team_id}") logger.debug(f"Found {len(entries)} draft list entries for team {team_id}")
return entries return entries

View File

@ -91,8 +91,8 @@ class DraftPickService(BaseService[DraftPick]):
params = [ params = [
('season', str(season)), ('season', str(season)),
('owner_team_id', str(team_id)), ('owner_team_id', str(team_id)),
('round_start', str(round_start)), ('pick_round_start', str(round_start)),
('round_end', str(round_end)), ('pick_round_end', str(round_end)),
('sort', 'order-asc') ('sort', 'order-asc')
] ]
@ -260,6 +260,9 @@ class DraftPickService(BaseService[DraftPick]):
""" """
Update a pick with player selection. Update a pick with player selection.
NOTE: The API PATCH endpoint requires the full DraftPickModel body,
so we must first GET the pick, then send the complete model back.
Args: Args:
pick_id: Draft pick database ID pick_id: Draft pick database ID
player_id: Player ID being selected player_id: Player ID being selected
@ -268,7 +271,21 @@ class DraftPickService(BaseService[DraftPick]):
Updated DraftPick instance or None if update failed Updated DraftPick instance or None if update failed
""" """
try: try:
update_data = {'player_id': player_id} # First, get the current pick to retrieve all required fields
current_pick = await self.get_by_id(pick_id)
if not current_pick:
logger.error(f"Pick #{pick_id} not found")
return None
# Build full model for PATCH (API requires complete DraftPickModel)
update_data = {
'overall': current_pick.overall,
'round': current_pick.round,
'origowner_id': current_pick.origowner_id,
'owner_id': current_pick.owner_id,
'season': current_pick.season,
'player_id': player_id # The field we're updating
}
updated_pick = await self.patch(pick_id, update_data) updated_pick = await self.patch(pick_id, update_data)
if updated_pick: if updated_pick:
@ -286,6 +303,9 @@ class DraftPickService(BaseService[DraftPick]):
""" """
Clear player selection from a pick (for admin wipe operations). Clear player selection from a pick (for admin wipe operations).
NOTE: The API PATCH endpoint requires the full DraftPickModel body,
so we must first GET the pick, then send the complete model back.
Args: Args:
pick_id: Draft pick database ID pick_id: Draft pick database ID
@ -293,7 +313,21 @@ class DraftPickService(BaseService[DraftPick]):
Updated DraftPick instance with player cleared, or None if failed Updated DraftPick instance with player cleared, or None if failed
""" """
try: try:
update_data = {'player_id': None} # First, get the current pick to retrieve all required fields
current_pick = await self.get_by_id(pick_id)
if not current_pick:
logger.error(f"Pick #{pick_id} not found")
return None
# Build full model for PATCH (API requires complete DraftPickModel)
update_data = {
'overall': current_pick.overall,
'round': current_pick.round,
'origowner_id': current_pick.origowner_id,
'owner_id': current_pick.owner_id,
'season': current_pick.season,
'player_id': None # Clear the player selection
}
updated_pick = await self.patch(pick_id, update_data) updated_pick = await self.patch(pick_id, update_data)
if updated_pick: if updated_pick:

1409
tests/test_services_draft.py Normal file

File diff suppressed because it is too large Load Diff