Skip to content

Commit aa1cba5

Browse files
committed
Add basic tests
1 parent 8aae49d commit aa1cba5

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

spec/features/school_class/listing_school_classes_spec.rb

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,67 @@
109109
get("/api/schools/#{school.id}/classes/#{school_class.id}/members", headers:)
110110
expect(response).to have_http_status(:forbidden)
111111
end
112+
113+
it 'includes unread_feedback_count for a school-student' do
114+
authenticated_in_hydra_as(student)
115+
stub_user_info_api_for(teacher)
116+
117+
lesson = create(
118+
:lesson,
119+
school: school,
120+
school_class: school_class,
121+
visibility: 'students',
122+
user_id: teacher.id
123+
)
124+
125+
remix = create(
126+
:project,
127+
school: school,
128+
lesson: lesson,
129+
parent: lesson.project,
130+
remixed_from_id: lesson.project.id,
131+
user_id: student.id
132+
)
133+
134+
create(
135+
:feedback,
136+
school_project: remix.school_project,
137+
user_id: teacher.id,
138+
content: 'Not read',
139+
read_at: nil
140+
)
141+
142+
create(
143+
:feedback,
144+
school_project: remix.school_project,
145+
user_id: teacher.id,
146+
content: 'Already read',
147+
read_at: Time.current
148+
)
149+
150+
get("/api/schools/#{school.id}/classes", headers:)
151+
152+
data = JSON.parse(response.body, symbolize_names: true)
153+
this_class = data.find { |c| c[:name] == 'Test School Class' }
154+
155+
expect(this_class[:unread_feedback_count]).to eq(1)
156+
end
157+
158+
it 'does not include unread_feedback_count if user is a school-teacher' do
159+
authenticated_in_hydra_as(teacher)
160+
161+
get("/api/schools/#{school.id}/classes", headers:)
162+
data = JSON.parse(response.body, symbolize_names: true)
163+
164+
expect(data.first).not_to have_key(:unread_feedback_count)
165+
end
166+
167+
it 'does not include unread_feedback_count if user is a school-owner' do
168+
authenticated_in_hydra_as(owner)
169+
170+
get("/api/schools/#{school.id}/classes", headers:)
171+
data = JSON.parse(response.body, symbolize_names: true)
172+
173+
expect(data.first).not_to have_key(:unread_feedback_count)
174+
end
112175
end

0 commit comments

Comments
 (0)