chore: remove obsolete MoveAction test stubs

Closes #16

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Cal Corum 2026-02-19 22:28:47 -06:00
parent 9e43ffa1c1
commit 5af62171da

View File

@ -3,6 +3,7 @@ Tests for /dropadd Discord Commands
Validates the Discord command interface, autocomplete, and user interactions. Validates the Discord command interface, autocomplete, and user interactions.
""" """
import pytest import pytest
from unittest.mock import AsyncMock, MagicMock, patch from unittest.mock import AsyncMock, MagicMock, patch
import discord import discord
@ -18,7 +19,7 @@ from tests.factories import PlayerFactory, TeamFactory
class TestDropAddCommands: class TestDropAddCommands:
"""Test DropAddCommands Discord command functionality.""" """Test DropAddCommands Discord command functionality."""
@pytest.fixture @pytest.fixture
def mock_bot(self): def mock_bot(self):
"""Create mock Discord bot.""" """Create mock Discord bot."""
@ -26,12 +27,12 @@ class TestDropAddCommands:
bot.user = MagicMock() bot.user = MagicMock()
bot.user.id = 123456789 bot.user.id = 123456789
return bot return bot
@pytest.fixture @pytest.fixture
def commands_cog(self, mock_bot): def commands_cog(self, mock_bot):
"""Create DropAddCommands cog instance.""" """Create DropAddCommands cog instance."""
return DropAddCommands(mock_bot) return DropAddCommands(mock_bot)
@pytest.fixture @pytest.fixture
def mock_interaction(self): def mock_interaction(self):
"""Create mock Discord interaction.""" """Create mock Discord interaction."""
@ -47,88 +48,108 @@ class TestDropAddCommands:
interaction.guild = MagicMock() interaction.guild = MagicMock()
interaction.guild.id = 669356687294988350 # Test guild ID matching config interaction.guild.id = 669356687294988350 # Test guild ID matching config
return interaction return interaction
@pytest.fixture @pytest.fixture
def mock_team(self): def mock_team(self):
"""Create mock team data.""" """Create mock team data."""
return TeamFactory.west_virginia() return TeamFactory.west_virginia()
@pytest.fixture @pytest.fixture
def mock_player(self): def mock_player(self):
"""Create mock player data.""" """Create mock player data."""
return PlayerFactory.mike_trout() return PlayerFactory.mike_trout()
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_player_autocomplete_success(self, commands_cog, mock_interaction): async def test_player_autocomplete_success(self, commands_cog, mock_interaction):
"""Test successful player autocomplete.""" """Test successful player autocomplete."""
mock_players = [ mock_players = [
PlayerFactory.mike_trout(id=1), PlayerFactory.mike_trout(id=1),
PlayerFactory.ronald_acuna(id=2) PlayerFactory.ronald_acuna(id=2),
] ]
with patch('utils.autocomplete.player_service') as mock_service: with patch("utils.autocomplete.player_service") as mock_service:
mock_service.search_players = AsyncMock(return_value=mock_players) mock_service.search_players = AsyncMock(return_value=mock_players)
from utils.autocomplete import player_autocomplete from utils.autocomplete import player_autocomplete
choices = await player_autocomplete(mock_interaction, 'Trout')
choices = await player_autocomplete(mock_interaction, "Trout")
assert len(choices) == 2 assert len(choices) == 2
assert choices[0].name == 'Mike Trout (CF)' assert choices[0].name == "Mike Trout (CF)"
assert choices[0].value == 'Mike Trout' assert choices[0].value == "Mike Trout"
assert choices[1].name == 'Ronald Acuna Jr. (OF)' assert choices[1].name == "Ronald Acuna Jr. (OF)"
assert choices[1].value == 'Ronald Acuna Jr.' assert choices[1].value == "Ronald Acuna Jr."
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_player_autocomplete_with_team(self, commands_cog, mock_interaction): async def test_player_autocomplete_with_team(self, commands_cog, mock_interaction):
"""Test player autocomplete with team information.""" """Test player autocomplete with team information."""
mock_team = TeamFactory.create(id=499, abbrev='LAA', sname='Angels', lname='Los Angeles Angels') mock_team = TeamFactory.create(
id=499, abbrev="LAA", sname="Angels", lname="Los Angeles Angels"
)
mock_player = PlayerFactory.mike_trout(id=1) mock_player = PlayerFactory.mike_trout(id=1)
mock_player.team = mock_team # Add team info mock_player.team = mock_team # Add team info
with patch('utils.autocomplete.player_service') as mock_service: with patch("utils.autocomplete.player_service") as mock_service:
mock_service.search_players = AsyncMock(return_value=[mock_player]) mock_service.search_players = AsyncMock(return_value=[mock_player])
from utils.autocomplete import player_autocomplete from utils.autocomplete import player_autocomplete
choices = await player_autocomplete(mock_interaction, 'Trout')
choices = await player_autocomplete(mock_interaction, "Trout")
assert len(choices) == 1 assert len(choices) == 1
assert choices[0].name == 'Mike Trout (CF - LAA)' assert choices[0].name == "Mike Trout (CF - LAA)"
assert choices[0].value == 'Mike Trout' assert choices[0].value == "Mike Trout"
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_player_autocomplete_short_input(self, commands_cog, mock_interaction): async def test_player_autocomplete_short_input(
self, commands_cog, mock_interaction
):
"""Test player autocomplete with short input returns empty.""" """Test player autocomplete with short input returns empty."""
from utils.autocomplete import player_autocomplete from utils.autocomplete import player_autocomplete
choices = await player_autocomplete(mock_interaction, 'T')
choices = await player_autocomplete(mock_interaction, "T")
assert len(choices) == 0 assert len(choices) == 0
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_player_autocomplete_error_handling(self, commands_cog, mock_interaction): async def test_player_autocomplete_error_handling(
self, commands_cog, mock_interaction
):
"""Test player autocomplete error handling.""" """Test player autocomplete error handling."""
with patch('utils.autocomplete.player_service') as mock_service: with patch("utils.autocomplete.player_service") as mock_service:
mock_service.search_players.side_effect = Exception("API Error") mock_service.search_players.side_effect = Exception("API Error")
from utils.autocomplete import player_autocomplete from utils.autocomplete import player_autocomplete
choices = await player_autocomplete(mock_interaction, 'Trout')
choices = await player_autocomplete(mock_interaction, "Trout")
assert len(choices) == 0 assert len(choices) == 0
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_dropadd_command_no_team(self, commands_cog, mock_interaction): async def test_dropadd_command_no_team(self, commands_cog, mock_interaction):
"""Test /dropadd command when user has no team.""" """Test /dropadd command when user has no team."""
with patch('commands.transactions.dropadd.validate_user_has_team') as mock_validate: with patch(
"commands.transactions.dropadd.validate_user_has_team"
) as mock_validate:
mock_validate.return_value = None mock_validate.return_value = None
await commands_cog.dropadd.callback(commands_cog, mock_interaction) await commands_cog.dropadd.callback(commands_cog, mock_interaction)
mock_interaction.response.defer.assert_called_once() mock_interaction.response.defer.assert_called_once()
# validate_user_has_team sends its own error message, command just returns # validate_user_has_team sends its own error message, command just returns
mock_validate.assert_called_once_with(mock_interaction) mock_validate.assert_called_once_with(mock_interaction)
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_dropadd_command_success_no_params(self, commands_cog, mock_interaction, mock_team): async def test_dropadd_command_success_no_params(
self, commands_cog, mock_interaction, mock_team
):
"""Test /dropadd command success without parameters.""" """Test /dropadd command success without parameters."""
with patch('commands.transactions.dropadd.validate_user_has_team') as mock_validate: with patch(
with patch('commands.transactions.dropadd.get_transaction_builder') as mock_get_builder: "commands.transactions.dropadd.validate_user_has_team"
with patch('commands.transactions.dropadd.create_transaction_embed') as mock_create_embed: ) as mock_validate:
with patch(
"commands.transactions.dropadd.get_transaction_builder"
) as mock_get_builder:
with patch(
"commands.transactions.dropadd.create_transaction_embed"
) as mock_create_embed:
mock_validate.return_value = mock_team mock_validate.return_value = mock_team
mock_builder = MagicMock() mock_builder = MagicMock()
@ -143,17 +164,29 @@ class TestDropAddCommands:
# Verify flow # Verify flow
mock_interaction.response.defer.assert_called_once() mock_interaction.response.defer.assert_called_once()
mock_validate.assert_called_once_with(mock_interaction) mock_validate.assert_called_once_with(mock_interaction)
mock_get_builder.assert_called_once_with(mock_interaction.user.id, mock_team) mock_get_builder.assert_called_once_with(
mock_create_embed.assert_called_once_with(mock_builder, command_name='/dropadd') mock_interaction.user.id, mock_team
)
mock_create_embed.assert_called_once_with(
mock_builder, command_name="/dropadd"
)
mock_interaction.followup.send.assert_called_once() mock_interaction.followup.send.assert_called_once()
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_dropadd_command_with_quick_move(self, commands_cog, mock_interaction, mock_team): async def test_dropadd_command_with_quick_move(
self, commands_cog, mock_interaction, mock_team
):
"""Test /dropadd command with quick move parameters.""" """Test /dropadd command with quick move parameters."""
with patch('commands.transactions.dropadd.validate_user_has_team') as mock_validate: with patch(
with patch('commands.transactions.dropadd.get_transaction_builder') as mock_get_builder: "commands.transactions.dropadd.validate_user_has_team"
with patch.object(commands_cog, '_add_quick_move') as mock_add_quick: ) as mock_validate:
with patch('commands.transactions.dropadd.create_transaction_embed') as mock_create_embed: with patch(
"commands.transactions.dropadd.get_transaction_builder"
) as mock_get_builder:
with patch.object(commands_cog, "_add_quick_move") as mock_add_quick:
with patch(
"commands.transactions.dropadd.create_transaction_embed"
) as mock_create_embed:
mock_validate.return_value = mock_team mock_validate.return_value = mock_team
mock_builder = MagicMock() mock_builder = MagicMock()
@ -162,17 +195,18 @@ class TestDropAddCommands:
mock_add_quick.return_value = (True, "") mock_add_quick.return_value = (True, "")
mock_create_embed.return_value = MagicMock() mock_create_embed.return_value = MagicMock()
await commands_cog.dropadd.callback(commands_cog, await commands_cog.dropadd.callback(
commands_cog,
mock_interaction, mock_interaction,
player='Mike Trout', player="Mike Trout",
destination='ml' destination="ml",
) )
# Verify quick move was attempted # Verify quick move was attempted
mock_add_quick.assert_called_once_with( mock_add_quick.assert_called_once_with(
mock_builder, 'Mike Trout', 'ml' mock_builder, "Mike Trout", "ml"
) )
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_add_quick_move_success(self, commands_cog, mock_team, mock_player): async def test_add_quick_move_success(self, commands_cog, mock_team, mock_player):
"""Test successful quick move addition.""" """Test successful quick move addition."""
@ -185,45 +219,49 @@ class TestDropAddCommands:
mock_builder._current_roster.minor_league_players = [] mock_builder._current_roster.minor_league_players = []
mock_builder._current_roster.il_players = [] mock_builder._current_roster.il_players = []
with patch('commands.transactions.dropadd.player_service') as mock_service: with patch("commands.transactions.dropadd.player_service") as mock_service:
mock_service.search_players = AsyncMock(return_value=[mock_player]) mock_service.search_players = AsyncMock(return_value=[mock_player])
success, error_message = await commands_cog._add_quick_move( success, error_message = await commands_cog._add_quick_move(
mock_builder, 'Mike Trout', 'ml' mock_builder, "Mike Trout", "ml"
) )
assert success is True assert success is True
assert error_message == "" assert error_message == ""
mock_service.search_players.assert_called_once_with('Mike Trout', limit=10, season=13) mock_service.search_players.assert_called_once_with(
"Mike Trout", limit=10, season=13
)
mock_builder.add_move.assert_called_once() mock_builder.add_move.assert_called_once()
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_add_quick_move_player_not_found(self, commands_cog, mock_team): async def test_add_quick_move_player_not_found(self, commands_cog, mock_team):
"""Test quick move when player not found.""" """Test quick move when player not found."""
mock_builder = MagicMock() mock_builder = MagicMock()
mock_builder.team = mock_team mock_builder.team = mock_team
with patch('commands.transactions.dropadd.player_service') as mock_service: with patch("commands.transactions.dropadd.player_service") as mock_service:
mock_service.search_players = AsyncMock(return_value=[]) mock_service.search_players = AsyncMock(return_value=[])
success, error_message = await commands_cog._add_quick_move( success, error_message = await commands_cog._add_quick_move(
mock_builder, 'Nonexistent Player', 'ml' mock_builder, "Nonexistent Player", "ml"
) )
assert success is False assert success is False
assert "not found" in error_message assert "not found" in error_message
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_add_quick_move_invalid_action(self, commands_cog, mock_team, mock_player): async def test_add_quick_move_invalid_action(
self, commands_cog, mock_team, mock_player
):
"""Test quick move with invalid action.""" """Test quick move with invalid action."""
mock_builder = MagicMock() mock_builder = MagicMock()
mock_builder.team = mock_team mock_builder.team = mock_team
with patch('commands.transactions.dropadd.player_service') as mock_service: with patch("commands.transactions.dropadd.player_service") as mock_service:
mock_service.search_players = AsyncMock(return_value=[mock_player]) mock_service.search_players = AsyncMock(return_value=[mock_player])
success, error_message = await commands_cog._add_quick_move( success, error_message = await commands_cog._add_quick_move(
mock_builder, 'Mike Trout', 'invalid_destination' mock_builder, "Mike Trout", "invalid_destination"
) )
assert success is False assert success is False
@ -244,11 +282,11 @@ class TestDropAddCommands:
mock_player.name = "Mike Trout" mock_player.name = "Mike Trout"
mock_player.team = other_team mock_player.team = other_team
with patch('commands.transactions.dropadd.player_service') as mock_service: with patch("commands.transactions.dropadd.player_service") as mock_service:
mock_service.search_players = AsyncMock(return_value=[mock_player]) mock_service.search_players = AsyncMock(return_value=[mock_player])
success, error_message = await commands_cog._add_quick_move( success, error_message = await commands_cog._add_quick_move(
mock_builder, 'Mike Trout', 'ml' mock_builder, "Mike Trout", "ml"
) )
assert success is False assert success is False
@ -270,50 +308,55 @@ class TestDropAddCommands:
mock_builder._current_roster.il_players = [] mock_builder._current_roster.il_players = []
# Create a Free Agent team and player # Create a Free Agent team and player
fa_team = TeamFactory.create(id=1, abbrev="FA", sname="Free Agency", lname="Free Agency") fa_team = TeamFactory.create(
id=1, abbrev="FA", sname="Free Agency", lname="Free Agency"
)
fa_player = PlayerFactory.create(id=12472, name="Mike Trout", team_id=1) fa_player = PlayerFactory.create(id=12472, name="Mike Trout", team_id=1)
fa_player.team = fa_team fa_player.team = fa_team
with patch('commands.transactions.dropadd.player_service') as mock_service: with patch("commands.transactions.dropadd.player_service") as mock_service:
mock_service.search_players = AsyncMock(return_value=[fa_player]) mock_service.search_players = AsyncMock(return_value=[fa_player])
success, error_message = await commands_cog._add_quick_move( success, error_message = await commands_cog._add_quick_move(
mock_builder, 'Mike Trout', 'ml' mock_builder, "Mike Trout", "ml"
) )
assert success is True assert success is True
assert error_message == "" assert error_message == ""
# TODO: These tests are for obsolete MoveAction-based functionality
# The transaction system now uses from_roster/to_roster directly
# def test_determine_roster_types_add(self, commands_cog):
# def test_determine_roster_types_drop(self, commands_cog):
# def test_determine_roster_types_recall(self, commands_cog):
# def test_determine_roster_types_demote(self, commands_cog):
pass # Placeholder
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_clear_transaction_command(self, commands_cog, mock_interaction): async def test_clear_transaction_command(self, commands_cog, mock_interaction):
"""Test /cleartransaction command.""" """Test /cleartransaction command."""
with patch('commands.transactions.dropadd.clear_transaction_builder') as mock_clear: with patch(
await commands_cog.clear_transaction.callback(commands_cog, mock_interaction) "commands.transactions.dropadd.clear_transaction_builder"
) as mock_clear:
await commands_cog.clear_transaction.callback(
commands_cog, mock_interaction
)
mock_clear.assert_called_once_with(mock_interaction.user.id) mock_clear.assert_called_once_with(mock_interaction.user.id)
mock_interaction.response.send_message.assert_called_once() mock_interaction.response.send_message.assert_called_once()
# Check success message # Check success message
call_args = mock_interaction.response.send_message.call_args call_args = mock_interaction.response.send_message.call_args
assert "transaction builder has been cleared" in call_args[0][0] assert "transaction builder has been cleared" in call_args[0][0]
assert call_args[1]['ephemeral'] is True assert call_args[1]["ephemeral"] is True
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_dropadd_first_move_shows_full_embed(self, commands_cog, mock_interaction, mock_team): async def test_dropadd_first_move_shows_full_embed(
self, commands_cog, mock_interaction, mock_team
):
"""Test /dropadd command with first move shows full interactive embed.""" """Test /dropadd command with first move shows full interactive embed."""
with patch('commands.transactions.dropadd.validate_user_has_team') as mock_validate: with patch(
with patch('commands.transactions.dropadd.get_transaction_builder') as mock_get_builder: "commands.transactions.dropadd.validate_user_has_team"
with patch.object(commands_cog, '_add_quick_move') as mock_add_quick: ) as mock_validate:
with patch('commands.transactions.dropadd.create_transaction_embed') as mock_create_embed: with patch(
"commands.transactions.dropadd.get_transaction_builder"
) as mock_get_builder:
with patch.object(commands_cog, "_add_quick_move") as mock_add_quick:
with patch(
"commands.transactions.dropadd.create_transaction_embed"
) as mock_create_embed:
mock_validate.return_value = mock_team mock_validate.return_value = mock_team
# Create empty builder (first move) # Create empty builder (first move)
@ -324,76 +367,88 @@ class TestDropAddCommands:
mock_add_quick.return_value = (True, "") mock_add_quick.return_value = (True, "")
mock_create_embed.return_value = MagicMock() mock_create_embed.return_value = MagicMock()
await commands_cog.dropadd.callback(commands_cog, await commands_cog.dropadd.callback(
commands_cog,
mock_interaction, mock_interaction,
player='Mike Trout', player="Mike Trout",
destination='ml' destination="ml",
) )
# Should show full embed with view (now ephemeral) # Should show full embed with view (now ephemeral)
mock_interaction.followup.send.assert_called_once() mock_interaction.followup.send.assert_called_once()
call_args = mock_interaction.followup.send.call_args call_args = mock_interaction.followup.send.call_args
assert call_args[1]['ephemeral'] is True assert call_args[1]["ephemeral"] is True
assert 'embed' in call_args[1] assert "embed" in call_args[1]
assert 'view' in call_args[1] assert "view" in call_args[1]
assert 'content' in call_args[1] assert "content" in call_args[1]
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_dropadd_append_mode_shows_confirmation(self, commands_cog, mock_interaction, mock_team): async def test_dropadd_append_mode_shows_confirmation(
self, commands_cog, mock_interaction, mock_team
):
"""Test /dropadd command in append mode shows ephemeral confirmation.""" """Test /dropadd command in append mode shows ephemeral confirmation."""
with patch('commands.transactions.dropadd.validate_user_has_team') as mock_validate: with patch(
with patch('commands.transactions.dropadd.get_transaction_builder') as mock_get_builder: "commands.transactions.dropadd.validate_user_has_team"
with patch.object(commands_cog, '_add_quick_move') as mock_add_quick: ) as mock_validate:
with patch(
"commands.transactions.dropadd.get_transaction_builder"
) as mock_get_builder:
with patch.object(commands_cog, "_add_quick_move") as mock_add_quick:
mock_validate.return_value = mock_team mock_validate.return_value = mock_team
# Create builder with existing moves (append mode) # Create builder with existing moves (append mode)
mock_builder = MagicMock() mock_builder = MagicMock()
mock_builder.is_empty = False mock_builder.is_empty = False
mock_builder.move_count = 2 mock_builder.move_count = 2
mock_builder.validate_transaction = AsyncMock(return_value=MagicMock( mock_builder.validate_transaction = AsyncMock(
is_legal=True, return_value=MagicMock(
major_league_count=25, is_legal=True,
minor_league_count=10, major_league_count=25,
warnings=[], minor_league_count=10,
errors=[], warnings=[],
suggestions=[] errors=[],
)) suggestions=[],
)
)
mock_get_builder.return_value = mock_builder mock_get_builder.return_value = mock_builder
mock_add_quick.return_value = (True, "") mock_add_quick.return_value = (True, "")
with patch('commands.transactions.dropadd.create_transaction_embed') as mock_create_embed: with patch(
"commands.transactions.dropadd.create_transaction_embed"
) as mock_create_embed:
mock_create_embed.return_value = MagicMock() mock_create_embed.return_value = MagicMock()
await commands_cog.dropadd.callback(commands_cog, await commands_cog.dropadd.callback(
commands_cog,
mock_interaction, mock_interaction,
player='Kevin Ginkel', player="Kevin Ginkel",
destination='ml' destination="ml",
) )
# Should show embed with ephemeral confirmation # Should show embed with ephemeral confirmation
mock_interaction.followup.send.assert_called_once() mock_interaction.followup.send.assert_called_once()
call_args = mock_interaction.followup.send.call_args call_args = mock_interaction.followup.send.call_args
assert call_args[1]['ephemeral'] is True assert call_args[1]["ephemeral"] is True
assert 'embed' in call_args[1] assert "embed" in call_args[1]
assert 'view' in call_args[1] assert "view" in call_args[1]
content = call_args[1]['content'] content = call_args[1]["content"]
assert "Added Kevin Ginkel → ML" in content assert "Added Kevin Ginkel → ML" in content
assert "Transaction now has 2 moves" in content assert "Transaction now has 2 moves" in content
class TestDropAddCommandsIntegration: class TestDropAddCommandsIntegration:
"""Integration tests for dropadd commands with real-like data flows.""" """Integration tests for dropadd commands with real-like data flows."""
@pytest.fixture @pytest.fixture
def mock_bot(self): def mock_bot(self):
"""Create mock Discord bot.""" """Create mock Discord bot."""
return MagicMock() return MagicMock()
@pytest.fixture @pytest.fixture
def commands_cog(self, mock_bot): def commands_cog(self, mock_bot):
"""Create DropAddCommands cog instance.""" """Create DropAddCommands cog instance."""
return DropAddCommands(mock_bot) return DropAddCommands(mock_bot)
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_full_dropadd_workflow(self, commands_cog): async def test_full_dropadd_workflow(self, commands_cog):
"""Test complete dropadd workflow from command to builder creation.""" """Test complete dropadd workflow from command to builder creation."""
@ -407,13 +462,23 @@ class TestDropAddCommandsIntegration:
mock_player = PlayerFactory.mike_trout(id=12472) mock_player = PlayerFactory.mike_trout(id=12472)
with patch('commands.transactions.dropadd.validate_user_has_team') as mock_validate: with patch(
with patch('commands.transactions.dropadd.player_service') as mock_player_service: "commands.transactions.dropadd.validate_user_has_team"
with patch('commands.transactions.dropadd.get_transaction_builder') as mock_get_builder: ) as mock_validate:
with patch('commands.transactions.dropadd.create_transaction_embed') as mock_create_embed: with patch(
"commands.transactions.dropadd.player_service"
) as mock_player_service:
with patch(
"commands.transactions.dropadd.get_transaction_builder"
) as mock_get_builder:
with patch(
"commands.transactions.dropadd.create_transaction_embed"
) as mock_create_embed:
# Setup mocks # Setup mocks
mock_validate.return_value = mock_team mock_validate.return_value = mock_team
mock_player_service.search_players = AsyncMock(return_value=[mock_player]) mock_player_service.search_players = AsyncMock(
return_value=[mock_player]
)
mock_builder = TransactionBuilder(mock_team, 123456789, 13) mock_builder = TransactionBuilder(mock_team, 123456789, 13)
mock_get_builder.return_value = mock_builder mock_get_builder.return_value = mock_builder
@ -421,13 +486,15 @@ class TestDropAddCommandsIntegration:
# Mock the async function # Mock the async function
async def mock_create_embed_func(builder, command_name=None): async def mock_create_embed_func(builder, command_name=None):
return MagicMock() return MagicMock()
mock_create_embed.side_effect = mock_create_embed_func mock_create_embed.side_effect = mock_create_embed_func
# Execute command with parameters # Execute command with parameters
await commands_cog.dropadd.callback(commands_cog, await commands_cog.dropadd.callback(
commands_cog,
mock_interaction, mock_interaction,
player='Mike Trout', player="Mike Trout",
destination='ml' destination="ml",
) )
# Verify the builder has the move # Verify the builder has the move
@ -436,7 +503,7 @@ class TestDropAddCommandsIntegration:
assert move.player == mock_player assert move.player == mock_player
# Note: TransactionMove no longer has 'action' field - uses from_roster/to_roster instead # Note: TransactionMove no longer has 'action' field - uses from_roster/to_roster instead
assert move.to_roster == RosterType.MAJOR_LEAGUE assert move.to_roster == RosterType.MAJOR_LEAGUE
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_error_recovery_in_workflow(self, commands_cog): async def test_error_recovery_in_workflow(self, commands_cog):
"""Test error recovery in dropadd workflow.""" """Test error recovery in dropadd workflow."""
@ -446,7 +513,9 @@ class TestDropAddCommandsIntegration:
mock_interaction.guild = MagicMock() mock_interaction.guild = MagicMock()
mock_interaction.guild.id = 669356687294988350 mock_interaction.guild.id = 669356687294988350
with patch('commands.transactions.dropadd.validate_user_has_team') as mock_validate: with patch(
"commands.transactions.dropadd.validate_user_has_team"
) as mock_validate:
# Simulate API error # Simulate API error
mock_validate.side_effect = Exception("API Error") mock_validate.side_effect = Exception("API Error")
@ -455,4 +524,4 @@ class TestDropAddCommandsIntegration:
await commands_cog.dropadd.callback(commands_cog, mock_interaction) await commands_cog.dropadd.callback(commands_cog, mock_interaction)
# Should have deferred before the error occurred # Should have deferred before the error occurred
mock_interaction.response.defer.assert_called_once() mock_interaction.response.defer.assert_called_once()