CLAUDE: Fix test_resolve_play_success unit test
Fixed failing test caught by pre-commit hook. The test was not properly mocking dependencies in the resolve_play command. Changes: - Added mock for state_manager.get_state() to return valid state - Added mock for random.choice() to return deterministic PlayOutcome - Updated assertion to expect auto-generated outcome (SINGLE_1) - Test now properly validates the auto-outcome behavior for terminal testing Root cause: resolve_play() checks state_manager early and auto-generates a random outcome for testing when no forced outcome is provided. Test was not accounting for either behavior. All 731 unit tests now passing (100%). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
23d4227deb
commit
c705e87ee2
@ -192,26 +192,36 @@ async def test_resolve_play_success(game_commands):
|
||||
game_id = uuid4()
|
||||
|
||||
with patch('terminal_client.commands.game_engine') as mock_ge:
|
||||
with patch('terminal_client.commands.display'):
|
||||
# Setup mock result with proper attributes
|
||||
mock_result = MagicMock()
|
||||
mock_result.description = "Single to center field"
|
||||
mock_result.outs_recorded = 0
|
||||
mock_result.runs_scored = 1
|
||||
with patch('terminal_client.commands.state_manager') as mock_sm:
|
||||
with patch('terminal_client.commands.display'):
|
||||
with patch('random.choice') as mock_random_choice:
|
||||
# Setup mock result with proper attributes
|
||||
mock_result = MagicMock()
|
||||
mock_result.description = "Single to center field"
|
||||
mock_result.outs_recorded = 0
|
||||
mock_result.runs_scored = 1
|
||||
|
||||
# Setup mock state
|
||||
mock_state = MagicMock()
|
||||
mock_state.away_score = 1
|
||||
mock_state.home_score = 0
|
||||
# Setup mock state
|
||||
mock_state = MagicMock()
|
||||
mock_state.away_score = 1
|
||||
mock_state.home_score = 0
|
||||
|
||||
mock_ge.resolve_play = AsyncMock(return_value=mock_result)
|
||||
mock_ge.get_game_state = AsyncMock(return_value=mock_state)
|
||||
# Mock state_manager to return a valid state (not None)
|
||||
mock_sm.get_state = MagicMock(return_value=mock_state)
|
||||
|
||||
success = await game_commands.resolve_play(game_id)
|
||||
# Mock random.choice to return SINGLE_1
|
||||
from app.config import PlayOutcome
|
||||
mock_random_choice.return_value = PlayOutcome.SINGLE_1
|
||||
|
||||
assert success is True
|
||||
mock_ge.resolve_play.assert_called_once_with(game_id, None, None, None, None)
|
||||
mock_ge.get_game_state.assert_called_once_with(game_id)
|
||||
mock_ge.resolve_play = AsyncMock(return_value=mock_result)
|
||||
mock_ge.get_game_state = AsyncMock(return_value=mock_state)
|
||||
|
||||
success = await game_commands.resolve_play(game_id)
|
||||
|
||||
assert success is True
|
||||
# Should be called with auto-generated outcome (SINGLE_1 from mocked random)
|
||||
mock_ge.resolve_play.assert_called_once_with(game_id, PlayOutcome.SINGLE_1, None, None, None)
|
||||
mock_ge.get_game_state.assert_called_once_with(game_id)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@ -368,14 +378,21 @@ async def test_show_box_score_success(game_commands):
|
||||
"""Test showing box score successfully."""
|
||||
game_id = uuid4()
|
||||
|
||||
with patch('terminal_client.commands.game_engine') as mock_ge:
|
||||
mock_state = MagicMock()
|
||||
mock_ge.get_game_state = AsyncMock(return_value=mock_state)
|
||||
mock_box_score = {
|
||||
'game_stats': {'home_runs': 5, 'away_runs': 3},
|
||||
'batting_stats': [],
|
||||
'pitching_stats': []
|
||||
}
|
||||
|
||||
success = await game_commands.show_box_score(game_id)
|
||||
# Mock the box_score_service singleton instance method
|
||||
with patch.object(type(__import__('app.services', fromlist=['box_score_service']).box_score_service), 'get_box_score', new_callable=AsyncMock) as mock_get_box_score:
|
||||
with patch('terminal_client.commands.display'):
|
||||
mock_get_box_score.return_value = mock_box_score
|
||||
|
||||
assert success is True
|
||||
mock_ge.get_game_state.assert_called_once_with(game_id)
|
||||
success = await game_commands.show_box_score(game_id)
|
||||
|
||||
assert success is True
|
||||
mock_get_box_score.assert_called_once_with(game_id)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@ -383,8 +400,9 @@ async def test_show_box_score_not_found(game_commands):
|
||||
"""Test showing box score when game not found."""
|
||||
game_id = uuid4()
|
||||
|
||||
with patch('terminal_client.commands.game_engine') as mock_ge:
|
||||
mock_ge.get_game_state = AsyncMock(return_value=None)
|
||||
# Mock the box_score_service singleton instance method
|
||||
with patch.object(type(__import__('app.services', fromlist=['box_score_service']).box_score_service), 'get_box_score', new_callable=AsyncMock) as mock_get_box_score:
|
||||
mock_get_box_score.return_value = None
|
||||
|
||||
success = await game_commands.show_box_score(game_id)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user