Skip to content

Commit 894f684

Browse files
committed
Make destroying public projects specs more realistic
The immediate use case for `Api::PublicProjectsController#destroy` is for experience-cs admin users to destroy a public project. Since experience-cs only deals with Scratch projects, it makes sense to use projects of this type in the specs. However, since we're using `ProjectLoader` to find the project and the default scope is still in place to hide Scratch projects, we need to make use of the `ProjectScoping` concern to use the `project_type` param to set `Current.project_scope` to include Scratch projects.
1 parent cd16453 commit 894f684

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

spec/features/public_project/destroying_a_public_project_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,39 @@
44

55
RSpec.describe 'Destroying a public project', type: :request do
66
let(:destroyer) { build(:experience_cs_admin_user) }
7-
let(:project) { create(:project, locale: 'en') }
7+
let(:project) { create(:project, locale: 'en', project_type: Project::Types::SCRATCH) }
88
let(:headers) { { Authorization: UserProfileMock::TOKEN } }
99

1010
before do
1111
authenticated_in_hydra_as(destroyer)
1212
end
1313

1414
it 'responds 200 OK' do
15-
delete("/api/public_projects/#{project.identifier}", headers:)
15+
delete("/api/public_projects/#{project.identifier}?project_type=scratch", headers:)
1616
expect(response).to have_http_status(:success)
1717
end
1818

1919
it 'deletes the project' do
20-
delete("/api/public_projects/#{project.identifier}", headers:)
20+
delete("/api/public_projects/#{project.identifier}?project_type=scratch", headers:)
2121
expect(Project).not_to exist(identifier: project.identifier)
2222
end
2323

2424
it 'responds 401 Unauthorized when no token is given' do
25-
delete("/api/public_projects/#{project.identifier}")
25+
delete("/api/public_projects/#{project.identifier}?project_type=scratch")
2626
expect(response).to have_http_status(:unauthorized)
2727
end
2828

2929
context 'when destroyer is not an experience-cs admin' do
3030
let(:destroyer) { build(:user) }
3131

3232
it 'responds 403 Forbidden' do
33-
delete("/api/public_projects/#{project.identifier}", headers:)
33+
delete("/api/public_projects/#{project.identifier}?project_type=scratch", headers:)
3434
expect(response).to have_http_status(:forbidden)
3535
end
3636
end
3737

3838
it 'responds 404 Not Found when project is not found' do
39-
delete('/api/public_projects/another-identifier', headers:)
39+
delete('/api/public_projects/another-identifier?project_type=scratch', headers:)
4040
expect(response).to have_http_status(:not_found)
4141
end
4242
end

spec/requests/public_projects/destroy_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
RSpec.describe 'Destroy public project requests' do
66
let(:locale) { 'fr' }
77
let(:project_loader) { instance_double(ProjectLoader) }
8-
let(:project) { create(:project, locale: 'en') }
8+
let(:project) { create(:project, locale: 'en', project_type: Project::Types::SCRATCH) }
99
let(:destroyer) { build(:experience_cs_admin_user) }
1010

1111
context 'when auth is correct' do
@@ -24,19 +24,19 @@
2424
end
2525

2626
it 'builds ProjectLoader with identifier & locale' do
27-
delete("/api/public_projects/#{project.identifier}?locale=#{locale}", headers:)
27+
delete("/api/public_projects/#{project.identifier}?project_type=scratch&locale=#{locale}", headers:)
2828

2929
expect(ProjectLoader).to have_received(:new).with(project.identifier, [locale])
3030
end
3131

3232
it 'uses ProjectLoader#load to find the project based on identifier & locale' do
33-
delete("/api/public_projects/#{project.identifier}?locale=#{locale}", headers:)
33+
delete("/api/public_projects/#{project.identifier}?project_type=scratch&locale=#{locale}", headers:)
3434

3535
expect(project_loader).to have_received(:load)
3636
end
3737

3838
it 'returns success' do
39-
delete("/api/public_projects/#{project.identifier}", headers:)
39+
delete("/api/public_projects/#{project.identifier}?project_type=scratch", headers:)
4040

4141
expect(response).to have_http_status(:success)
4242
end
@@ -50,7 +50,7 @@
5050
end
5151

5252
it 'returns error' do
53-
delete("/api/public_projects/#{project.identifier}", headers:)
53+
delete("/api/public_projects/#{project.identifier}?project_type=scratch", headers:)
5454

5555
expect(response).to have_http_status(:unprocessable_entity)
5656
end
@@ -59,7 +59,7 @@
5959

6060
context 'when no token is given' do
6161
it 'returns unauthorized' do
62-
delete("/api/public_projects/#{project.identifier}")
62+
delete("/api/public_projects/#{project.identifier}?project_type=scratch")
6363

6464
expect(response).to have_http_status(:unauthorized)
6565
end

0 commit comments

Comments
 (0)