From b3b5dbd5ab34af92fea0502b4202e583bd1ea8de Mon Sep 17 00:00:00 2001 From: James Williams Date: Mon, 24 Aug 2020 15:26:45 -0600 Subject: [PATCH] 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 Reviewed-by: Jackson Howe QA-Review: Robin Kuss Product-Review: James Williams --- app/controllers/enrollments_api_controller.rb | 2 +- spec/apis/v1/enrollments_api_spec.rb | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/controllers/enrollments_api_controller.rb b/app/controllers/enrollments_api_controller.rb index bee02d0d256..381b9e843a7 100644 --- a/app/controllers/enrollments_api_controller.rb +++ b/app/controllers/enrollments_api_controller.rb @@ -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 diff --git a/spec/apis/v1/enrollments_api_spec.rb b/spec/apis/v1/enrollments_api_spec.rb index 8f5b29bdb57..831d65002dd 100644 --- a/spec/apis/v1/enrollments_api_spec.rb +++ b/spec/apis/v1/enrollments_api_spec.rb @@ -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!