include pending enrollments in current_and_future API scope

test plan:
* have a course set to begin in the future with
 users restricted to participate between course dates
* enroll an observer in the future course
* /api/v1/users/self/enrollments?state[]=current_and_future
 should return the future enrollment

closes #LS-1384

Change-Id: I261f78b4f49efbf406aeb450b55c29b1825b3a99
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/245911
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Jackson Howe <jackson.howe@instructure.com>
QA-Review: Robin Kuss <rkuss@instructure.com>
Product-Review: James Williams <jamesw@instructure.com>
This commit is contained in:
James Williams 2020-08-24 15:26:45 -06:00
parent 0a1f6164ca
commit b3b5dbd5ab
2 changed files with 14 additions and 2 deletions

View File

@ -998,7 +998,7 @@ class EnrollmentsApiController < ApplicationController
def enrollment_states_for_state_param
states = Array(params[:state]).uniq
states.concat(%w(active invited)) if states.delete 'current_and_invited'
states.concat(%w(active invited creation_pending)) if states.delete 'current_and_future'
states.concat(%w(active invited creation_pending pending_active pending_invited)) if states.delete 'current_and_future'
states.concat(%w(active completed)) if states.delete 'current_and_concluded'
states.uniq
end

View File

@ -1803,7 +1803,7 @@ describe EnrollmentsApiController, type: :request do
it "should show enrollments for courses that aren't published if state[]=current_and_future" do
course_factory
@course.claim
enrollment = course_factory.enroll_student(@user)
enrollment = @course.enroll_student(@user)
enrollment.update_attribute(:workflow_state, 'active')
json = api_call(:get, @user_path,
@ -1811,6 +1811,18 @@ describe EnrollmentsApiController, type: :request do
expect(json.map { |e| e['id'] }).to include enrollment.id
end
it "should show enrollments for courses with future start dates if state[]=current_and_future" do
course_factory
@course.update_attributes(:start_at => 1.week.from_now, :restrict_enrollments_to_course_dates => true)
enrollment = @course.enroll_student(@user)
enrollment.update_attribute(:workflow_state, 'active')
expect(enrollment.enrollment_state.state).to eq "pending_active"
json = api_call(:get, @user_path,
@user_params.merge(:state => %w{current_and_future}, :type => %w{StudentEnrollment}))
expect(json.map { |e| e['id'] }).to include enrollment.id
end
it "should accept multiple state[] filters" do
course_factory
@course.offer!