|
12 | 12 | let!(:lesson) { create(:lesson, name: 'Test Lesson', visibility: 'public', user_id: teacher.id) } |
13 | 13 | let(:teacher) { create(:teacher, school:, name: 'School Teacher') } |
14 | 14 | let(:owner) { create(:owner, school:) } |
| 15 | + let(:student) { create(:student, school:) } |
15 | 16 | let(:school) { create(:school) } |
16 | 17 | let(:school_class) { create(:school_class, teacher_ids: [teacher.id], school:) } |
17 | 18 | let(:another_school_class) { create(:school_class, teacher_ids: [teacher.id], school:) } |
|
119 | 120 | expect(data.size).to eq(1) |
120 | 121 | end |
121 | 122 |
|
| 123 | + it 'includes the submitted_count for each lesson' do |
| 124 | + lesson.update!(school_class_id: school_class.id) |
| 125 | + remix = create(:project, school:, remixed_from_id: lesson.project.id, user_id: student.id) |
| 126 | + remix.school_project.transition_status_to!(:submitted, student.id) |
| 127 | + |
| 128 | + get("/api/lessons?school_class_id=#{school_class.id}", headers:) |
| 129 | + data = JSON.parse(response.body, symbolize_names: true) |
| 130 | + |
| 131 | + expect(data.first[:submitted_count]).to eq(1) |
| 132 | + end |
| 133 | + |
122 | 134 | context "when the lesson's visibility is 'private'" do |
123 | 135 | let!(:lesson) { create(:lesson, name: 'Test Lesson', visibility: 'private') } |
124 | 136 | let(:owner) { create(:owner, school:) } |
|
172 | 184 | end |
173 | 185 |
|
174 | 186 | it 'does not include the lesson when the user is a school-student' do |
175 | | - student = create(:student, school:) |
176 | 187 | authenticated_in_hydra_as(student) |
177 | 188 |
|
178 | 189 | get('/api/lessons', headers:) |
|
200 | 211 | end |
201 | 212 |
|
202 | 213 | it "includes the lesson when the user is a school-student within the lesson's class" do |
203 | | - student = create(:student, school:) |
204 | 214 | authenticated_in_hydra_as(student) |
205 | 215 | create(:class_student, school_class:, student_id: student.id) |
206 | 216 |
|
|
210 | 220 | expect(data.size).to eq(1) |
211 | 221 | end |
212 | 222 |
|
| 223 | + it 'does not include the submitted_count when the user is a school-student within the lesson\'s class' do |
| 224 | + authenticated_in_hydra_as(student) |
| 225 | + create(:class_student, school_class:, student_id: student.id) |
| 226 | + |
| 227 | + get('/api/lessons', headers:) |
| 228 | + data = JSON.parse(response.body, symbolize_names: true) |
| 229 | + expect(data.first).not_to have_key(:submitted_count) |
| 230 | + end |
| 231 | + |
213 | 232 | it "does not include the lesson when the user is not a school-student within the lesson's class" do |
214 | | - student = create(:student, school:) |
215 | 233 | authenticated_in_hydra_as(student) |
216 | 234 |
|
217 | 235 | get('/api/lessons', headers:) |
|
0 commit comments