|
109 | 109 | get("/api/schools/#{school.id}/classes/#{school_class.id}/members", headers:) |
110 | 110 | expect(response).to have_http_status(:forbidden) |
111 | 111 | 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 |
112 | 175 | end |
0 commit comments