diff --git a/Changelog.md b/Changelog.md index 8de31a944f..a77f70fefd 100644 --- a/Changelog.md +++ b/Changelog.md @@ -28,6 +28,7 @@ - Fix: include original total mark in JSON response for remark requests (#7945) ### 🔧 Internal changes +- Added tests for `MarksGradersController` to achieve full test coverage for `randomly_assign` (#7947) - Added tests for `graders_controller` to fully cover `grader_criteria_mapping` function (#7949) - Added tests for `GradersController` to fully cover `grader_groupers_mapping` (#7946) - Added seed task to assign TAs to A1 groupings and criteria (#7867) diff --git a/doc/markus-contributors.txt b/doc/markus-contributors.txt index 3915d2ac4e..151374e33d 100644 --- a/doc/markus-contributors.txt +++ b/doc/markus-contributors.txt @@ -57,6 +57,7 @@ Clément Delafargue Clément Schiano Danesh Dadachanji Daniel Dervishi +Daniel Rafailov Daniel St. Jules Daniyal Liaqat Daryn Lam diff --git a/spec/controllers/marks_graders_controller_spec.rb b/spec/controllers/marks_graders_controller_spec.rb index 2a590ec2b5..3837b9ac82 100644 --- a/spec/controllers/marks_graders_controller_spec.rb +++ b/spec/controllers/marks_graders_controller_spec.rb @@ -376,4 +376,87 @@ end end end + + describe '#randomly_assign' do + before do + allow(GradeEntryStudent).to receive(:randomly_assign_tas) + end + + context 'when students and graders are selected' do + it 'calls GradeEntryStudent `randomly_assign_tas` and returns a success response' do + student = create(:student) + grade_entry_student = grade_entry_form.grade_entry_students.find_or_create_by(role: student) + grade_entry_student_ta = create(:grade_entry_student_ta, grade_entry_student: grade_entry_student) + + expect(GradeEntryStudent).to receive(:randomly_assign_tas).with( + [grade_entry_student.id.to_s], + [grade_entry_student_ta.id.to_s], + grade_entry_form + ) + + post_as instructor, :randomly_assign, params: { + course_id: course.id, + grade_entry_form_id: grade_entry_form.id, + students: [grade_entry_student.id], + graders: [grade_entry_student_ta.id] + } + + expect(response).to have_http_status(:ok) + end + end + + context 'when students are not selected' do + it 'returns bad request and sets a flash error' do + post_as instructor, :randomly_assign, params: { + course_id: course.id, + grade_entry_form_id: grade_entry_form.id, + students: [], + graders: [1] + } + + expect(response).to have_http_status(:bad_request) + expect(flash[:error]).to have_message(I18n.t('groups.select_a_student')) + end + end + + context 'when graders are not selected' do + it 'returns bad request and sets flash error' do + post_as instructor, :randomly_assign, params: { + course_id: course.id, + grade_entry_form_id: grade_entry_form.id, + students: [1], + graders: [] + } + + expect(response).to have_http_status(:bad_request) + expect(flash[:error]).to have_message(I18n.t('graders.select_a_grader')) + end + end + + context 'when students parameter is missing' do + it 'returns bad request and sets flash error' do + post_as instructor, :randomly_assign, params: { + course_id: course.id, + grade_entry_form_id: grade_entry_form.id, + graders: [1] + } + + expect(response).to have_http_status(:bad_request) + expect(flash[:error]).to have_message(I18n.t('groups.select_a_student')) + end + end + + context 'when graders parameter is missing' do + it 'returns bad request and sets flash error' do + post_as instructor, :randomly_assign, params: { + course_id: course.id, + grade_entry_form_id: grade_entry_form.id, + students: [1] + } + + expect(response).to have_http_status(:bad_request) + expect(flash[:error]).to have_message(I18n.t('graders.select_a_grader')) + end + end + end end