diff --git a/services/telegram_bot_service.py b/services/telegram_bot_service.py index 6cb5927..c453555 100644 --- a/services/telegram_bot_service.py +++ b/services/telegram_bot_service.py @@ -164,7 +164,7 @@ class TrendTelegramBot: ] return InlineKeyboardMarkup(keyboard) - def _get_category_keyboard(self, callback_prefix: str = "cat"): + def _get_category_keyboard(self, callback_prefix: str = "trend"): """建立分類選擇按鈕""" # 每行 3 個按鈕 keyboard = [] diff --git a/tests/test_trend_telegram_bot_service.py b/tests/test_trend_telegram_bot_service.py index 02c5a24..11fe8dc 100644 --- a/tests/test_trend_telegram_bot_service.py +++ b/tests/test_trend_telegram_bot_service.py @@ -50,6 +50,21 @@ def _run(coro): return asyncio.run(coro) +def test_default_category_keyboard_uses_handled_trend_prefix(): + from services.telegram_bot_service import CATEGORIES, TrendTelegramBot + + bot = TrendTelegramBot(token="dummy") + keyboard = bot._get_category_keyboard() + callback_values = [ + button.callback_data + for row in keyboard.inline_keyboard + for button in row + ] + + assert f"trend_{CATEGORIES[0]}" in callback_values + assert not any(value.startswith("cat_") for value in callback_values) + + def test_polling_callback_dedup_without_update_id(monkeypatch): from services.telegram_bot_service import TrendTelegramBot