@@ -71,6 +71,19 @@ async def test_get_userinfo_success_without_email(self, github_client):
7171 assert result ['login' ] == mock_user_data ['login' ]
7272 assert result ['email' ] == 'test@example.com'
7373
74+ @pytest .mark .asyncio
75+ @respx .mock
76+ async def test_get_userinfo_without_primary_email_uses_first_email (self , github_client ):
77+ mock_user_data = create_mock_user_data ('github' , email = None )
78+ mock_user_info_response (respx , GITHUB_USER_INFO_URL , mock_user_data )
79+ emails_data = [
80+ {'email' : 'fallback@example.com' , 'primary' : False },
81+ {'email' : 'secondary@example.com' , 'primary' : False },
82+ ]
83+ respx .get (GITHUB_EMAILS_URL ).mock (return_value = httpx .Response (200 , json = emails_data ))
84+ result = await github_client .get_userinfo (TEST_ACCESS_TOKEN )
85+ assert result ['email' ] == 'fallback@example.com'
86+
7487 @pytest .mark .asyncio
7588 @respx .mock
7689 async def test_get_userinfo_with_different_access_token (self , github_client ):
@@ -134,6 +147,15 @@ async def test_get_userinfo_invalid_json(self, github_client):
134147 with pytest .raises (GetUserInfoError ):
135148 await github_client .get_userinfo (TEST_ACCESS_TOKEN )
136149
150+ @pytest .mark .asyncio
151+ @respx .mock
152+ async def test_get_userinfo_emails_invalid_json (self , github_client ):
153+ mock_user_data = create_mock_user_data ('github' , email = None )
154+ mock_user_info_response (respx , GITHUB_USER_INFO_URL , mock_user_data )
155+ respx .get (GITHUB_EMAILS_URL ).mock (return_value = httpx .Response (200 , text = 'invalid json' ))
156+ with pytest .raises (GetUserInfoError ):
157+ await github_client .get_userinfo (TEST_ACCESS_TOKEN )
158+
137159 @pytest .mark .asyncio
138160 @respx .mock
139161 async def test_get_userinfo_rate_limit (self , github_client ):
0 commit comments