Skip to content

Commit d21f3b9

Browse files
committed
testing
1 parent 766ca77 commit d21f3b9

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

spec/features/school_class/listing_school_classes_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,28 @@
5353
expect(data.first[:teachers].first).to be_nil
5454
end
5555

56+
it 'includes submitted_count if user is a school-teacher' do
57+
authenticated_in_hydra_as(teacher)
58+
get("/api/schools/#{school.id}/classes", headers:)
59+
data = JSON.parse(response.body, symbolize_names: true)
60+
expect(data.first).to have_key(:submitted_count)
61+
end
62+
63+
it 'includes submitted_count if user is a school-owner' do
64+
authenticated_in_hydra_as(owner)
65+
get("/api/schools/#{school.id}/classes", headers:)
66+
data = JSON.parse(response.body, symbolize_names: true)
67+
expect(data.first).to have_key(:submitted_count)
68+
end
69+
70+
it 'does not include submitted_count if user is a school-student' do
71+
authenticated_in_hydra_as(student)
72+
stub_user_info_api_for(teacher)
73+
get("/api/schools/#{school.id}/classes", headers:)
74+
data = JSON.parse(response.body, symbolize_names: true)
75+
expect(data.first).not_to have_key(:submitted_count)
76+
end
77+
5678
it "does not include school classes that the school-teacher doesn't teach" do
5779
teacher = create(:teacher, school:)
5880
authenticated_in_hydra_as(teacher)

spec/models/school_class_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,29 @@
262262
end
263263
end
264264

265+
describe '#submitted_count' do
266+
it 'returns 0 if there are no lessons' do
267+
school_class = create(:school_class, teacher_ids: [teacher.id], school:)
268+
expect(school_class.submitted_count).to eq(0)
269+
end
270+
271+
it 'returns the sum of submitted counts from all lessons' do
272+
school_class = create(:school_class, teacher_ids: [teacher.id], school:)
273+
274+
lesson_1 = create(:lesson, school_class:, user_id: teacher.id)
275+
remix_1 = create(:project, school:, remixed_from_id: lesson_1.project.id, user_id: student.id)
276+
remix_1.school_project.transition_status_to!(:submitted, remix_1.user_id)
277+
278+
lesson_2 = create(:lesson, school_class:, user_id: teacher.id)
279+
remix_2 = create(:project, school:, remixed_from_id: lesson_2.project.id, user_id: student.id)
280+
remix_2.school_project.transition_status_to!(:submitted, remix_2.user_id)
281+
remix_3 = create(:project, school:, remixed_from_id: lesson_2.project.id, user_id: student.id)
282+
remix_3.school_project.transition_status_to!(:submitted, remix_3.user_id)
283+
284+
expect(school_class.submitted_count).to eq(3)
285+
end
286+
end
287+
265288
describe 'auditing' do
266289
subject(:school_class) { create(:school_class, teacher_ids: [teacher.id], school:) }
267290

0 commit comments

Comments
 (0)