Skip to content

Commit

Permalink
[57347] Fixed NextcloudConnectionValidator specs
Browse files Browse the repository at this point in the history
  • Loading branch information
apfohl committed Sep 17, 2024
1 parent fc9c584 commit 6cd2071
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,24 @@ def initialize(storage:)
@storage = storage
end

# rubocop:disable Metrics/AbcSize
def validate
maybe_is_not_configured
.or { host_url_not_found }
.or { missing_dependencies }
.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
Expand Down Expand Up @@ -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")
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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
2 changes: 1 addition & 1 deletion modules/storages/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6cd2071

Please sign in to comment.