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

[57347] Fixed NextcloudConnectionValidator specs

Andreas Pfohl6cd207198a9b
diff --git a/modules/storages/app/common/storages/peripherals/nextcloud_connection_validator.rb b/modules/storages/app/common/storages/peripherals/nextcloud_connection_validator.rb
index 19e0dcd3212..c275c310b73 100644
--- a/modules/storages/app/common/storages/peripherals/nextcloud_connection_validator.rb
+++ b/modules/storages/app/common/storages/peripherals/nextcloud_connection_validator.rb
@@ -39,6 +39,7 @@ module Storages
@storage = storage
end
+ # rubocop:disable Metrics/AbcSize
def validate
maybe_is_not_configured
.or { host_url_not_found }
@@ -46,13 +47,16 @@ module Storages
.or { version_mismatch }
.or { with_unexpected_content }
.or { group_folder_not_found }
- .or { request_failed_with_unknown_error }
+ .or { capabilities_request_failed_with_unknown_error }
+ .or { files_request_failed_with_unknown_error }
.value_or(ConnectionValidation.new(type: :healthy,
error_code: :none,
timestamp: Time.current,
description: nil))
end
+ # rubocop:enable Metrics/AbcSize
+
private
def capabilities
@@ -164,15 +168,7 @@ module Storages
# rubocop:disable Metrics/AbcSize
def with_unexpected_content
return None() unless @storage.automatic_management_enabled?
-
- if files.failure?
- return Some(
- ConnectionValidation.new(type: :error,
- error_code: :err_unknown,
- timestamp: Time.current,
- description: I18n.t("storages.health.connection_validation.unknown_error"))
- )
- end
+ return None() if files.failure?
expected_folder_ids = @storage.project_storages
.where(project_folder_mode: "automatic")
@@ -193,8 +189,7 @@ module Storages
# rubocop:enable Metrics/AbcSize
- # rubocop:disable Metrics/AbcSize
- def request_failed_with_unknown_error
+ def capabilities_request_failed_with_unknown_error
return None() if capabilities.success?
Rails.logger.error(
@@ -204,6 +199,13 @@ module Storages
"response: #{capabilities.error_payload}"
)
+ Some(ConnectionValidation.new(type: :error,
+ error_code: :err_unknown,
+ timestamp: Time.current,
+ description: I18n.t("storages.health.connection_validation.unknown_error")))
+ end
+
+ def files_request_failed_with_unknown_error
return None() if files.success?
Rails.logger.error(
@@ -219,15 +221,11 @@ module Storages
description: I18n.t("storages.health.connection_validation.unknown_error")))
end
- # rubocop:enable Metrics/AbcSize
-
def noop = StorageInteraction::AuthenticationStrategies::Noop.strategy
def userless = Peripherals::Registry.resolve("#{@storage.short_provider_type}.authentication.userless").call
- def path_to_config
- Rails.root.join("modules/storages/config/nextcloud_dependencies.yml")
- end
+ def path_to_config = Rails.root.join("modules/storages/config/nextcloud_dependencies.yml")
end
end
end
diff --git a/modules/storages/config/locales/en.yml b/modules/storages/config/locales/en.yml
index 51013896c8d..130c171126b 100644
--- a/modules/storages/config/locales/en.yml
+++ b/modules/storages/config/locales/en.yml
@@ -210,8 +210,8 @@ en:
client_id_wrong: The configured OAuth 2 client id is invalid. Please check the configuration.
client_secret_wrong: The configured OAuth 2 client secret is invalid. Please check the configuration.
drive_id_wrong: The configured drive id could not be found. Please check the configuration.
- group_folder_version_mismatch: The Group Folder version is not supported. Please update your Nextcloud server.
group_folder_not_found: The group folder could not be found.
+ group_folder_version_mismatch: The Group Folder version is not supported. Please update your Nextcloud server.
host_not_found: No Nextcloud server found at the configured host url. Please check the configuration.
missing_dependencies: 'A required dependency is missing on the file storage. Please add the following dependency: %{dependency}.'
not_configured: The connection could not be validated. Please finish configuration first.
diff --git a/modules/storages/spec/common/storages/peripherals/nextcloud_connection_validator_spec.rb b/modules/storages/spec/common/storages/peripherals/nextcloud_connection_validator_spec.rb
index 208a14d2269..f9ddf0a3b40 100644
--- a/modules/storages/spec/common/storages/peripherals/nextcloud_connection_validator_spec.rb
+++ b/modules/storages/spec/common/storages/peripherals/nextcloud_connection_validator_spec.rb
@@ -164,9 +164,7 @@ RSpec.describe Storages::Peripherals::NextcloudConnectionValidator do
before { project_storage }
context "if the request returns not_found" do
- let(:files_response) do
- Storages::Peripherals::StorageInteraction::Nextcloud::Util.error(:not_found)
- end
+ let(:files_response) { build_failure(code: :not_found, payload: nil) }
it "returns a validation failure" do
expect(subject.type).to eq(:error)
@@ -212,6 +210,7 @@ RSpec.describe Storages::Peripherals::NextcloudConnectionValidator do
context "if query returns an unhandled error" do
let(:storage) { create(:nextcloud_storage_configured) }
let(:capabilities_response) { build_failure(code: :error, payload: nil) }
+ let(:files_response) { build_failure(code: :error, payload: nil) }
before do
allow(Rails.logger).to receive(:error)