@@ -564,96 +564,93 @@ def test_download_task_pdf
564564 end
565565
566566 def test_cant_submit_until_prerequisites_submitted
567- Sidekiq ::Testing . inline! do
568- # Create a unit and two task definitions
569- unit = FactoryBot . create ( :unit , student_count : 1 , task_count : 2 )
570- td1 = unit . task_definitions . first
571- td2 = unit . task_definitions . second
572- project = unit . active_projects . first
573-
574- task = project . task_for_task_definition ( td2 )
575-
576- td1 . update (
577- upload_requirements : [ { "key" => 'file0' , "name" => 'Shape Class' , "type" => 'code' } ] ,
578- target_grade : 0 , # Pass
579- start_date : Time . zone . now - 2 . weeks ,
580- target_date : Time . zone . now + 1 . week
581- )
567+ # Create a unit and two task definitions
568+ unit = FactoryBot . create ( :unit , student_count : 1 , task_count : 2 )
569+ td1 = unit . task_definitions . first
570+ td2 = unit . task_definitions . second
571+ project = unit . active_projects . first
582572
583- td2 . update (
584- upload_requirements : [ { "key" => 'file0' , "name" => 'Shape Class' , "type" => 'code' } ] ,
585- target_grade : 3 , # HD
586- start_date : Time . zone . now - 2 . weeks ,
587- target_date : Time . zone . now + 1 . week
588- )
573+ task = project . task_for_task_definition ( td2 )
589574
590- # Create a prerequisite on the second taskDef that adds the first taskDef as a prereq
591- prereq = TaskPrerequisite . create! (
592- task_definition : td2 , # Before you can submit td2...
593- prerequisite : td1 , # You need to submit td1
594- task_status_id : TaskStatus . ready_for_feedback . id
595- )
575+ td1 . update (
576+ upload_requirements : [ { "key" => 'file0' , "name" => 'Shape Class' , "type" => 'code' } ] ,
577+ target_grade : 0 , # Pass
578+ start_date : Time . zone . now - 2 . weeks ,
579+ target_date : Time . zone . now + 1 . week
580+ )
596581
597- assert prereq . valid?
582+ td2 . update (
583+ upload_requirements : [ { "key" => 'file0' , "name" => 'Shape Class' , "type" => 'code' } ] ,
584+ target_grade : 3 , # HD
585+ start_date : Time . zone . now - 2 . weeks ,
586+ target_date : Time . zone . now + 1 . week
587+ )
598588
599- # Add username and auth_token to Header
600- add_auth_header_for ( user : project . user )
589+ # Create a prerequisite on the second taskDef that adds the first taskDef as a prereq
590+ prereq = TaskPrerequisite . create! (
591+ task_definition : td2 , # Before you can submit td2...
592+ prerequisite : td1 , # You need to submit td1
593+ task_status_id : TaskStatus . ready_for_feedback . id
594+ )
601595
602- data_to_post = {
603- trigger : 'ready_for_feedback'
604- }
596+ assert prereq . valid?
605597
606- data_to_post = with_file ( 'test_files/submissions/program.cs' , 'application/json' , data_to_post )
598+ # Add username and auth_token to Header
599+ add_auth_header_for ( user : project . user )
607600
608- # Attempt to make a submission that has an unsubmitted prerequisite
609- post "/api/projects/#{ project . id } /task_def_id/#{ td2 . id } /submission" , data_to_post
610- assert_equal 409 , last_response . status , last_response_body
611- task = project . task_for_task_definition ( td2 )
612- # Ensure the submission was denied
613- assert_equal TaskStatus . not_started , task . task_status
614- assert_equal last_response_body [ 'error' ] , "Cannot submit this task until prerequisite '#{ td1 . abbreviation } ' has been submitted"
601+ data_to_post = {
602+ trigger : 'ready_for_feedback'
603+ }
615604
616- prereq . update ( task_status_id : TaskStatus . discuss . id )
617- post "/api/projects/#{ project . id } /task_def_id/#{ td2 . id } /submission" , data_to_post
618- assert_equal 409 , last_response . status , last_response_body
619- task . reload
620- # Ensure the submission was denied
621- assert_equal TaskStatus . not_started , task . task_status
622- assert_equal last_response_body [ 'error' ] , "Cannot submit this task until prerequisite '#{ td1 . abbreviation } ' has been discussed"
605+ data_to_post = with_file ( 'test_files/submissions/program.cs' , 'application/json' , data_to_post )
623606
624- prereq . update ( task_status_id : TaskStatus . demonstrate . id )
625- post "/api/projects/#{ project . id } /task_def_id/#{ td2 . id } /submission" , data_to_post
626- assert_equal 409 , last_response . status , last_response_body
627- task . reload
628- # Ensure the submission was denied
629- assert_equal TaskStatus . not_started , task . task_status
630- assert_equal last_response_body [ 'error' ] , "Cannot submit this task until prerequisite '#{ td1 . abbreviation } ' has been demonstrated "
607+ # Attempt to make a submission that has an unsubmitted prerequisite
608+ post "/api/projects/#{ project . id } /task_def_id/#{ td2 . id } /submission" , data_to_post
609+ assert_equal 409 , last_response . status , last_response_body
610+ task = project . task_for_task_definition ( td2 )
611+ # Ensure the submission was denied
612+ assert_equal TaskStatus . not_started , task . task_status
613+ assert_equal last_response_body [ 'error' ] , "Cannot submit this task until prerequisite '#{ td1 . abbreviation } ' has been submitted "
631614
632- prereq . update ( task_status_id : TaskStatus . complete . id )
633- post "/api/projects/#{ project . id } /task_def_id/#{ td2 . id } /submission" , data_to_post
634- assert_equal 409 , last_response . status , last_response_body
635- task . reload
636- # Ensure the submission was denied
637- assert_equal TaskStatus . not_started , task . task_status
638- assert_equal last_response_body [ 'error' ] , "Cannot submit this task until prerequisite '#{ td1 . abbreviation } ' has been completed "
615+ prereq . update ( task_status_id : TaskStatus . discuss . id )
616+ post "/api/projects/#{ project . id } /task_def_id/#{ td2 . id } /submission" , data_to_post
617+ assert_equal 409 , last_response . status , last_response_body
618+ task . reload
619+ # Ensure the submission was denied
620+ assert_equal TaskStatus . not_started , task . task_status
621+ assert_equal last_response_body [ 'error' ] , "Cannot submit this task until prerequisite '#{ td1 . abbreviation } ' has been discussed "
639622
640- prereq . update ( task_status_id : TaskStatus . ready_for_feedback . id )
623+ prereq . update ( task_status_id : TaskStatus . demonstrate . id )
624+ post "/api/projects/#{ project . id } /task_def_id/#{ td2 . id } /submission" , data_to_post
625+ assert_equal 409 , last_response . status , last_response_body
626+ task . reload
627+ # Ensure the submission was denied
628+ assert_equal TaskStatus . not_started , task . task_status
629+ assert_equal last_response_body [ 'error' ] , "Cannot submit this task until prerequisite '#{ td1 . abbreviation } ' has been demonstrated"
641630
642- # Make a submission to the prerequsite task
643- post "/api/projects/#{ project . id } /task_def_id/#{ td1 . id } /submission" , data_to_post
644- assert_equal 201 , last_response . status , last_response_body
645- task1 = project . task_for_task_definition ( td1 )
646- assert_equal TaskStatus . ready_for_feedback , task1 . task_status
631+ prereq . update ( task_status_id : TaskStatus . complete . id )
632+ post "/api/projects/#{ project . id } /task_def_id/#{ td2 . id } /submission" , data_to_post
633+ assert_equal 409 , last_response . status , last_response_body
634+ task . reload
635+ # Ensure the submission was denied
636+ assert_equal TaskStatus . not_started , task . task_status
637+ assert_equal last_response_body [ 'error' ] , "Cannot submit this task until prerequisite '#{ td1 . abbreviation } ' has been completed"
647638
648- # Re-attempt to make a submission (Prerequisite status is ready for feedback, expecting complete)
649- post "/api/projects/#{ project . id } /task_def_id/#{ td2 . id } /submission" , data_to_post
650- assert_equal 201 , last_response . status , last_response_body
651- task . reload
652- assert_equal TaskStatus . ready_for_feedback , task . task_status
639+ prereq . update ( task_status_id : TaskStatus . ready_for_feedback . id )
653640
654- prereq . destroy
655- unit . destroy
656- end
641+ # Use a direct status change here to avoid waiting for submission processing.
642+ task1 = project . task_for_task_definition ( td1 )
643+ task1 . submit ( project . user )
644+ assert_equal TaskStatus . ready_for_feedback , task1 . task_status
645+
646+ # Re-attempt to make a submission (Prerequisite status is ready for feedback, expecting complete)
647+ post "/api/projects/#{ project . id } /task_def_id/#{ td2 . id } /submission" , data_to_post
648+ assert_equal 201 , last_response . status , last_response_body
649+ task . reload
650+ assert_equal TaskStatus . ready_for_feedback , task . task_status
651+
652+ prereq . destroy
653+ unit . destroy
657654 end
658655
659656 def test_prerequisites_task_status
@@ -678,13 +675,6 @@ def test_prerequisites_task_status
678675
679676 project = unit . active_projects . first
680677
681- # Add username and auth_token to Header
682- add_auth_header_for ( user : project . user )
683-
684- data_to_post = {
685- trigger : 'ready_for_feedback'
686- }
687-
688678 # Create a prerequisite on the second taskDef that adds the first taskDef as a prereq
689679 prereq = TaskPrerequisite . create! (
690680 task_definition : td2 , # Before you can submit td2...
@@ -697,78 +687,53 @@ def test_prerequisites_task_status
697687 tests = [
698688 {
699689 prerequisite_status : TaskStatus . ready_for_feedback ,
700- required_status : TaskStatus . ready_for_feedback ,
701- expected_status : 201 ,
702- expected_error : nil
690+ required_status : TaskStatus . ready_for_feedback
703691 } ,
704692 {
705693 prerequisite_status : TaskStatus . discuss ,
706- required_status : TaskStatus . discuss ,
707- expected_status : 201 ,
708- expected_error : nil
694+ required_status : TaskStatus . discuss
709695 } ,
710696 {
711697 prerequisite_status : TaskStatus . demonstrate ,
712- required_status : TaskStatus . demonstrate ,
713- expected_status : 201 ,
714- expected_error : nil
698+ required_status : TaskStatus . demonstrate
715699 } ,
716700 {
717701 prerequisite_status : TaskStatus . discuss ,
718- required_status : TaskStatus . demonstrate ,
719- expected_status : 201 ,
720- expected_error : nil
702+ required_status : TaskStatus . demonstrate
721703 } ,
722704 {
723705 prerequisite_status : TaskStatus . demonstrate ,
724- required_status : TaskStatus . discuss ,
725- expected_status : 201 ,
726- expected_error : nil
706+ required_status : TaskStatus . discuss
727707 } ,
728708 {
729709 prerequisite_status : TaskStatus . complete ,
730- required_status : TaskStatus . complete ,
731- expected_status : 201 ,
732- expected_error : nil
710+ required_status : TaskStatus . complete
733711 } ,
734712 {
735713 prerequisite_status : TaskStatus . complete ,
736- required_status : TaskStatus . ready_for_feedback ,
737- expected_status : 201 ,
738- expected_error : nil
714+ required_status : TaskStatus . ready_for_feedback
739715 } ,
740716 {
741717 prerequisite_status : TaskStatus . discuss ,
742- required_status : TaskStatus . ready_for_feedback ,
743- expected_status : 201 ,
744- expected_error : nil
718+ required_status : TaskStatus . ready_for_feedback
745719 }
746720 ]
747721
748- Sidekiq ::Testing . inline! do
749- prereq_task = project . task_for_task_definition ( td1 )
750- task = project . task_for_task_definition ( td2 )
751- data_to_post = with_file ( 'test_files/submissions/program.cs' , 'application/json' , data_to_post )
752-
753- tests . each do |test |
754- prereq_task . update ( task_status_id : test [ :prerequisite_status ] . id )
755- task . update ( task_status_id : TaskStatus . not_started . id )
756-
757- post "/api/projects/#{ project . id } /task_def_id/#{ td2 . id } /submission" , data_to_post
758- assert_equal test [ :expected_status ] , last_response . status , last_response_body
759- task . reload
760- if test [ :expected_status ] == 201
761- # Ensure submission was accepted
762- assert_equal TaskStatus . ready_for_feedback , task . task_status
763- else
764- # Ensure submission was denied
765- assert_equal TaskStatus . not_started , task . task_status
766- end
767- end
722+ prereq_task = project . task_for_task_definition ( td1 )
723+ task = project . task_for_task_definition ( td2 )
724+
725+ tests . each do |test |
726+ prereq . update! ( task_status_id : test [ :required_status ] . id )
727+ prereq_task . update! ( task_status_id : test [ :prerequisite_status ] . id )
728+ task . update! ( task_status_id : TaskStatus . not_started . id , submission_date : nil )
768729
769- prereq . destroy
770- unit . destroy
730+ task . submit ( project . user )
731+ task . reload
732+ assert_equal TaskStatus . ready_for_feedback , task . task_status
771733 end
734+
735+ prereq . destroy
736+ unit . destroy
772737 end
773738
774739 def test_check_in_comment
@@ -866,66 +831,60 @@ def test_requires_discussion_blocks_complete_until_discussed_comment_added
866831 end
867832
868833 def test_require_comment_for_feedback_submission_assess_in_portfolio
869- Sidekiq ::Testing . inline! do
870- unit = FactoryBot . create ( :unit , student_count : 1 , task_count : 2 )
871- td1 = unit . task_definitions . first
872- project = unit . active_projects . first
873-
874- task = project . task_for_task_definition ( td1 )
875-
876- td1 . update (
877- upload_requirements : [ { "key" => 'file0' , "name" => 'Shape Class' , "type" => 'code' } ] ,
878- target_grade : 0 , # Pass
879- start_date : Time . zone . now - 2 . weeks ,
880- target_date : Time . zone . now + 1 . week ,
881- assess_in_portfolio_only : false
882- )
834+ unit = FactoryBot . create ( :unit , student_count : 1 , task_count : 2 )
835+ td1 = unit . task_definitions . first
836+ project = unit . active_projects . first
883837
884- add_auth_header_for ( user : project . user )
838+ task = project . task_for_task_definition ( td1 )
885839
886- # Make a submission where a comment isn't required
887- post "/api/projects/#{ project . id } /task_def_id/#{ td1 . id } /submission" ,
888- with_file ( 'test_files/submissions/program.cs' , 'application/json' , {
889- trigger : 'ready_for_feedback'
890- } )
891- assert_equal 201 , last_response . status , last_response_body
892- task . reload
893- assert_equal TaskStatus . ready_for_feedback , task . task_status
840+ td1 . update (
841+ upload_requirements : [ { "key" => 'file0' , "name" => 'Shape Class' , "type" => 'code' } ] ,
842+ target_grade : 0 , # Pass
843+ start_date : Time . zone . now - 2 . weeks ,
844+ target_date : Time . zone . now + 1 . week ,
845+ assess_in_portfolio_only : false
846+ )
847+
848+ add_auth_header_for ( user : project . user )
894849
895- task . update ( task_status : TaskStatus . not_started )
850+ # Use a direct submit here so the test can focus on the comment requirement.
851+ task . submit ( project . user )
852+ task . reload
853+ assert_equal TaskStatus . ready_for_feedback , task . task_status
896854
897- td1 . update ( assess_in_portfolio_only : true )
855+ task . update! ( task_status : TaskStatus . not_started , submission_date : nil )
898856
899- # Make a submission where a comment is required
900- post "/api/projects/#{ project . id } /task_def_id/#{ td1 . id } /submission" ,
901- with_file ( 'test_files/submissions/program.cs' , 'application/json' , {
902- trigger : 'ready_for_feedback'
903- } )
904- assert_equal 422 , last_response . status , last_response_body
905- task . reload
906- assert_equal TaskStatus . not_started , task . task_status
857+ td1 . update ( assess_in_portfolio_only : true )
907858
908- comment = 'I would like feedback with my code..'
859+ # Make a submission where a comment is required
860+ post "/api/projects/#{ project . id } /task_def_id/#{ td1 . id } /submission" ,
861+ with_file ( 'test_files/submissions/program.cs' , 'application/json' , {
862+ trigger : 'ready_for_feedback'
863+ } )
864+ assert_equal 422 , last_response . status , last_response_body
865+ task . reload
866+ assert_equal TaskStatus . not_started , task . task_status
909867
910- # Make a submission with comment
911- post "/api/projects/#{ project . id } /task_def_id/#{ td1 . id } /submission" ,
912- with_file ( 'test_files/submissions/program.cs' , 'application/json' , {
913- trigger : 'ready_for_feedback' ,
914- comment : comment
915- } )
916- assert_equal 201 , last_response . status , last_response_body
917- task . reload
918- assert_equal TaskStatus . ready_for_feedback , task . task_status
868+ comment = 'I would like feedback with my code..'
919869
920- status_comment = task . comments . last
921- text_comment = task . comments . second_to_last
870+ # Make a submission with comment
871+ post "/api/projects/#{ project . id } /task_def_id/#{ td1 . id } /submission" ,
872+ with_file ( 'test_files/submissions/program.cs' , 'application/json' , {
873+ trigger : 'ready_for_feedback' ,
874+ comment : comment
875+ } )
876+ assert_equal 201 , last_response . status , last_response_body
877+ task . reload
878+ assert_equal TaskStatus . ready_for_feedback , task . task_status
922879
923- assert_not status_comment . nil?
924- assert_not text_comment . nil?
880+ status_comment = task . comments . last
881+ text_comment = task . comments . second_to_last
925882
926- assert_equal TaskStatus . ready_for_feedback . name , status_comment . comment
927- assert_equal comment , text_comment . comment
928- end
883+ assert_not status_comment . nil?
884+ assert_not text_comment . nil?
885+
886+ assert_equal TaskStatus . ready_for_feedback . name , status_comment . comment
887+ assert_equal comment , text_comment . comment
929888 end
930889
931890 def test_resubmission_doesnt_change_submission_date
0 commit comments