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
Refactor code.
Pavel Balashovbdd91acd9f17
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/upload_link_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/upload_link_query.rbindex 6d041bdefcd..6d823e8a5a8 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/upload_link_query.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/upload_link_query.rb@@ -43,22 +43,22 @@ module Storages::Peripherals::StorageInteraction::Nextcloudif data.nil? || data['parent'].nil?Util.error(:error, 'Data is invalid', data)else- outbound_response(method: :post,- relative_path: URI_TOKEN_REQUEST,- payload: { folder_id: data['parent'] },- token:)- .map { |result| build_upload_link result }+ outbound_response(+ method: :post,+ relative_path: URI_TOKEN_REQUEST,+ payload: { folder_id: data['parent'] },+ token:+ ).map do |response|+ Storages::UploadLink.new(+ URI.parse(Util.join_uri_path(@base_uri, URI_UPLOAD_BASE_PATH, response.token))+ )+ endendendendprivate- def build_upload_link(response)- destination = URI.parse(Util.join_uri_path(@base_uri, URI_UPLOAD_BASE_PATH, response.token))- ServiceResult.success(result: Storages::UploadLink.new(destination))- end-# rubocop:disable Metrics/AbcSizedef outbound_response(method:, relative_path:, payload:, token:)response = begindiff --git a/modules/storages/app/common/storages/peripherals/storage_requests.rb b/modules/storages/app/common/storages/peripherals/storage_requests.rbindex bbc00067b1b..4228a33856d 100644--- a/modules/storages/app/common/storages/peripherals/storage_requests.rb+++ b/modules/storages/app/common/storages/peripherals/storage_requests.rb@@ -67,7 +67,7 @@ module Storages::Peripheralsprivatedef result(request_class)- ServiceResult.success(result: request_class.new(@storage).method(:call).to_proc)+ request_class.new(@storage).method(:call).to_procenddef clazz(storage, request)diff --git a/modules/storages/app/workers/manage_nextcloud_integration_job.rb b/modules/storages/app/workers/manage_nextcloud_integration_job.rbindex b57f122eefe..4ce8efd7b50 100644--- a/modules/storages/app/workers/manage_nextcloud_integration_job.rb+++ b/modules/storages/app/workers/manage_nextcloud_integration_job.rb@@ -51,31 +51,25 @@ class ManageNextcloudIntegrationJob < Cron::CronJobrequests = Storages::Peripherals::StorageRequests.new(storage:)- group_users = requests.group_users_query.result.call(group:).match(- on_success: ->(r) { r },- on_failure: ->(r) { raise "group_users_query failed: #{r}, group: #{group}" }- )+ group_users = requests.group_users_query.call(group:).on_failure do |r|+ raise "group_users_query failed: #{r.inspect}, group: #{group}"+ end.result- requests.set_permissions_command.result.call(+ requests.set_permissions_command.call(path: groupfolder,permissions: {users: { "#{username}": 31 },groups: { "#{group}": 1 }}- ).match(- on_success: ->(_) {},- on_failure: ->(r) { raise "set_permissions_command failed: #{r}, path: #{path}, permissions: #{permissions}" }- )+ ).on_failure do |r|+ raise "set_permissions_command failed: #{r}, path: #{path}, permissions: #{permissions}"+ endfolders_props = requests- .propfind_query- .result- .call(depth: '1', path: groupfolder)- .match(- on_success: ->(r) { r },- on_failure: ->(r) { raise "propfind_query failed: #{r}, depth: 1, path: #{groupfolder}" }- )-+ .propfind_query+ .call(depth: '1', path: groupfolder)+ .on_failure { |r| raise "propfind_query failed: #{r}, depth: 1, path: #{groupfolder}" }+ .resultfile_ids = folders_props.map { |_path, props| props['fileid'] }storage.projects_storages.where(project_folder_mode: 'automatic').each do |project_storage|@@ -86,22 +80,22 @@ class ManageNextcloudIntegrationJob < Cron::CronJobif file_ids.include?(project_folder_id)source = folders_props.find { |_k, v| v['fileid'] == project_folder_id }.firstif source != target- requests.rename_file_command.result.call(source:, target:).match(- on_success: ->(r) { r },- on_failure: ->(r) { raise "rename_file_command failed: #{r}, source: #{source} target: #{target}" }- )+ requests.rename_file_command.call(source:, target:).on_failure do |r|+ raise "rename_file_command failed: #{r}, source: #{source} target: #{target}"+ endendelse- requests.create_folder_command.result.call(folder_path: target)+ requests.create_folder_command.call(folder_path: target).match(on_success: ->(_) {propfind_response2 = requests.propfind_query- .result.call(depth: '0', path: target).match(on_success: ->(r) { r },- on_failure: ->(r) { raise "propfind_query failed: #{r}, depth: 0, path: #{target}" }+ on_failure: ->(r) {+ raise "propfind_query failed: #{r}, depth: 0, path: #{target}"+ })project_storage.update(project_folder_id: propfind_response2[target]['fileid'])},@@ -124,26 +118,21 @@ class ManageNextcloudIntegrationJob < Cron::CronJobpermissions[:users][nextcloud_username.to_sym] = calculate_permissions(user: token.user, project:)if group_users.exclude?(nextcloud_username) && nextcloud_usernames_used_in_openprojects.exclude?(nextcloud_username)- requests.add_user_to_group_command.result.call(user: nextcloud_username).match(- on_success: ->(_) {},- on_failure: ->(r) { raise "add_user_to_group_command failed: #{r}, user: #{netcloud_username}" }- )+ requests.add_user_to_group_command.call(user: nextcloud_username).on_failure do |r|+ raise "add_user_to_group_command failed: #{r}, user: #{netcloud_username}"+ endendnextcloud_usernames_used_in_openprojects << nextcloud_usernameend- requests.set_permissions_command.result.call(path: target, permissions:).match(- on_success: ->(_) {},- on_failure: ->(r) { raise "set_permissions_command failed: #{r}, path: #{target}, permissions: #{permissions}" }- )+ requests.set_permissions_command.call(path: target, permissions:).on_failure do |r|+ raise "set_permissions_command failed: #{r}, path: #{target}, permissions: #{permissions}"+ endend(group_users - nextcloud_usernames_used_in_openprojects.to_a).each do |user|- requests.remove_user_from_group_command.result.call(user:)- .match(- on_success: ->(_) {},- on_failure: ->(r) { raise "remove_user_from_group_command failed: #{r}, user: #{user}" }- )+ requests.remove_user_from_group_command.call(user:)+ .on_failure { |r| raise "remove_user_from_group_command failed: #{r}, user: #{user}" }endlost_folder_paths = folders_props@@ -152,20 +141,19 @@ class ManageNextcloudIntegrationJob < Cron::CronJobarray.push(path) if project_folder_ids_used_in_openproject.exclude?(attrs['fileid'])endlost_folder_paths.each do |path|- requests.set_permissions_command.result.call(+ requests.set_permissions_command.call(path:,permissions: {users: { "#{username}": 31 },groups: { "#{group}": 0 }}- ).match(- on_success: ->(_) {},- on_failure: ->(r) { raise "set_permissions_command failed: #{r}, path: #{path}, permissions: #{permissions}" }- )+ ).on_failure { |r| raise "set_permissions_command failed: #{r}, path: #{path}, permissions: #{permissions}" }endendend+ private+def calculate_permissions(user:, project:){read_files: user.allowed_to?(:read_files, project),diff --git a/modules/storages/lib/api/v3/file_links/file_links_download_api.rb b/modules/storages/lib/api/v3/file_links/file_links_download_api.rbindex bbef2561d1c..479e1e96a8a 100644--- a/modules/storages/lib/api/v3/file_links/file_links_download_api.rb+++ b/modules/storages/lib/api/v3/file_links/file_links_download_api.rb@@ -35,18 +35,12 @@ class API::V3::FileLinks::FileLinksDownloadAPI < API::OpenProjectAPIStorages::Peripherals::StorageRequests.new(storage: @file_link.storage).download_link_query+ .call(user: User.current, file_link: @file_link).match(- on_success: ->(download_link_query) {- download_link_query- .call(user: User.current, file_link: @file_link)- .match(- on_success: ->(url) do- redirect(url, body: "The requested resource can be downloaded from #{url}")- status(303)- end,- on_failure: ->(error) { raise_error(error) }- )- },+ on_success: ->(url) do+ redirect(url, body: "The requested resource can be downloaded from #{url}")+ status(303)+ end,on_failure: ->(error) { raise_error(error) })enddiff --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 85bd9eaacd2..15ad3567a69 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@@ -33,10 +33,10 @@ module API::V3::StorageFilesresources :files doget do- (Storages::Peripherals::StorageRequests.new(storage: @storage).files_query >> ->(query) {- query.call(user: current_user,- folder: params[:parent])- })+ Storages::Peripherals::StorageRequests+ .new(storage: @storage)+ .files_query+ .call(user: current_user, folder: params[:parent]).match(on_success: ->(files) { API::V3::StorageFiles::StorageFilesRepresenter.new(files, @storage, current_user:) },on_failure: ->(error) { raise_error(error) }@@ -45,10 +45,10 @@ module API::V3::StorageFilesroute_param :file_id, type: String, desc: 'Storage file id' doget do- (Storages::Peripherals::StorageRequests.new(storage: @storage).file_query >> ->(query) {- query.call(user: current_user,- file_id: params[:file_id])- })+ Storages::Peripherals::StorageRequests+ .new(storage: @storage)+ .file_query+ .call(user: current_user, file_id: params[:file_id]).match(on_success: ->(storage_file) {API::V3::StorageFiles::StorageFileRepresenter.new(storage_file, @storage, current_user:)@@ -70,10 +70,10 @@ module API::V3::StorageFilesendvalidate.call(request_body) >> ->(data) do- (Storages::Peripherals::StorageRequests.new(storage: @storage).upload_link_query >> ->(query) {- query.call(user: current_user,- data:)- })+ Storages::Peripherals::StorageRequests+ .new(storage: @storage)+ .upload_link_query+ .call(user: current_user, data:).match(on_success: ->(link) { API::V3::StorageFiles::StorageUploadLinkRepresenter.new(link, current_user:) },on_failure: ->(error) { raise_error(error) }diff --git a/modules/storages/spec/common/peripherals/storage_requests_spec.rb b/modules/storages/spec/common/peripherals/storage_requests_spec.rbindex 72a93d1cc25..b6d31e290ec 100644--- a/modules/storages/spec/common/peripherals/storage_requests_spec.rb+++ b/modules/storages/spec/common/peripherals/storage_requests_spec.rb@@ -84,7 +84,6 @@ describe Storages::Peripherals::StorageRequests, webmock: true doit 'must return a download link URL' doresult = subject.download_link_query- .result.call(user:, file_link:)expect(result).to be_successexpect(result.result).to be_eql(uri)@@ -96,7 +95,6 @@ describe Storages::Peripherals::StorageRequests, webmock: true doit 'must return a download link URL' doresult = subject.download_link_query- .result.call(user:, file_link:)expect(result).to be_successexpect(result.result).to be_eql(uri)@@ -122,7 +120,6 @@ describe Storages::Peripherals::StorageRequests, webmock: true doit 'must return ":not_authorized" ServiceResult' doresult = subject.download_link_query- .result.call(user:, file_link:)expect(result).to be_failureexpect(result.errors.code).to be(:not_authorized)@@ -137,7 +134,6 @@ describe Storages::Peripherals::StorageRequests, webmock: true doit 'must return :not_authorized ServiceResult' doresult = subject.download_link_query- .result.call(user:, file_link:)expect(result).to be_failureexpect(result.errors.code).to be(:not_authorized)@@ -153,7 +149,6 @@ describe Storages::Peripherals::StorageRequests, webmock: true doit "must return :#{symbol} ServiceResult" doresult = subject.download_link_query- .result.call(user:, file_link:)expect(result).to be_failureexpect(result.errors.code).to be(symbol)@@ -189,7 +184,6 @@ describe Storages::Peripherals::StorageRequests, webmock: true doit 'returns a list files directories with names and permissions' doresult = subject.files_query- .result.call(folder: nil, user:)expect(result).to be_successexpect(result.result.files.size).to eq(4)@@ -225,7 +219,6 @@ describe Storages::Peripherals::StorageRequests, webmock: true doit doresult = subject.files_query- .result.call(folder: parent, user:)expect(result.result.files[0].location).to eq('/Folder1')@@ -239,7 +232,6 @@ describe Storages::Peripherals::StorageRequests, webmock: true doit doresult = subject.files_query- .result.call(folder: parent, user:)expect(result.result.files[2].location).to eq('/Photos/Birds/README.md')expect(result.result.ancestors[0].location).to eq('/')@@ -255,7 +247,6 @@ describe Storages::Peripherals::StorageRequests, webmock: true doit doresult = subject.files_query- .result.call(folder: nil, user:)expect(result.result.files[2].location).to eq('/README.md')assert_requested(:propfind, request_url)@@ -269,7 +260,6 @@ describe Storages::Peripherals::StorageRequests, webmock: true doit doresult = subject.files_query- .result.call(folder: parent, user:)expect(result.result.files[2].location).to eq('/Photos/Birds/README.md')@@ -296,7 +286,6 @@ describe Storages::Peripherals::StorageRequests, webmock: true doit 'must return ":not_authorized" ServiceResult' doresult = subject.files_query- .result.call(folder: parent, user:)expect(result).to be_failureexpect(result.errors.code).to be(:not_authorized)@@ -313,7 +302,6 @@ describe Storages::Peripherals::StorageRequests, webmock: true doit "must return :#{symbol} ServiceResult" doresult = subject.files_query- .result.call(folder: parent, user:)expect(result).to be_failureexpect(result.errors.code).to be(symbol)@@ -375,7 +363,6 @@ describe Storages::Peripherals::StorageRequests, webmock: true doit 'must return a list of files when called' doresult = subject.file_query- .result.call(user:, file_id:)expect(result).to be_successstorage_file = result.result@@ -409,7 +396,6 @@ describe Storages::Peripherals::StorageRequests, webmock: true doit 'must return an upload link URL' dolink = subject.upload_link_query- .result.call(user:, data: query_payload).resultexpect(link.destination.path).to be_eql("/index.php/apps/integration_openproject/direct-upload/#{upload_token}")@@ -439,7 +425,6 @@ describe Storages::Peripherals::StorageRequests, webmock: true doit 'must return ":not_authorized" ServiceResult' doresult = subject.upload_link_query- .result.call(user:, data: query_payload)expect(result).to be_failureexpect(result.errors.code).to be(:not_authorized)@@ -455,7 +440,6 @@ describe Storages::Peripherals::StorageRequests, webmock: true doit "must return :#{symbol} ServiceResult" doresult = subject.upload_link_query- .result.call(user:, data: query_payload)expect(result).to be_failureexpect(result.errors.code).to be(symbol)@@ -511,7 +495,6 @@ describe Storages::Peripherals::StorageRequests, webmock: true doit 'must return an upload link URL' dolink = subject.upload_link_query- .result.call(user:, data: query_payload).resultexpect(link.destination.path).to be_eql("/public.php/webdav/#{query_payload.fileName}")@@ -543,7 +526,6 @@ describe Storages::Peripherals::StorageRequests, webmock: true doit 'must return ":not_authorized" ServiceResult' doresult = subject.upload_link_query- .result.call(user:, data: query_payload)expect(result).to be_failureexpect(result.errors.code).to be(:not_authorized)@@ -568,7 +550,6 @@ describe Storages::Peripherals::StorageRequests, webmock: true doit 'must return :not_authorized ServiceResult' doresult = subject.upload_link_query- .result.call(user:, data: query_payload)expect(result).to be_failureexpect(result.errors.code).to be(:not_authorized)@@ -585,7 +566,6 @@ describe Storages::Peripherals::StorageRequests, webmock: true doit 'must return :not_authorized ServiceResult' doresult = subject.upload_link_query- .result.call(user:, data: query_payload)expect(result).to be_failureexpect(result.errors.code).to be(:not_authorized)@@ -601,7 +581,6 @@ describe Storages::Peripherals::StorageRequests, webmock: true doit "must return :#{symbol} ServiceResult" doresult = subject.upload_link_query- .result.call(user:, data: query_payload)expect(result).to be_failureexpect(result.errors.code).to be(symbol)@@ -664,7 +643,6 @@ describe Storages::Peripherals::StorageRequests, webmock: true doit 'responds with a strings array with group users' doresult = subject.group_users_query- .result.callexpect(result).to be_successexpect(result.result).to eq(["admin", "OpenProject", "reader", "TestUser", "TestUser34"])@@ -709,7 +687,6 @@ describe Storages::Peripherals::StorageRequests, webmock: true doit 'adds user to the group' doresult = subject.add_user_to_group_command- .result.call(user: origin_user_id)expect(result).to be_successexpect(result.message).to eq("User has been added successfully")@@ -754,7 +731,6 @@ describe Storages::Peripherals::StorageRequests, webmock: true doit 'removes user from the group' doresult = subject.remove_user_from_group_command- .result.call(user: origin_user_id)expect(result).to be_successexpect(result.message).to eq("User has been removed from group")@@ -786,7 +762,6 @@ describe Storages::Peripherals::StorageRequests, webmock: true doit 'creates a folder and responds with a success' doresult = subject.create_folder_command- .result.call(folder_path:)expect(result).to be_successexpect(result.message).to eq("Folder was successfully created.")@@ -814,7 +789,6 @@ describe Storages::Peripherals::StorageRequests, webmock: true doit 'does not create a folder and responds with a success' doresult = subject.create_folder_command- .result.call(folder_path:)expect(result).to be_successexpect(result.message).to eq("Folder already exists.")@@ -842,7 +816,6 @@ describe Storages::Peripherals::StorageRequests, webmock: true doit 'does not create a folder and responds with a failure' doresult = subject.create_folder_command- .result.call(folder_path:)expect(result).to be_failureexpect(result.result).to eq(:conflict)@@ -949,7 +922,6 @@ describe Storages::Peripherals::StorageRequests, webmock: true doit 'returns success when permissions can be set' doresult = subject.set_permissions_command- .result.call(path:, permissions:)expect(result).to be_successend@@ -978,7 +950,6 @@ describe Storages::Peripherals::StorageRequests, webmock: true doit 'returns failure' doresult = subject.set_permissions_command- .result.call(path:, permissions:)expect(result).to be_failureend@@ -1007,7 +978,6 @@ describe Storages::Peripherals::StorageRequests, webmock: true doit 'returns failure' doresult = subject.set_permissions_command- .result.call(path:, permissions:)expect(result).to be_failureend@@ -1019,7 +989,6 @@ describe Storages::Peripherals::StorageRequests, webmock: true doexpect dosubject.set_permissions_command- .result.call(path: nil, permissions:)end.to raise_error(ArgumentError)end@@ -1028,7 +997,6 @@ describe Storages::Peripherals::StorageRequests, webmock: true doexpect dosubject.set_permissions_command- .result.call(path: '', permissions:)end.to raise_error(ArgumentError)end@@ -1137,7 +1105,6 @@ describe Storages::Peripherals::StorageRequests, webmock: true doit 'responds with a list of paths and attributes for each of them' doresult = subject.propfind_query- .result.call(depth: '1', path: 'OpenProject').resultexpect(result).to eq({ "OpenProject/" => { "fileid" => "349" },@@ -1165,7 +1132,6 @@ describe Storages::Peripherals::StorageRequests, webmock: true doit 'moves the file' doresult = subject.rename_file_command- .result.call(source: 'OpenProject/asd', target: 'OpenProject/qwe')expect(result).to be_successenddiff --git a/modules/storages/spec/requests/api/v3/file_links/file_links_spec.rb b/modules/storages/spec/requests/api/v3/file_links/file_links_spec.rbindex 928433eba06..96a59f5a726 100644--- a/modules/storages/spec/requests/api/v3/file_links/file_links_spec.rb+++ b/modules/storages/spec/requests/api/v3/file_links/file_links_spec.rb@@ -558,78 +558,19 @@ describe 'API v3 file links resource' dodescribe 'with successful response' dobefore do- storage_requests = instance_double(Storages::Peripherals::StorageRequests)- download_link_query = Proc.new do- ServiceResult.success(result: url)- end- allow(storage_requests).to receive(:download_link_query).and_return(ServiceResult.success(result: download_link_query))- allow(Storages::Peripherals::StorageRequests).to receive(:new).and_return(storage_requests)-- get path+ allow_any_instance_of(+ Storages::Peripherals::StorageInteraction::Nextcloud::DownloadLinkQuery+ ).to receive(:call).and_return(ServiceResult.success(result: url))endit 'responds successfully' do+ get path+expect(subject.status).to be(303)expect(subject.location).to be(url)endend- describe 'with download link query creation failed' do- let(:storage_requests) { instance_double(Storages::Peripherals::StorageRequests) }-- before do- allow(Storages::Peripherals::StorageRequests).to receive(:new).and_return(storage_requests)- end-- describe 'due to authorization failure' do- before do- allow(storage_requests).to receive(:download_link_query).and_return(- ServiceResult.failure(- result: :not_authorized,- errors: Storages::StorageError.new(code: :not_authorized)- )- )- get path- end-- it { expect(subject.status).to be(500) }- end-- describe 'due to internal error' do- before do- allow(storage_requests).to receive(:download_link_query).and_return(- ServiceResult.failure(- result: :error,- errors: Storages::StorageError.new(code: :error)- )- )- get path- end-- it { expect(subject.status).to be(500) }- end-- describe 'due to not found' do- before do- allow(storage_requests).to receive(:download_link_query).and_return(- ServiceResult.failure(- result: :not_found,- errors: Storages::StorageError.new(code: :not_found)- )- )- get path- end-- it 'fails with outbound request failure' do- expect(subject.status).to be(500)-- body = JSON.parse(subject.body)- expect(body['message']).to eq(I18n.t('api_v3.errors.code_500_outbound_request_failure', status_code: 404))- expect(body['errorIdentifier']).to eq('urn:openproject-org:api:v3:errors:OutboundRequest:NotFound')- end- end- end-describe 'with query failed' dobefore doallow_any_instance_of(diff --git a/modules/storages/spec/requests/api/v3/storages/storage_files_spec.rb b/modules/storages/spec/requests/api/v3/storages/storage_files_spec.rbindex 22915a05c1e..1585b0a3678 100644--- a/modules/storages/spec/requests/api/v3/storages/storage_files_spec.rb+++ b/modules/storages/spec/requests/api/v3/storages/storage_files_spec.rb@@ -76,105 +76,51 @@ describe 'API v3 storage files', content_type: :json, webmock: true do)end- describe 'with successful response' do+ context 'with successful response' dobefore dostorage_requests = instance_double(Storages::Peripherals::StorageRequests)files_query = Proc.new doServiceResult.success(result: response)end- allow(storage_requests).to receive(:files_query).and_return(ServiceResult.success(result: files_query))+ allow(storage_requests).to receive(:files_query).and_return(files_query)allow(Storages::Peripherals::StorageRequests).to receive(:new).and_return(storage_requests)endsubject { last_response.body }- it { is_expected.to be_json_eql(response.files[0].id.to_json).at_path('files/0/id') }- it { is_expected.to be_json_eql(response.files[0].name.to_json).at_path('files/0/name') }- it { is_expected.to be_json_eql(response.files[1].id.to_json).at_path('files/1/id') }- it { is_expected.to be_json_eql(response.files[1].name.to_json).at_path('files/1/name') }-- it { is_expected.to be_json_eql(response.files[0].permissions.to_json).at_path('files/0/permissions') }- it { is_expected.to be_json_eql(response.files[1].permissions.to_json).at_path('files/1/permissions') }-- it { is_expected.to be_json_eql(response.parent.id.to_json).at_path('parent/id') }- it { is_expected.to be_json_eql(response.parent.name.to_json).at_path('parent/name') }-- it { is_expected.to be_json_eql(response.ancestors.to_json).at_path('ancestors') }- end-- describe 'with files query creation failed' do- let(:storage_requests) { instance_double(Storages::Peripherals::StorageRequests) }-- before do- allow(Storages::Peripherals::StorageRequests).to receive(:new).and_return(storage_requests)- end-- describe 'due to authorization failure' do- before do- allow(storage_requests).to receive(:files_query).and_return(- ServiceResult.failure(- result: :not_authorized,- errors: Storages::StorageError.new(code: :not_authorized)- )- )- end-- it { expect(last_response.status).to be(500) }- end-- describe 'due to internal error' do- before do- allow(storage_requests).to receive(:files_query).and_return(- ServiceResult.failure(- result: :error,- errors: Storages::StorageError.new(code: :error)- )- )- end-- it { expect(last_response.status).to be(500) }- end-- describe 'due to not found' do- before do- allow(storage_requests).to receive(:files_query).and_return(- ServiceResult.failure(- result: :not_found,- errors: Storages::StorageError.new(code: :not_found)- )- )- end-- it 'fails with outbound request failure' do- expect(last_response.status).to be(500)-- body = JSON.parse(last_response.body)- expect(body['message']).to eq(I18n.t('api_v3.errors.code_500_outbound_request_failure', status_code: 404))- expect(body['errorIdentifier']).to eq('urn:openproject-org:api:v3:errors:OutboundRequest:NotFound')- end+ it 'responds with appropriate JSON' do+ expect(subject).to be_json_eql(response.files[0].id.to_json).at_path('files/0/id')+ expect(subject).to be_json_eql(response.files[0].name.to_json).at_path('files/0/name')+ expect(subject).to be_json_eql(response.files[1].id.to_json).at_path('files/1/id')+ expect(subject).to be_json_eql(response.files[1].name.to_json).at_path('files/1/name')+ expect(subject).to be_json_eql(response.files[0].permissions.to_json).at_path('files/0/permissions')+ expect(subject).to be_json_eql(response.files[1].permissions.to_json).at_path('files/1/permissions')+ expect(subject).to be_json_eql(response.parent.id.to_json).at_path('parent/id')+ expect(subject).to be_json_eql(response.parent.name.to_json).at_path('parent/name')+ expect(subject).to be_json_eql(response.ancestors.to_json).at_path('ancestors')endend- describe 'with query failed' do+ context 'with query failed' dobefore doallow_any_instance_of(Storages::Peripherals::StorageInteraction::Nextcloud::FilesQuery).to receive(:call).and_return(ServiceResult.failure(result: error, errors: Storages::StorageError.new(code: error)))end- describe 'due to authorization failure' do+ context 'due to authorization failure' dolet(:error) { :not_authorized }it { expect(last_response.status).to be(500) }end- describe 'due to internal error' do+ context 'due to internal error' dolet(:error) { :error }it { expect(last_response.status).to be(500) }end- describe 'due to not found' do+ context 'due to not found' dolet(:error) { :not_found }it 'fails with outbound request failure' do@@ -200,69 +146,45 @@ describe 'API v3 storage files', content_type: :json, webmock: true dodescribe 'with successful response' dobefore do- storage_requests = instance_double(Storages::Peripherals::StorageRequests)- uplaod_link_query = Proc.new { ServiceResult.success(result: upload_link) }- allow(storage_requests).to receive(:upload_link_query).and_return(ServiceResult.success(result: uplaod_link_query))- allow(Storages::Peripherals::StorageRequests).to receive(:new).and_return(storage_requests)+ allow_any_instance_of(+ Storages::Peripherals::StorageInteraction::Nextcloud::UploadLinkQuery+ ).to receive(:call).and_return(ServiceResult.success(result: upload_link))endsubject { last_response.body }- it { is_expected.to be_json_eql(Storages::UploadLink.name.split('::').last.to_json).at_path('_type') }-- it do+ it 'responds with appropriate JSON' do+ expect(subject).to be_json_eql(Storages::UploadLink.name.split('::').last.to_json).at_path('_type')expect(subject).to(be_json_eql("#{API::V3::URN_PREFIX}storages:upload_link:no_link_provided".to_json).at_path('_links/self/href'))+ expect(subject).to be_json_eql(upload_link.destination.to_json).at_path('_links/destination/href')+ expect(subject).to be_json_eql("post".to_json).at_path('_links/destination/method')+ expect(subject).to be_json_eql("Upload File".to_json).at_path('_links/destination/title')end-- it { is_expected.to be_json_eql(upload_link.destination.to_json).at_path('_links/destination/href') }- it { is_expected.to be_json_eql("post".to_json).at_path('_links/destination/method') }- it { is_expected.to be_json_eql("Upload File".to_json).at_path('_links/destination/title') }end- describe 'with files query creation failed' do- let(:storage_requests) { instance_double(Storages::Peripherals::StorageRequests) }-+ context 'with query failed' dobefore do- allow(Storages::Peripherals::StorageRequests).to receive(:new).and_return(storage_requests)+ allow_any_instance_of(+ Storages::Peripherals::StorageInteraction::Nextcloud::UploadLinkQuery+ ).to receive(:call).and_return(ServiceResult.failure(result: error, errors: Storages::StorageError.new(code: error)))enddescribe 'due to authorization failure' do- before do- allow(storage_requests).to receive(:upload_link_query).and_return(- ServiceResult.failure(- result: :not_authorized,- errors: Storages::StorageError.new(code: :not_authorized)- )- )- end+ let(:error) { :not_authorized }it { expect(last_response.status).to be(500) }enddescribe 'due to internal error' do- before do- allow(storage_requests).to receive(:upload_link_query).and_return(- ServiceResult.failure(- result: :error,- errors: Storages::StorageError.new(code: :error)- )- )- end+ let(:error) { :error }it { expect(last_response.status).to be(500) }enddescribe 'due to not found' do- before do- allow(storage_requests).to receive(:upload_link_query).and_return(- ServiceResult.failure(- result: :not_found,- errors: Storages::StorageError.new(code: :not_found)- )- )- end+ let(:error) { :not_found }it 'fails with outbound request failure' doexpect(last_response.status).to be(500)