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
Added additional tests for storage files query
Andreas Pfohl96c5f2cd0fd5
diff --git a/app/services/service_result.rb b/app/services/service_result.rbindex bf69ff54a9b..902ee59387a 100644--- a/app/services/service_result.rb+++ b/app/services/service_result.rb@@ -173,7 +173,7 @@ class ServiceResultif success?on_success.call(result)else- on_failure.call+ on_failure.call(result)endenddiff --git a/modules/storages/lib/api/v3/storage_files/storage_files_api.rb b/modules/storages/lib/api/v3/storage_files/storage_files_api.rbindex c7a09b209d4..006ef200647 100644--- a/modules/storages/lib/api/v3/storage_files/storage_files_api.rb+++ b/modules/storages/lib/api/v3/storage_files/storage_files_api.rb@@ -43,18 +43,24 @@ module API::V3::StorageFilesresources :files doget do- files = ::API::V3::Utilities::StorageRequests- .new(storage: @storage)- .files_query(user: current_user)- .call- .on_failure { |r| handle_files_error(r) }- .result+ ::API::V3::Utilities::StorageRequests+ .new(storage: @storage)+ .files_query(user: current_user)+ .match(+ on_success: ->(query) {+ files = query+ .call+ .on_failure { |r| handle_files_error(r) }+ .result- ::API::V3::StorageFiles::StorageFileCollectionRepresenter.new(- files,- self_link: api_v3_paths.storage_files(@storage.id),- current_user:- )+ ::API::V3::StorageFiles::StorageFileCollectionRepresenter.new(+ files,+ self_link: api_v3_paths.storage_files(@storage.id),+ current_user:+ )+ },+ on_failure: ->(error) { handle_files_error(error) }+ )endendenddiff --git a/modules/storages/lib/api/v3/utilities/storage_interaction/storage_queries.rb b/modules/storages/lib/api/v3/utilities/storage_interaction/storage_queries.rbindex d72f693124f..17a68aabb02 100644--- a/modules/storages/lib/api/v3/utilities/storage_interaction/storage_queries.rb+++ b/modules/storages/lib/api/v3/utilities/storage_interaction/storage_queries.rb@@ -13,14 +13,17 @@ module API::V3::Utilities::StorageInteractionconnection_manager = ::OAuthClients::ConnectionManager.new(user: @user, oauth_client: @oauth_client)connection_manager.get_access_token.match(on_success: ->(token) do- ::API::V3::Utilities::StorageInteraction::NextcloudStorageQuery.new(- base_uri: @uri,- origin_user_id: token.send(:origin_user_id),- token: token.send(:access_token),- with_refreshed_token: connection_manager.method(:with_refreshed_token).to_proc+ ServiceResult.success(+ result:+ ::API::V3::Utilities::StorageInteraction::NextcloudStorageQuery.new(+ base_uri: @uri,+ origin_user_id: token.send(:origin_user_id),+ token: token.send(:access_token),+ with_refreshed_token: connection_manager.method(:with_refreshed_token).to_proc+ ))end,- on_failure: -> do+ on_failure: ->(_) doServiceResult.failure(result: :not_authorized)end)diff --git a/modules/storages/lib/api/v3/utilities/storage_requests.rb b/modules/storages/lib/api/v3/utilities/storage_requests.rbindex 36b25213c64..d2889a92f8f 100644--- a/modules/storages/lib/api/v3/utilities/storage_requests.rb+++ b/modules/storages/lib/api/v3/utilities/storage_requests.rb@@ -64,7 +64,6 @@ class API::V3::Utilities::StorageRequestsoauth_client: @oauth_client).files_query- .method(:files)- .to_proc+ .map { |query| query.method(:files).to_proc }endenddiff --git a/modules/storages/spec/lib/api/v3/utilities/storage_requests_spec.rb b/modules/storages/spec/lib/api/v3/utilities/storage_requests_spec.rbindex 3badd03cda6..42b4b967a05 100644--- a/modules/storages/spec/lib/api/v3/utilities/storage_requests_spec.rb+++ b/modules/storages/spec/lib/api/v3/utilities/storage_requests_spec.rb@@ -89,8 +89,8 @@ describe API::V3::Utilities::StorageRequests, webmock: true dolet(:storage) dostorage = instance_double(::Storages::Storage)allow(storage).to receive(:oauth_client).and_return(instance_double(OAuthClient))- allow(storage).to receive(:host).and_return(url)allow(storage).to receive(:provider_type).and_return(::Storages::Storage::PROVIDER_TYPE_NEXTCLOUD)+ allow(storage).to receive(:host).and_return(url)storageend@@ -108,7 +108,7 @@ describe API::V3::Utilities::StorageRequests, webmock: true dotokenend- subject { described_class.new(storage:).files_query(user:) }+ subject { described_class.new(storage:) }before doallow(::OAuthClients::ConnectionManager).to receive(:new).and_return(connection_manager)@@ -117,10 +117,56 @@ describe API::V3::Utilities::StorageRequests, webmock: true doenddescribe 'files_query' do- it 'must return a list of files when called' do- result = subject.call- expect(result.success).to be_truthy- expect(result.result.size).to eq(2)+ describe 'with Nextcloud storage type selected' do+ it 'must return a list of files when called' do+ subject+ .files_query(user:)+ .match(+ on_success: ->(q) do+ result = q.call+ expect(result.success).to be_truthy+ expect(result.result.size).to eq(2)+ end,+ on_failure: ->(_) do+ raise "Files query could not be created."+ end+ )+ end++ # test if results are correct+ end++ describe 'with not supported storage type selected' do+ before do+ allow(storage).to receive(:provider_type).and_return('not_supported_storage_type'.freeze)+ end++ it 'must raise ArgumentError' do+ expect { subject.files_query(user:) }.to raise_error(ArgumentError)+ endend++ describe 'with missing OAuth token' do+ before do+ allow(connection_manager).to receive(:get_access_token).and_return(ServiceResult.failure)+ end++ it 'must return ":not_authorized" ServiceResult if OAuth token is missing' do+ expect(subject.files_query(user:)).to be_failure+ end+ end++ #+ # it 'must return ":not_authorized" ServiceResult if outbound request returns "401 Not Authorized"' do+ #+ # end+ #+ # it 'must return ":not_found" ServiceResult if outbound request cannot find ressource' do+ #+ # end+ #+ # it 'must return ":error" ServiceResult if outbound request is not successful' do+ #+ # endendend