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
Split the DownloadLinkQuery tests from the Registry
Marcello Rochaefc44e5102a8
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive.rbindex 60096478dfd..9d70ce56118 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/one_drive.rb@@ -34,6 +34,7 @@ module Storagesmodule OneDriveQueries = Dry::Container::Namespace.new('queries') donamespace('one_drive') do+ register(:download_link, DownloadLinkQuery)register(:files, FilesQuery)register(:file_info, FileInfoQuery)register(:files_info, FilesInfoQuery)diff --git a/modules/storages/spec/common/storages/peripherals/registry_spec.rb b/modules/storages/spec/common/storages/peripherals/registry_spec.rbindex 01d1b1deb94..6144ec65261 100644--- a/modules/storages/spec/common/storages/peripherals/registry_spec.rb+++ b/modules/storages/spec/common/storages/peripherals/registry_spec.rb@@ -64,115 +64,6 @@ RSpec.describe Storages::Peripherals::Registry, :webmock dobefore { token }- describe '#download_link_query' do- let(:file_link) do- Struct.new(:file_link) do- def origin_id- 42- end-- def origin_name- 'example.md'- end- end.new- end- let(:download_token) { "8dM3dC9iy1N74F5AJ0ClnjSF4dWTxfymVy1HTXBh8rbZVM81CpcBJaIYZvmR" }- let(:uri) do- "#{url}/index.php/apps/integration_openproject/direct/#{download_token}/#{CGI.escape(file_link.origin_name)}"- end- let(:json) do- {- ocs: {- meta: {- status: 'ok',- statuscode: 200,- message: 'OK'- },- data: {- url: "https://example.com/remote.php/direct/#{download_token}"- }- }- }.to_json- end-- before do- stub_request(:post, "#{url}/ocs/v2.php/apps/dav/api/v1/direct")- .to_return(status: 200, body: json, headers: {})- end-- describe 'with Nextcloud storage type selected' do- it 'must return a download link URL' do- result = registry.resolve("queries.nextcloud.download_link").call(storage:, user:, file_link:)- expect(result).to be_success- expect(result.result).to eql(uri)- end-- context 'if Nextcloud is running on a sub path' do- let(:url) { 'https://example.com/html' }-- it 'must return a download link URL' do- result = registry.resolve('queries.nextcloud.download_link').call(storage:, user:, file_link:)- expect(result).to be_success- expect(result.result).to eql(uri)- end- end- end-- describe 'with not supported storage type selected' do- before do- allow(storage).to receive(:provider_type).and_return('not_supported_storage_type')- end-- it 'must raise ArgumentError' do- expect { registry.resolve('queries.nextcloud.download_link').call(storage:) }.to raise_error(ArgumentError)- end- end-- describe 'with missing OAuth token' do- before do- instance = instance_double(OAuthClients::ConnectionManager)- allow(OAuthClients::ConnectionManager).to receive(:new).and_return(instance)- allow(instance).to receive(:get_access_token).and_return(ServiceResult.failure)- end-- it 'must return ":unauthorized" ServiceResult' do- result = registry.resolve('queries.nextcloud.download_link').call(storage:, user:, file_link:)- expect(result).to be_failure- expect(result.errors.code).to be(:unauthorized)- end- end-- describe 'with outbound request returning 200 and an empty body' do- before do- stub_request(:post, "#{url}/ocs/v2.php/apps/dav/api/v1/direct").to_return(status: 200, body: '')- end-- it 'must return :unauthorized ServiceResult' do- result = registry.resolve('queries.nextcloud.download_link').call(user:, file_link:, storage:)- expect(result).to be_failure- expect(result.errors.code).to be(:unauthorized)- end- end-- shared_examples_for 'outbound is failing' do |code = 500, symbol = :error|- describe "with outbound request returning #{code}" do- before do- stub_request(:post, "#{url}/ocs/v2.php/apps/dav/api/v1/direct").to_return(status: code)- end-- it "must return :#{symbol} ServiceResult" do- result = registry.resolve('queries.nextcloud.download_link').call(user:, file_link:, storage:)- expect(result).to be_failure- expect(result.errors.code).to eq(symbol)- end- end- end-- include_examples 'outbound is failing', 404, :not_found- include_examples 'outbound is failing', 401, :unauthorized- include_examples 'outbound is failing', 500, :error- end-describe '#upload_link_query' dolet(:query_payload) { Struct.new(:parent).new(42) }let(:upload_token) { 'valid-token' }diff --git a/modules/storages/spec/common/storages/peripherals/storage_interaction/nextcloud/download_link_query_spec.rb b/modules/storages/spec/common/storages/peripherals/storage_interaction/nextcloud/download_link_query_spec.rbnew file mode 100644index 00000000000..530d6bcda03--- /dev/null+++ b/modules/storages/spec/common/storages/peripherals/storage_interaction/nextcloud/download_link_query_spec.rb@@ -0,0 +1,111 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++require 'spec_helper'+require_module_spec_helper++RSpec.describe Storages::Peripherals::StorageInteraction::Nextcloud::DownloadLinkQuery, :webmock do+ let(:file_link) { create(:file_link) }+ let(:download_token) { "8dM3dC9iy1N74F5AJ0ClnjSF4dWTxfymVy1HTXBh8rbZVM81CpcBJaIYZvmR" }+ let(:uri) do+ "#{url}/index.php/apps/integration_openproject/direct/#{download_token}/#{CGI.escape(file_link.origin_name)}"+ end+ let(:json) do+ {+ ocs: {+ meta: {+ status: 'ok',+ statuscode: 200,+ message: 'OK'+ },+ data: {+ url: "https://example.com/remote.php/direct/#{download_token}"+ }+ }+ }.to_json+ end++ let(:url) { storage.host }+ let(:storage) { create(:nextcloud_storage, :with_oauth_client) }+ let(:user) { create(:user) }+ let(:token) { create(:oauth_client_token, user:, oauth_client: storage.oauth_client) }++ before do+ allow(Storages::Peripherals::StorageInteraction::Nextcloud::Util).to receive(:token).and_yield(token)++ stub_request(:post, "#{url}/ocs/v2.php/apps/dav/api/v1/direct").to_return(status: 200, body: json, headers: {})+ end++ it 'must return a download link URL' do+ result = described_class.call(storage:, user:, file_link:)+ expect(result).to be_success+ expect(result.result).to eql(uri)+ end++ context 'if Nextcloud is running on a sub path' do+ let(:storage) { create(:nextcloud_storage, :with_oauth_client, host: 'https://example.com/html') }++ it 'must return a download link URL' do+ result = described_class.call(storage:, user:, file_link:)+ expect(result).to be_success+ expect(result.result).to eql(uri)+ end+ end++ describe 'with outbound request returning 200 and an empty body' do+ before do+ stub_request(:post, "#{url}/ocs/v2.php/apps/dav/api/v1/direct").to_return(status: 200, body: '')+ end++ it 'must return :unauthorized ServiceResult' do+ result = described_class.call(user:, file_link:, storage:)+ expect(result).to be_failure+ expect(result.errors.code).to be(:unauthorized)+ end+ end++ shared_examples_for 'outbound is failing' do |code = 500, symbol = :error|+ describe "with outbound request returning #{code}" do+ before do+ stub_request(:post, "#{url}/ocs/v2.php/apps/dav/api/v1/direct").to_return(status: code)+ end++ it "must return :#{symbol} ServiceResult" do+ result = described_class.call(user:, file_link:, storage:)+ expect(result).to be_failure+ expect(result.errors.code).to eq(symbol)+ end+ end+ end++ include_examples 'outbound is failing', 404, :not_found+ include_examples 'outbound is failing', 401, :unauthorized+ include_examples 'outbound is failing', 500, :error+end