Add id command

This commit is contained in:
2026-07-01 21:47:01 +02:00
parent 62ea12033f
commit 12434ec557
2 changed files with 191 additions and 0 deletions

70
tests/test_id_command.py Normal file
View File

@@ -0,0 +1,70 @@
from __future__ import annotations
import unittest
from types import SimpleNamespace
from unittest.mock import AsyncMock
from app.commands.builtins import _format_id_report, id_command
class IdCommandTests(unittest.IsolatedAsyncioTestCase):
def _ctx(self):
reply = SimpleNamespace(
id=777,
topic=SimpleNamespace(id=55, title="Deploys"),
from_user=SimpleNamespace(
id=202,
first_name="Reply",
last_name="User",
username="reply_user",
),
sender_chat=None,
media=SimpleNamespace(value="photo"),
text="hello from reply",
caption=None,
)
message = SimpleNamespace(
id=123,
chat=SimpleNamespace(
id=-1001234567890,
type=SimpleNamespace(value="channel"),
title="Build Channel",
username="builds",
),
topic=SimpleNamespace(id=42, title="Main Thread"),
from_user=SimpleNamespace(
id=101,
first_name="Owner",
last_name=None,
username="owner",
),
sender_chat=None,
reply_to_message=reply,
reply_text=AsyncMock(),
)
return SimpleNamespace(message=message, reply=message.reply_text)
async def test_id_report_includes_current_and_replied_message_data(self) -> None:
report = _format_id_report(self._ctx())
self.assertIn("chat_id: -1001234567890", report)
self.assertIn("chat_type: channel", report)
self.assertIn("thread_id: 42", report)
self.assertIn("user_id: 101", report)
self.assertIn("reply_message_id: 777", report)
self.assertIn("reply_thread_id: 55", report)
self.assertIn("reply_user_id: 202", report)
self.assertIn("reply_media: photo", report)
self.assertIn("reply_text: hello from reply", report)
async def test_id_command_replies_with_report(self) -> None:
ctx = self._ctx()
await id_command(ctx)
ctx.reply.assert_awaited_once()
self.assertIn("chat_id: -1001234567890", ctx.reply.await_args.args[0])
if __name__ == "__main__":
unittest.main()