|
6 | 6 | before do |
7 | 7 | authenticated_in_hydra_as(owner) |
8 | 8 | stub_user_info_api_for(teacher) |
| 9 | + create(:class_student, school_class:, student_id: student.id) |
9 | 10 | end |
10 | 11 |
|
11 | 12 | let(:headers) { { Authorization: UserProfileMock::TOKEN } } |
|
199 | 200 | let!(:lesson) { create(:lesson, school_class:, name: 'Test Lesson', visibility: 'students', user_id: teacher.id) } |
200 | 201 | let(:teacher) { create(:teacher, school:) } |
201 | 202 |
|
| 203 | + let(:student_project) do |
| 204 | + create( |
| 205 | + :project, |
| 206 | + school:, |
| 207 | + lesson:, |
| 208 | + parent: lesson.project, |
| 209 | + remixed_from_id: lesson.project.id, |
| 210 | + user_id: student.id |
| 211 | + ) |
| 212 | + end |
| 213 | + |
| 214 | + let(:school_project) { student_project.school_project } |
| 215 | + |
202 | 216 | it 'includes the lesson when the user owns the lesson' do |
203 | 217 | another_teacher = create(:teacher, school:) |
204 | 218 | authenticated_in_hydra_as(another_teacher) |
|
212 | 226 |
|
213 | 227 | it "includes the lesson when the user is a school-student within the lesson's class" do |
214 | 228 | authenticated_in_hydra_as(student) |
215 | | - create(:class_student, school_class:, student_id: student.id) |
216 | | - |
217 | 229 | get('/api/lessons', headers:) |
218 | 230 | data = JSON.parse(response.body, symbolize_names: true) |
219 | 231 |
|
|
222 | 234 |
|
223 | 235 | it 'does not include the submitted_count when the user is a school-student within the lesson\'s class' do |
224 | 236 | authenticated_in_hydra_as(student) |
225 | | - create(:class_student, school_class:, student_id: student.id) |
226 | | - |
227 | 237 | get('/api/lessons', headers:) |
228 | 238 | data = JSON.parse(response.body, symbolize_names: true) |
229 | 239 | expect(data.first).not_to have_key(:submitted_count) |
230 | 240 | end |
231 | 241 |
|
232 | 242 | it "includes the remix identifier when the user has remixed the lesson's project" do |
233 | | - student = create(:student, school:) |
234 | 243 | authenticated_in_hydra_as(student) |
235 | | - create(:class_student, school_class:, student_id: student.id) |
236 | | - student_project = create(:project, school:, lesson:, parent: lesson.project, user_id: student.id) |
| 244 | + student_project = create(:project, school:, lesson:, parent: lesson.project, remixed_from_id: lesson.project.id, user_id: student.id) |
237 | 245 |
|
238 | 246 | get('/api/lessons', headers:) |
239 | 247 | data = JSON.parse(response.body, symbolize_names: true) |
240 | 248 | expect(data.first[:remix_identifier]).to eq(student_project.identifier) |
241 | 249 | end |
242 | 250 |
|
243 | 251 | it "does not include the lesson when the user is not a school-student within the lesson's class" do |
244 | | - authenticated_in_hydra_as(student) |
| 252 | + another_student = create(:student, school:) |
| 253 | + authenticated_in_hydra_as(another_student) |
245 | 254 |
|
246 | 255 | get('/api/lessons', headers:) |
247 | 256 | data = JSON.parse(response.body, symbolize_names: true) |
|
258 | 267 |
|
259 | 268 | expect(data.size).to eq(0) |
260 | 269 | end |
| 270 | + |
| 271 | + it 'includes has_unread_feedback as true when there is unread feedback' do |
| 272 | + authenticated_in_hydra_as(student) |
| 273 | + create( |
| 274 | + :feedback, |
| 275 | + school_project: school_project, |
| 276 | + user_id: teacher.id, |
| 277 | + content: 'Unread', |
| 278 | + read_at: nil |
| 279 | + ) |
| 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 | + |
| 292 | + expect(data.first[:has_unread_feedback]).to be(true) |
| 293 | + end |
| 294 | + |
| 295 | + it 'includes has_unread_feedback as false when there is no unread feedback' do |
| 296 | + authenticated_in_hydra_as(student) |
| 297 | + create( |
| 298 | + :feedback, |
| 299 | + school_project: school_project, |
| 300 | + user_id: teacher.id, |
| 301 | + content: 'Read', |
| 302 | + read_at: Time.current |
| 303 | + ) |
| 304 | + |
| 305 | + get('/api/lessons', headers:) |
| 306 | + data = JSON.parse(response.body, symbolize_names: true) |
| 307 | + |
| 308 | + expect(data.first[:has_unread_feedback]).to be(false) |
| 309 | + end |
| 310 | + |
| 311 | + it 'includes status when the user is a student' do |
| 312 | + authenticated_in_hydra_as(student) |
| 313 | + school_project.transition_status_to!(:submitted, teacher.id) |
| 314 | + |
| 315 | + get('/api/lessons', headers:) |
| 316 | + data = JSON.parse(response.body, symbolize_names: true) |
| 317 | + |
| 318 | + expect(data.size).to eq(1) |
| 319 | + expect(data.first[:status]).to eq('submitted') |
| 320 | + end |
| 321 | + |
| 322 | + it 'includes the default status when no transitions have happened' do |
| 323 | + authenticated_in_hydra_as(student) |
| 324 | + create( |
| 325 | + :project, |
| 326 | + school:, |
| 327 | + lesson:, |
| 328 | + parent: lesson.project, |
| 329 | + remixed_from_id: lesson.project.id, |
| 330 | + user_id: student.id |
| 331 | + ) |
| 332 | + |
| 333 | + get('/api/lessons', headers:) |
| 334 | + data = JSON.parse(response.body, symbolize_names: true) |
| 335 | + |
| 336 | + expect(data.first[:status]).to eq('unsubmitted') |
| 337 | + end |
| 338 | + |
| 339 | + it 'does not include the status when the user is a teacher' do |
| 340 | + authenticated_in_hydra_as(teacher) |
| 341 | + |
| 342 | + get('/api/lessons', headers:) |
| 343 | + data = JSON.parse(response.body, symbolize_names: true) |
| 344 | + |
| 345 | + expect(data.first).not_to have_key(:status) |
| 346 | + end |
| 347 | + |
| 348 | + it 'does not include has_unread_feedback when the user is a teacher' do |
| 349 | + authenticated_in_hydra_as(teacher) |
| 350 | + |
| 351 | + get('/api/lessons', headers:) |
| 352 | + data = JSON.parse(response.body, symbolize_names: true) |
| 353 | + |
| 354 | + expect(data.first).not_to have_key(:has_unread_feedback) |
| 355 | + end |
261 | 356 | end |
262 | 357 | end |
0 commit comments