Skip to content

Commit adae62b

Browse files
committed
testing listing lessons requests
1 parent f81eb5b commit adae62b

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

spec/features/lesson/listing_lessons_spec.rb

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
let!(:lesson) { create(:lesson, name: 'Test Lesson', visibility: 'public', user_id: teacher.id) }
1313
let(:teacher) { create(:teacher, school:, name: 'School Teacher') }
1414
let(:owner) { create(:owner, school:) }
15+
let(:student) { create(:student, school:) }
1516
let(:school) { create(:school) }
1617
let(:school_class) { create(:school_class, teacher_ids: [teacher.id], school:) }
1718
let(:another_school_class) { create(:school_class, teacher_ids: [teacher.id], school:) }
@@ -119,6 +120,17 @@
119120
expect(data.size).to eq(1)
120121
end
121122

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+
122134
context "when the lesson's visibility is 'private'" do
123135
let!(:lesson) { create(:lesson, name: 'Test Lesson', visibility: 'private') }
124136
let(:owner) { create(:owner, school:) }
@@ -172,7 +184,6 @@
172184
end
173185

174186
it 'does not include the lesson when the user is a school-student' do
175-
student = create(:student, school:)
176187
authenticated_in_hydra_as(student)
177188

178189
get('/api/lessons', headers:)
@@ -200,7 +211,6 @@
200211
end
201212

202213
it "includes the lesson when the user is a school-student within the lesson's class" do
203-
student = create(:student, school:)
204214
authenticated_in_hydra_as(student)
205215
create(:class_student, school_class:, student_id: student.id)
206216

@@ -210,8 +220,16 @@
210220
expect(data.size).to eq(1)
211221
end
212222

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+
213232
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:)
215233
authenticated_in_hydra_as(student)
216234

217235
get('/api/lessons', headers:)

0 commit comments

Comments
 (0)