Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Test that :add_work_package_attachments permission allows to prepare attachments

Christophe Bliarddb7a62341a4d
diff --git a/spec/requests/api/v3/attachments_spec.rb b/spec/requests/api/v3/attachments_spec.rb
index fa54026bd5a..9c1fc008b06 100644
--- a/spec/requests/api/v3/attachments_spec.rb
+++ b/spec/requests/api/v3/attachments_spec.rb
@@ -40,9 +40,7 @@ RSpec.describe API::V3::Attachments::AttachmentsAPI do
let(:role) { create(:role, permissions:) }
let(:permissions) { [:add_work_packages] }
- context 'with missing permissions', :with_direct_uploads do
- let(:permissions) { [] }
-
+ describe 'permissions', :with_direct_uploads do
let(:request_path) { api_v3_paths.prepare_new_attachment_upload }
let(:request_parts) { { metadata: metadata.to_json, file: } }
let(:metadata) { { fileName: 'cat.png', fileSize: file.size, contentType: 'image/png' } }
@@ -53,8 +51,28 @@ RSpec.describe API::V3::Attachments::AttachmentsAPI do
post request_path, request_parts
end
- it 'forbids to prepare attachments' do
- expect(last_response.status).to eq 403
+ context 'with missing permissions' do
+ let(:permissions) { [] }
+
+ it 'forbids to prepare attachments' do
+ expect(last_response.status).to eq 403
+ end
+ end
+
+ context 'with :edit_work_packages permission' do
+ let(:permissions) { [:edit_work_packages] }
+
+ it 'can prepare attachments' do
+ expect(last_response.status).to eq 201
+ end
+ end
+
+ context 'with :add_work_package_attachments permission' do
+ let(:permissions) { [:add_work_package_attachments] }
+
+ it 'can prepare attachments' do
+ expect(last_response.status).to eq 201
+ end
end
end