@@ -586,7 +586,18 @@ async def test_build_subject_selection_screen_data_respects_chips_limits() -> No
586586 service = FlowService ()
587587 user = User (id = 405 , wa_id = "255700006665" , name = "Teacher" )
588588 subjects = [
589- Subject (id = index + 1 , name = subject_name )
589+ Subject (
590+ id = index + 1 ,
591+ name = subject_name ,
592+ subject_classes = [
593+ Class (
594+ id = 1000 + index ,
595+ subject_id = index + 1 ,
596+ grade_level = enums .GradeLevel .os1 ,
597+ status = enums .SubjectClassStatus .active ,
598+ )
599+ ],
600+ )
590601 for index , subject_name in enumerate (list (enums .SubjectName )[:25 ])
591602 ]
592603
@@ -602,6 +613,57 @@ async def test_build_subject_selection_screen_data_respects_chips_limits() -> No
602613 assert all (len (option ["title" ]) <= 30 for option in data ["subject_options" ])
603614
604615
616+ @pytest .mark .asyncio
617+ async def test_build_subject_selection_screen_data_excludes_subjects_without_active_classes () -> (
618+ None
619+ ):
620+ service = FlowService ()
621+ user = User (id = 406 , wa_id = "255700006664" , name = "Teacher" )
622+ subjects = [
623+ Subject (
624+ id = 1 ,
625+ name = enums .SubjectName .geography ,
626+ subject_classes = [
627+ Class (
628+ id = 101 ,
629+ subject_id = 1 ,
630+ grade_level = enums .GradeLevel .os1 ,
631+ status = enums .SubjectClassStatus .inactive ,
632+ )
633+ ],
634+ ),
635+ Subject (
636+ id = 2 ,
637+ name = enums .SubjectName .biology ,
638+ subject_classes = [
639+ Class (
640+ id = 201 ,
641+ subject_id = 2 ,
642+ grade_level = enums .GradeLevel .os1 ,
643+ status = enums .SubjectClassStatus .active ,
644+ )
645+ ],
646+ ),
647+ Subject (
648+ id = 3 ,
649+ name = enums .SubjectName .history ,
650+ subject_classes = [],
651+ ),
652+ ]
653+
654+ with patch (
655+ "app.services.flows.handlers.subjects_classes_flow_handler.db.read_subjects" ,
656+ AsyncMock (return_value = subjects ),
657+ ):
658+ data = await service ._subjects_classes_flow_handler ._build_subject_selection_screen_data (
659+ user = user
660+ )
661+
662+ assert data ["subject_options" ] == [{"id" : "2" , "title" : "Biology 🧬" }]
663+ assert data ["selected_subject_ids" ] == []
664+ assert data ["has_subject_options" ] is True
665+
666+
605667def test_build_class_option_title_keeps_form_prefix_when_truncating () -> None :
606668 service = FlowService ()
607669
0 commit comments