Skip to content

Commit

Permalink
feat(stats): show grades for graded state
Browse files Browse the repository at this point in the history
- previously, only "published" state is allowed the view.
- Now, we allow both "graded" and "published" the view of grades on stats
- also add the tests that reflects on this
  • Loading branch information
bivanalhar authored and cysjonathan committed Aug 26, 2024
1 parent 993a0c4 commit c2307ba
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ json.submissions @student_submissions_hash.each do |course_user, (submission, an
json.name name
end

if !submission.nil? && submission.workflow_state == 'published' && submission.grader_ids
if !submission.nil? && (submission.graded? || submission.published?) && submission.grader_ids
# the graders are all the same regardless of question, so we just pick the first one
json.partial! 'answer', grader: @course_users_hash[submission.grader_ids.first], answers: answers
json.partial! 'attempt_status', answers: answers
Expand Down
32 changes: 21 additions & 11 deletions spec/controllers/course/statistics/assessment_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

let(:assessment) { course.assessments.first }

let(:students) { create_list(:course_student, 3, course: course) }
let(:students) { create_list(:course_student, 4, course: course) }
let(:teaching_assistant) { create(:course_teaching_assistant, course: course) }

let!(:submission1) do
Expand All @@ -27,6 +27,10 @@
create(:submission, :attempting,
assessment: assessment, course: course, creator: students[1].user)
end
let!(:submission3) do
create(:submission, :graded,
assessment: assessment, course: course, creator: students[2].user)
end
let!(:submission_teaching_assistant) do
create(:submission, :published,
assessment: assessment, course: course, creator: teaching_assistant.user)
Expand Down Expand Up @@ -57,22 +61,25 @@
json_result = JSON.parse(response.body)

# all the students data will be included here, including the non-existing submission one
expect(json_result['submissions'].count).to eq(3)
expect(json_result['submissions'].count).to eq(4)

# showing the correct workflow state
expect(json_result['submissions'][0]['workflowState']).to eq('published')
expect(json_result['submissions'][1]['workflowState']).to eq('attempting')
expect(json_result['submissions'][2]['workflowState']).to eq('unstarted')
expect(json_result['submissions'][2]['workflowState']).to eq('graded')
expect(json_result['submissions'][3]['workflowState']).to eq('unstarted')

# only published submissions' answers will be included in the stats
# only graded and published submissions' answers will be included in the stats
expect(json_result['submissions'][0]['answers']).not_to be_nil
expect(json_result['submissions'][1]['answers']).to be_nil
expect(json_result['submissions'][2]['answers']).to be_nil
expect(json_result['submissions'][2]['answers']).not_to be_nil
expect(json_result['submissions'][3]['answers']).to be_nil

# only published submissions' answers will be included in the stats
# only graded and published submissions' answers will be included in the stats
expect(json_result['submissions'][0]['courseUser']['role']).to eq('student')
expect(json_result['submissions'][1]['courseUser']['role']).to eq('student')
expect(json_result['submissions'][2]['courseUser']['role']).to eq('student')
expect(json_result['submissions'][3]['courseUser']['role']).to eq('student')

# only 1 ancestor will be returned (current) as no permission for ancestor assessment
expect(json_result['ancestors'].count).to eq(1)
Expand All @@ -88,22 +95,25 @@
json_result = JSON.parse(response.body)

# all the students data will be included here, including the non-existing submission one
expect(json_result['submissions'].count).to eq(3)
expect(json_result['submissions'].count).to eq(4)

# showing the correct workflow state
expect(json_result['submissions'][0]['workflowState']).to eq('published')
expect(json_result['submissions'][1]['workflowState']).to eq('attempting')
expect(json_result['submissions'][2]['workflowState']).to eq('unstarted')
expect(json_result['submissions'][2]['workflowState']).to eq('graded')
expect(json_result['submissions'][3]['workflowState']).to eq('unstarted')

# only published submissions' answers will be included in the stats
# only graded and published submissions' answers will be included in the stats
expect(json_result['submissions'][0]['answers']).not_to be_nil
expect(json_result['submissions'][1]['answers']).to be_nil
expect(json_result['submissions'][2]['answers']).to be_nil
expect(json_result['submissions'][2]['answers']).not_to be_nil
expect(json_result['submissions'][3]['answers']).to be_nil

# only published submissions' answers will be included in the stats
# only graded and published submissions' answers will be included in the stats
expect(json_result['submissions'][0]['courseUser']['role']).to eq('student')
expect(json_result['submissions'][1]['courseUser']['role']).to eq('student')
expect(json_result['submissions'][2]['courseUser']['role']).to eq('student')
expect(json_result['submissions'][3]['courseUser']['role']).to eq('student')

expect(json_result['ancestors'].count).to eq(2)
end
Expand Down

0 comments on commit c2307ba

Please sign in to comment.