|
3 | 3 | require 'rails_helper'
|
4 | 4 |
|
5 | 5 | RSpec.describe 'Project show requests' do
|
6 |
| - let!(:project) { create(:project, user_id: owner.id, locale: nil) } |
7 |
| - let(:project_json) do |
8 |
| - { |
9 |
| - identifier: project.identifier, |
10 |
| - project_type: 'python', |
11 |
| - locale: project.locale, |
12 |
| - name: project.name, |
13 |
| - user_id: project.user_id, |
14 |
| - components: [], |
15 |
| - image_list: [] |
16 |
| - }.to_json |
17 |
| - end |
18 | 6 | let(:headers) { {} }
|
19 |
| - let(:owner) { create(:owner, school:) } |
| 7 | + let(:teacher) { create(:teacher, school:) } |
20 | 8 | let(:school) { create(:school) }
|
21 | 9 |
|
22 | 10 | context 'when user is logged in' do
|
23 | 11 | let(:headers) { { Authorization: UserProfileMock::TOKEN } }
|
24 | 12 |
|
25 | 13 | before do
|
26 |
| - authenticated_in_hydra_as(owner) |
| 14 | + authenticated_in_hydra_as(teacher) |
| 15 | + stub_profile_api_list_school_students(school:, student_attributes: [{ name: 'Joe Bloggs' }]) |
27 | 16 | end
|
28 | 17 |
|
29 | 18 | context 'when loading own project' do
|
| 19 | + let!(:project) { create(:project, user_id: teacher.id, locale: nil) } |
| 20 | + let(:project_json) do |
| 21 | + { |
| 22 | + identifier: project.identifier, |
| 23 | + project_type: 'python', |
| 24 | + locale: project.locale, |
| 25 | + name: project.name, |
| 26 | + user_id: project.user_id, |
| 27 | + components: [], |
| 28 | + image_list: [] |
| 29 | + }.to_json |
| 30 | + end |
| 31 | + |
30 | 32 | it 'returns success response' do
|
31 | 33 | get("/api/projects/#{project.identifier}", headers:)
|
32 | 34 |
|
|
44 | 46 | end
|
45 | 47 | end
|
46 | 48 |
|
| 49 | + context 'when loading a student\'s project' do |
| 50 | + let(:student) { create(:student, school:) } |
| 51 | + let(:lesson) { build(:lesson, school:, user_id: teacher.id, visibility: 'students') } |
| 52 | + let(:teacher_project) { create(:project, school_id: school.id, lesson_id: lesson.id, user_id: teacher.id, locale: nil) } |
| 53 | + let!(:student_project) { create(:project, school_id: school.id, lesson_id: nil, user_id: student.id, remixed_from_id: teacher_project.id, locale: nil) } |
| 54 | + let(:student_project_json) do |
| 55 | + { |
| 56 | + identifier: student_project.identifier, |
| 57 | + project_type: 'python', |
| 58 | + locale: student_project.locale, |
| 59 | + name: student_project.name, |
| 60 | + user_id: student_project.user_id, |
| 61 | + parent: { |
| 62 | + name: teacher_project.name, |
| 63 | + identifier: teacher_project.identifier |
| 64 | + }, |
| 65 | + components: [], |
| 66 | + image_list: [], |
| 67 | + user_name: 'Joe Bloggs' |
| 68 | + }.to_json |
| 69 | + end |
| 70 | + |
| 71 | + it 'returns success response' do |
| 72 | + get("/api/projects/#{student_project.identifier}", headers:) |
| 73 | + expect(response).to have_http_status(:ok) |
| 74 | + end |
| 75 | + |
| 76 | + it 'includes the student\'s name in the project json' do |
| 77 | + get("/api/projects/#{student_project.identifier}", headers:) |
| 78 | + expect(response.body).to eq(student_project_json) |
| 79 | + end |
| 80 | + end |
| 81 | + |
47 | 82 | context 'when loading another user\'s project' do
|
48 | 83 | let!(:another_project) { create(:project, user_id: SecureRandom.uuid, locale: nil) }
|
49 | 84 | let(:another_project_json) do
|
|
115 | 150 | end
|
116 | 151 |
|
117 | 152 | context 'when loading an owned project' do
|
| 153 | + let!(:project) { create(:project, user_id: teacher.id, locale: nil) } |
| 154 | + let(:project_json) do |
| 155 | + { |
| 156 | + identifier: project.identifier, |
| 157 | + project_type: 'python', |
| 158 | + locale: project.locale, |
| 159 | + name: project.name, |
| 160 | + user_id: project.user_id, |
| 161 | + components: [], |
| 162 | + image_list: [] |
| 163 | + }.to_json |
| 164 | + end |
| 165 | + |
118 | 166 | it 'returns forbidden response' do
|
119 | 167 | get("/api/projects/#{project.identifier}", headers:)
|
120 | 168 |
|
|
0 commit comments