don't count student-view student in course api total_students
test plan: ensure the API endpoint below does not include the student view student in total counts api/v1/courses/X?include=total_students fixes ADMIN-800 Change-Id: I706bcdabdf2cba9031c8b5649a89370e1f0471e9 Reviewed-on: https://gerrit.instructure.com/141685 Tested-by: Jenkins Reviewed-by: Jon Willesen <jonw+gerrit@instructure.com> QA-Review: Jon Willesen <jonw+gerrit@instructure.com> Product-Review: Jeremy Stanley <jeremy@instructure.com>
This commit is contained in:
parent
ec2696e118
commit
c78eeae6f9
|
@ -90,7 +90,7 @@ module Api::V1::Course
|
|||
hash['course_progress'] = CourseProgress.new(course, subject_user).to_json if includes.include?('course_progress')
|
||||
hash['apply_assignment_group_weights'] = course.apply_group_weights?
|
||||
hash['sections'] = section_enrollments_json(enrollments) if includes.include?('sections')
|
||||
hash['total_students'] = course.student_count || course.students.count if includes.include?('total_students')
|
||||
hash['total_students'] = course.student_count || course.student_enrollments.not_fake.distinct.count(:user_id) if includes.include?('total_students')
|
||||
hash['passback_status'] = post_grades_status_json(course) if includes.include?('passback_status')
|
||||
hash['is_favorite'] = course.favorite_for_user?(user) if includes.include?('favorites')
|
||||
hash['teachers'] = course.teachers.map { |teacher| user_display_json(teacher) } if includes.include?('teachers')
|
||||
|
|
|
@ -135,6 +135,24 @@ describe Api::V1::Course do
|
|||
expect(json['total_students']).to eq 1
|
||||
end
|
||||
|
||||
it "counts students with multiple enrollments once in 'total students'" do
|
||||
section = @course2.course_sections.create! name: 'other section'
|
||||
@course2.enroll_student @student, section: section, allow_multiple_enrollments: true
|
||||
expect(@course2.student_enrollments.count).to eq 2
|
||||
|
||||
json = @test_api.course_json(@course2, @me, {}, ['total_students'], [])
|
||||
expect(json).to include('total_students')
|
||||
expect(json['total_students']).to eq 1
|
||||
end
|
||||
|
||||
it "excludes the student view student in 'total students'" do
|
||||
@course2.student_view_student
|
||||
json = @test_api.course_json(@course2, @me, {}, ['total_students'], [])
|
||||
|
||||
expect(json).to include('total_students')
|
||||
expect(json['total_students']).to eq 1
|
||||
end
|
||||
|
||||
it "includes the course nickname if one is set" do
|
||||
@me.course_nicknames[@course1.id] = 'nickname'
|
||||
json = @test_api.course_json(@course1, @me, {}, [], [])
|
||||
|
@ -518,6 +536,7 @@ describe CoursesController, type: :request do
|
|||
|
||||
it "returns 200 success" do
|
||||
api_call(:put, @path, @params, { :event => 'undelete', :course_ids => [@course.id] })
|
||||
expect(response).to be_success
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue