@@ -525,3 +525,67 @@ def test_was_bot_mentioned_later_in_thread(mock_env: Mock):
525525 result = was_bot_mentioned_in_thread_root ("C123" , "1234567890.123456" , mock_client )
526526
527527 assert result is True
528+
529+
530+ def test_get_bot_user_id_auth_test_fails (mock_env : Mock ):
531+ """test get_bot_user_id returns None when auth_test fails"""
532+ mock_client = Mock ()
533+ mock_client .auth_test .return_value = {"ok" : False }
534+
535+ if "app.utils.handler_utils" in sys .modules :
536+ del sys .modules ["app.utils.handler_utils" ]
537+ from app .utils .handler_utils import get_bot_user_id
538+
539+ if hasattr (get_bot_user_id , "_cache" ):
540+ get_bot_user_id ._cache .clear ()
541+
542+ result = get_bot_user_id (mock_client )
543+
544+ assert result is None
545+
546+
547+ def test_get_bot_user_id_exception (mock_env : Mock ):
548+ """test get_bot_user_id returns None when exception occurs"""
549+ mock_client = Mock ()
550+ mock_client .auth_test .side_effect = Exception ("Auth failed" )
551+
552+ if "app.utils.handler_utils" in sys .modules :
553+ del sys .modules ["app.utils.handler_utils" ]
554+ from app .utils .handler_utils import get_bot_user_id
555+
556+ if hasattr (get_bot_user_id , "_cache" ):
557+ get_bot_user_id ._cache .clear ()
558+
559+ result = get_bot_user_id (mock_client )
560+
561+ assert result is None
562+
563+
564+ def test_was_bot_mentioned_no_messages_in_response (mock_env : Mock ):
565+ """test fail when API returns no messages"""
566+ mock_client = Mock ()
567+ mock_client .auth_test .return_value = {"ok" : True , "user_id" : "U123ABC" }
568+ mock_client .conversations_replies .return_value = {"ok" : True , "messages" : []}
569+
570+ if "app.utils.handler_utils" in sys .modules :
571+ del sys .modules ["app.utils.handler_utils" ]
572+ from app .utils .handler_utils import was_bot_mentioned_in_thread_root
573+
574+ result = was_bot_mentioned_in_thread_root ("C123" , "1234567890.123456" , mock_client )
575+
576+ assert result is True
577+
578+
579+ def test_was_bot_mentioned_api_not_ok (mock_env : Mock ):
580+ """test fail when API returns ok: False"""
581+ mock_client = Mock ()
582+ mock_client .auth_test .return_value = {"ok" : True , "user_id" : "U123ABC" }
583+ mock_client .conversations_replies .return_value = {"ok" : False }
584+
585+ if "app.utils.handler_utils" in sys .modules :
586+ del sys .modules ["app.utils.handler_utils" ]
587+ from app .utils .handler_utils import was_bot_mentioned_in_thread_root
588+
589+ result = was_bot_mentioned_in_thread_root ("C123" , "1234567890.123456" , mock_client )
590+
591+ assert result is True
0 commit comments