Skip to content

Commit 7111392

Browse files
committed
fix: add test for refactored reactionevents
1 parent baf0756 commit 7111392

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tests/test_bot.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,39 @@ def ensure_attributes(target_object) -> None:
127127
getattr(target_object, attr)
128128

129129

130+
@pytest.mark.asyncio
131+
async def test_reaction_events(bot: Client, guild: Guild) -> None:
132+
"""
133+
Tests reaction event handling on an uncached message.
134+
135+
Requires manual setup:
136+
1. Set TARGET_CHANNEL_ID environment variable to a valid channel ID.
137+
2. A user must add a reaction to the test message within 60 seconds.
138+
"""
139+
# Skip test if target channel not provided
140+
target_channel_id = os.environ.get("BOT_TEST_CHANNEL_ID")
141+
if not target_channel_id:
142+
pytest.skip("Set TARGET_CHANNEL_ID to run this test")
143+
144+
# Get channel and post test message
145+
channel = await bot.fetch_channel(target_channel_id)
146+
test_msg = await channel.send("Reaction Event Test - React with ✅ within 60 seconds")
147+
148+
try:
149+
# simulate uncached state
150+
bot.cache.delete_message(message_id=test_msg.id, channel_id=test_msg.channel.id)
151+
152+
# wait for user to react with checkmark
153+
reaction_event = await bot.wait_for(
154+
"message_reaction_add", timeout=60, checks=lambda e: e.message.id == test_msg.id and str(e.emoji) == "✅"
155+
)
156+
157+
assert reaction_event.message.id == test_msg.id
158+
assert reaction_event.emoji.name == "✅"
159+
finally:
160+
await test_msg.delete()
161+
162+
130163
@pytest.mark.asyncio
131164
async def test_channels(bot: Client, guild: Guild) -> None:
132165
channels = [

0 commit comments

Comments
 (0)