|
168 | 168 | expect(response).to have_http_status(:not_found) |
169 | 169 | end |
170 | 170 |
|
| 171 | + context 'when the original project belongs to another user' do |
| 172 | + let!(:original_project) { create(:project, user_id: create(:user).id) } |
| 173 | + |
| 174 | + it 'returns forbidden without creating a remix' do |
| 175 | + allow(Project::CreateRemix).to receive(:call).and_call_original |
| 176 | + |
| 177 | + expect do |
| 178 | + post("/api/projects/#{original_project.identifier}/remix", params: { project: project_params }, headers:) |
| 179 | + end.not_to change(Project, :count) |
| 180 | + |
| 181 | + expect(response).to have_http_status(:forbidden) |
| 182 | + expect(Project::CreateRemix).not_to have_received(:call) |
| 183 | + end |
| 184 | + end |
| 185 | + |
| 186 | + context 'when a student cannot view the teacher-only original project' do |
| 187 | + let(:student) { create(:student, school:) } |
| 188 | + let(:teacher) { create(:teacher, school:) } |
| 189 | + let(:school_class) { create(:school_class, school:, teacher_ids: [teacher.id]) } |
| 190 | + let(:lesson) { create(:lesson, school:, school_class:, user_id: teacher.id, visibility: 'teachers') } |
| 191 | + let!(:original_project) do |
| 192 | + lesson.project.tap do |project| |
| 193 | + project.update!(school:, user_id: teacher.id, instructions: 'Teacher-only instructions') |
| 194 | + end |
| 195 | + end |
| 196 | + |
| 197 | + before do |
| 198 | + create(:class_student, school_class:, student_id: student.id) |
| 199 | + authenticated_in_hydra_as(student) |
| 200 | + end |
| 201 | + |
| 202 | + it 'returns forbidden without creating a remix' do |
| 203 | + allow(Project::CreateRemix).to receive(:call).and_call_original |
| 204 | + |
| 205 | + expect do |
| 206 | + post("/api/projects/#{original_project.identifier}/remix", params: { project: project_params }, headers:) |
| 207 | + end.not_to change(Project, :count) |
| 208 | + |
| 209 | + expect(response).to have_http_status(:forbidden) |
| 210 | + expect(Project::CreateRemix).not_to have_received(:call) |
| 211 | + end |
| 212 | + end |
| 213 | + |
171 | 214 | context 'when project cannot be saved' do |
172 | 215 | before do |
173 | 216 | authenticated_in_hydra_as(owner) |
|
0 commit comments