From 839d67b53664482ba84e6c00cc4a4edd417f774c Mon Sep 17 00:00:00 2001 From: Andreas Pfohl Date: Tue, 17 Sep 2024 10:06:11 +0200 Subject: [PATCH] [57347] Fixed NextcloudConnectionValidator specs --- .../nextcloud_connection_validator.rb | 32 +++++++++---------- .../nextcloud_connection_validator_spec.rb | 5 ++- 2 files changed, 17 insertions(+), 20 deletions(-) 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 19e0dcd32126..c275c310b732 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 @@ def initialize(storage:) @storage = storage end + # rubocop:disable Metrics/AbcSize def validate maybe_is_not_configured .or { host_url_not_found } @@ -46,13 +47,16 @@ def validate .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 @@ def group_folder_not_found # 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 @@ def with_unexpected_content # 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 @@ def request_failed_with_unknown_error "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 @@ def request_failed_with_unknown_error 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/spec/common/storages/peripherals/nextcloud_connection_validator_spec.rb b/modules/storages/spec/common/storages/peripherals/nextcloud_connection_validator_spec.rb index 208a14d2269a..f9ddf0a3b403 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 @@ 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 @@ 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)