Skip to content
Open
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions doc/markus-contributors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Clément Delafargue
Clément Schiano
Danesh Dadachanji
Daniel Dervishi
Daniel Rafailov
Daniel St. Jules
Daniyal Liaqat
Daryn Lam
Expand Down
83 changes: 83 additions & 0 deletions spec/controllers/marks_graders_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code and the above line can be simplified, as we provide a factory for grade entry students directly. This means that you can use create(:grade_entry_student), you just need to also specify the associated grade_entry_form

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
Loading