|
29 | 29 | expect(response).to render_template(:index) |
30 | 30 | end |
31 | 31 |
|
| 32 | + it 'includes Lead TA enrollments in staff courses' do |
| 33 | + UserToCourse.create!(user: user, course: student_course, role: 'leadta') |
| 34 | + |
| 35 | + get :index |
| 36 | + |
| 37 | + expect(assigns(:teacher_courses).map(&:role)).to include('leadta') |
| 38 | + end |
| 39 | + |
32 | 40 | context 'semester grouping' do |
33 | 41 | let(:spring_course) { Course.create!(course_name: 'Spring Course', canvas_id: 'sp1', course_code: 'SP101', semester: 'Spring 2026') } |
34 | 42 | let(:fall_course) { Course.create!(course_name: 'Fall Course', canvas_id: 'fa1', course_code: 'FA101', semester: 'Fall 2025') } |
|
112 | 120 | expect(response).to redirect_to(courses_path) |
113 | 121 | expect(flash[:notice]).to eq('Selected courses and their assignments have been imported successfully.') |
114 | 122 | end |
| 123 | + |
| 124 | + it 'imports courses where the user is enrolled with the Canvas Lead TA role' do |
| 125 | + lead_ta_course = { |
| 126 | + 'id' => '999', |
| 127 | + 'name' => 'Lead TA Canvas Course', |
| 128 | + 'course_code' => 'LTA101', |
| 129 | + 'enrollments' => [ { 'type' => 'ta', 'role' => 'Lead TA' } ] |
| 130 | + } |
| 131 | + allow(Course).to receive(:fetch_courses).and_return([ lead_ta_course ]) |
| 132 | + allow(Course).to receive(:create_or_update_from_canvas) |
| 133 | + |
| 134 | + post :create, params: { courses: [ '999' ] } |
| 135 | + |
| 136 | + expect(Course).to have_received(:create_or_update_from_canvas).with(lead_ta_course, 'fake_token', user) |
| 137 | + end |
115 | 138 | end |
116 | 139 |
|
117 | 140 | describe 'POST #sync_assignments' do |
|
139 | 162 | headers: { 'Authorization' => 'Bearer fake_token' } |
140 | 163 | ).to_return(status: 200, body: '[]', headers: {}) |
141 | 164 | end |
| 165 | + stub_request(:get, "#{ENV.fetch('CANVAS_URL', nil)}/api/v1/courses/456/users") |
| 166 | + .with( |
| 167 | + query: { |
| 168 | + 'enrollment_role' => 'Lead TA', |
| 169 | + 'per_page' => '100' |
| 170 | + }, |
| 171 | + headers: { 'Authorization' => 'Bearer fake_token' } |
| 172 | + ).to_return(status: 200, body: '[]', headers: {}) |
142 | 173 | end |
143 | 174 |
|
144 | 175 | context 'when user is a teacher (course admin)' do |
|
215 | 246 | 'id' => '103', |
216 | 247 | 'name' => 'Test Course 103', |
217 | 248 | 'course_code' => 'TC103', |
218 | | - 'enrollments' => [ { 'type' => 'teacher' } ], |
| 249 | + 'enrollments' => [ { 'type' => 'ta', 'role' => 'Lead TA' } ], |
219 | 250 | 'term' => { 'name' => 'Fall 2025' } |
220 | 251 | }, |
221 | 252 | { |
|
246 | 277 | expect(assigns(:courses_student)).not_to be_empty |
247 | 278 |
|
248 | 279 | # Teacher course should be categorized correctly |
249 | | - teacher_course = assigns(:courses_teacher).first |
250 | | - expect(teacher_course['enrollments'].first['type']).to eq('teacher') |
| 280 | + teacher_course_roles = assigns(:courses_teacher).map { |canvas_course| canvas_course['enrollments'].first } |
| 281 | + expect(teacher_course_roles).to include(hash_including('type' => 'teacher')) |
| 282 | + expect(teacher_course_roles).to include(hash_including('role' => 'Lead TA')) |
251 | 283 |
|
252 | 284 | # Student course should be categorized correctly |
253 | 285 | student_course = assigns(:courses_student).first |
|
0 commit comments