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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[#50543] added request tests
Eric Schubert27fa563f9e93
diff --git a/modules/storages/lib/api/v3/storages/storage_open_api.rb b/modules/storages/lib/api/v3/storages/storage_open_api.rbindex be0d7d2c34c..4159cc34af0 100644--- a/modules/storages/lib/api/v3/storages/storage_open_api.rb+++ b/modules/storages/lib/api/v3/storages/storage_open_api.rb@@ -35,7 +35,7 @@ class API::V3::Storages::StorageOpenAPI < API::OpenProjectAPIget doStorages::Peripherals::Registry.resolve("queries.#{@storage.short_provider_type}.open_storage")- .call(storage: @storage, user: current_user, file_id: nil)+ .call(storage: @storage, user: current_user).match(on_success: ->(url) doredirect url, body: "The requested resource can be viewed at #{url}"diff --git a/modules/storages/spec/requests/api/v3/project_storages/project_storages_spec.rb b/modules/storages/spec/requests/api/v3/project_storages/project_storages_spec.rbindex a72f3cb680e..5f05963f82c 100644--- a/modules/storages/spec/requests/api/v3/project_storages/project_storages_spec.rb+++ b/modules/storages/spec/requests/api/v3/project_storages/project_storages_spec.rb@@ -237,4 +237,61 @@ RSpec.describe 'API v3 project storages resource', :webmock, content_type: :jsonit_behaves_like 'not found'endend++ describe 'GET /api/v3/project_storages/:id/open' do+ let(:path) { api_v3_paths.project_storage_open(project_storage11.id) }+ let(:location) { 'https://deathstar.storage.org/files' }+ let(:location_project_folder) { 'https://deathstar.storage.org/files/data/project_destroy_alderan' }+ let(:current_user) do+ create(:user, member_with_permissions: { project1 => view_permissions })+ end++ before do+ Storages::Peripherals::Registry.stub(+ 'queries.nextcloud.open_storage',+ ->(_) { ServiceResult.success(result: location) }+ )+ Storages::Peripherals::Registry.stub(+ 'queries.nextcloud.open_file_link',+ ->(_) { ServiceResult.success(result: location_project_folder) }+ )+ end++ context 'as admin' do+ let(:current_user) { create(:admin) }++ it_behaves_like 'redirect response'+ end++ context 'if user belongs to a project related to project storage' do+ it_behaves_like 'redirect response'++ context 'if project storage has a configured project folder' do+ let!(:project_storage12) do+ create(:project_storage,+ project: project1,+ storage: storage2,+ project_folder_id: '1337',+ project_folder_mode: 'manual')+ end+ let(:path) { api_v3_paths.project_storage_open(project_storage12.id) }++ it_behaves_like 'redirect response' do+ let(:location) { location_project_folder }+ end+ end++ context 'if user is missing permission view_file_links' do+ let(:view_permissions) { [] }++ it_behaves_like 'not found'+ end+ end++ context 'if user is not member of the project' do+ let(:path) { api_v3_paths.project_storage_open(project_storage21.id) }++ it_behaves_like 'not found'+ end+ endenddiff --git a/modules/storages/spec/requests/api/v3/storages/storages_api_spec.rb b/modules/storages/spec/requests/api/v3/storages/storages_api_spec.rbindex 72713642ae0..649840dcfb4 100644--- a/modules/storages/spec/requests/api/v3/storages/storages_api_spec.rb+++ b/modules/storages/spec/requests/api/v3/storages/storages_api_spec.rb@@ -407,6 +407,40 @@ RSpec.describe 'API v3 storages resource', :webmock, content_type: :json doendend+ describe 'GET /api/v3/storages/:storage_id/open' do+ let(:path) { api_v3_paths.storage_open(storage.id) }+ let(:location) { 'https://deathstar.storage.org/files' }++ before do+ Storages::Peripherals::Registry.stub(+ 'queries.nextcloud.open_storage',+ ->(_) { ServiceResult.success(result: location) }+ )+ end++ context 'as admin' do+ let(:current_user) { create(:admin) }++ it_behaves_like 'redirect response'+ end++ context 'if user belongs to a project using the given storage' do+ it_behaves_like 'redirect response'++ context 'if user is missing permission view_file_links' do+ let(:permissions) { [] }++ it_behaves_like 'not found'+ end++ context 'if no storage with that id exists' do+ let(:path) { api_v3_paths.storage_open('1337') }++ it_behaves_like 'not found'+ end+ end+ end+describe 'POST /api/v3/storages/:storage_id/oauth_client_credentials' dolet(:path) { api_v3_paths.storage_oauth_client_credentials(storage.id) }let(:client_id) { 'myl1ttlecl13ntidii' }diff --git a/spec/requests/api/v3/support/response_examples.rb b/spec/requests/api/v3/support/response_examples.rbindex b318d5bad36..807215133e7 100644--- a/spec/requests/api/v3/support/response_examples.rb+++ b/spec/requests/api/v3/support/response_examples.rb@@ -46,6 +46,18 @@ RSpec.shared_examples_for 'successful no content response' do |code = 204|endend+RSpec.shared_examples_for 'redirect response' do |code = 303|+ let(:location) { '' }++ it "has the status code #{code}" do+ expect(last_response.status).to eq(code)+ end++ it 'redirects to expected location' do+ expect(last_response.headers['Location']).to eq(location)+ end+end+RSpec.shared_examples_for 'error response' do |code, id, provided_message = nil|let(:expected_message) doprovided_message || message@@ -113,7 +125,7 @@ RSpec.shared_examples_for 'parse error' do |details|it 'shows the given details' doif detailsexpect(last_response.body).to be_json_eql(details.to_json)- .at_path('_embedded/details/parseError')+ .at_path('_embedded/details/parseError')endendend