Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions tests/test_admin_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,28 @@ async def test_results_calculate_records_cooldown_and_calls_followup_steps(
mock_interaction_admin, score_result
)

@pytest.mark.asyncio
async def test_results_calculate_does_not_record_cooldown_when_scoring_fails(
self, admin_cog, mock_interaction_admin, monkeypatch
):
"""Validation failures should not throttle a retry after the admin fixes results state."""
fixture = {"id": 7, "week_number": 7, "games": ["A - B"], "deadline": datetime.now(UTC)}

monkeypatch.setattr(admin_cog.db, "get_open_fixtures", AsyncMock(return_value=[fixture]))
admin_cog.service.calculate_fixture_scores = AsyncMock(
side_effect=ValueError("No results entered")
)
admin_cog._create_backup = AsyncMock()
admin_cog._post_calculation_to_channel = AsyncMock()

await admin_cog.results_calculate.callback(admin_cog, mock_interaction_admin, None)

user_id = str(mock_interaction_admin.user.id)
assert admin_cog.workflow_state.get_calculate_cooldown(user_id) is None
assert mock_interaction_admin.response_sent[-1]["content"] == "No results entered"
admin_cog._create_backup.assert_not_called()
admin_cog._post_calculation_to_channel.assert_not_called()


class TestResultsPostFlow:
@pytest.fixture
Expand Down
4 changes: 2 additions & 2 deletions typer_bot/commands/admin_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,14 +373,14 @@ async def results_calculate(self, interaction: discord.Interaction, week: int |
if not fixture:
return

self.workflow_state.record_calculate_cooldown(user_id, current_time=current_time)

try:
score_result = await self.service.calculate_fixture_scores(fixture["id"])
except ValueError as exc:
await interaction.response.send_message(str(exc), ephemeral=True)
return

self.workflow_state.record_calculate_cooldown(user_id, current_time=current_time)

await self._create_backup()
await self._post_calculation_to_channel(interaction, score_result)

Expand Down
Loading