@@ -1149,5 +1149,44 @@ def test_handle_faq_reaction_posts_answer_to_original_thread(self, mock_call, mo
11491149 )
11501150
11511151
1152+ class TestFormatFaqSources (unittest .TestCase ):
1153+ """format_faq_sources prefixes each line with the source type."""
1154+
1155+ def test_labels_known_source_types (self ):
1156+ sources = [
1157+ {'source' : 'faq' , 'title' : 'Can I use TypeScript?' , 'url' : 'https://x/faq#1' },
1158+ {'source' : 'docs' , 'title' : 'Project' , 'url' : 'https://x/docs' },
1159+ {'source' : 'course-repo' , 'title' : 'README' , 'url' : 'https://x/repo' },
1160+ ]
1161+ result = lambda_function .format_faq_sources (sources , found_answer = True )
1162+ self .assertIn ('*Sources:*' , result )
1163+ self .assertIn ('• [FAQ] <https://x/faq#1|Can I use TypeScript?>' , result )
1164+ self .assertIn ('• [docs] <https://x/docs|Project>' , result )
1165+ self .assertIn ('• [repo] <https://x/repo|README>' , result )
1166+
1167+ def test_unknown_source_type_used_verbatim (self ):
1168+ sources = [{'source' : 'blog' , 'title' : 'Post' , 'url' : 'https://x/p' }]
1169+ result = lambda_function .format_faq_sources (sources )
1170+ self .assertIn ('• [blog] <https://x/p|Post>' , result )
1171+
1172+ def test_missing_source_type_has_no_prefix (self ):
1173+ sources = [{'title' : 'Post' , 'url' : 'https://x/p' }]
1174+ result = lambda_function .format_faq_sources (sources )
1175+ self .assertIn ('• <https://x/p|Post>' , result )
1176+
1177+ def test_not_found_changes_heading (self ):
1178+ sources = [{'source' : 'faq' , 'title' : 'T' , 'url' : 'https://x/f' }]
1179+ result = lambda_function .format_faq_sources (sources , found_answer = False )
1180+ self .assertIn ('*You can check these for more information:*' , result )
1181+
1182+ def test_sources_without_url_are_skipped (self ):
1183+ sources = [{'source' : 'faq' , 'title' : 'No link' }]
1184+ self .assertEqual (lambda_function .format_faq_sources (sources ), '' )
1185+
1186+ def test_empty_sources (self ):
1187+ self .assertEqual (lambda_function .format_faq_sources (None ), '' )
1188+ self .assertEqual (lambda_function .format_faq_sources ([]), '' )
1189+
1190+
11521191if __name__ == '__main__' :
11531192 unittest .main ()
0 commit comments