Skip to content

Commit 7cae8f8

Browse files
committed
Add tests for data being returned
1 parent 1490e69 commit 7cae8f8

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

spec/features/lesson/listing_lessons_spec.rb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,5 +258,53 @@
258258

259259
expect(data.size).to eq(0)
260260
end
261+
262+
it 'includes unread_feedback_count when the user is a student' do
263+
authenticated_in_hydra_as(student)
264+
create(:class_student, school_class:, student_id: student.id)
265+
student_project = create(
266+
:project,
267+
school:,
268+
lesson:,
269+
parent: lesson.project,
270+
remixed_from_id: lesson.project.id,
271+
user_id: student.id
272+
)
273+
school_project = student_project.school_project
274+
create(
275+
:feedback,
276+
school_project: school_project,
277+
user_id: teacher.id,
278+
content: 'Unread',
279+
read_at: nil
280+
)
281+
create(
282+
:feedback,
283+
school_project: school_project,
284+
user_id: teacher.id,
285+
content: 'Read',
286+
read_at: Time.current
287+
)
288+
289+
get('/api/lessons', headers:)
290+
data = JSON.parse(response.body, symbolize_names: true)
291+
expect(data.first[:unread_feedback_count]).to eq(1)
292+
end
293+
294+
it 'includes status when the user is a student' do
295+
authenticated_in_hydra_as(student)
296+
create(:class_student, school_class:, student_id: student.id)
297+
298+
lesson.project.update!(school: school)
299+
school_project = lesson.project.school_project
300+
301+
school_project.transition_status_to!(:submitted, teacher.id)
302+
303+
get('/api/lessons', headers:)
304+
data = JSON.parse(response.body, symbolize_names: true)
305+
306+
expect(data.size).to eq(1)
307+
expect(data.first[:status]).to eq('submitted')
308+
end
261309
end
262310
end

0 commit comments

Comments
 (0)