Skip to content

Commit

Permalink
[57347] Added test for unexpected files validation for Nextcloud storage
Browse files Browse the repository at this point in the history
  • Loading branch information
apfohl committed Sep 11, 2024
1 parent ec581a8 commit 21e5536
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ def request_failed_with_unknown_error

Rails.logger.error(
"Connection validation failed with unknown error:\n\t" \
"storage: ##{@storage.id} #{@storage.name}\n\t" \
"status: #{query.result}\n\t" \
"response: #{query.error_payload}"
"storage: ##{@storage.id} #{@storage.name}\n\t" \
"status: #{query.result}\n\t" \
"response: #{query.error_payload}"
)

Some(ConnectionValidation.new(type: :error,
Expand All @@ -184,10 +184,14 @@ def with_unexpected_content
unexpected_files = files.result.files.reject { |file| expected_folder_ids.include?(file.id) }
return None() if unexpected_files.empty?

Some(ConnectionValidation.new(type: :warning,
error_code: :wrn_unexpected_content,
timestamp: Time.current,
description: I18n.t("storages.health.connection_validation.unexpected_content")))
Some(
ConnectionValidation.new(
type: :warning,
error_code: :wrn_unexpected_content,
timestamp: Time.current,
description: I18n.t("storages.health.connection_validation.unexpected_content.nextcloud")
)
)
end

# rubocop:enable Metrics/AbcSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def drive_with_unexpected_content
Some(ConnectionValidation.new(type: :warning,
error_code: :wrn_unexpected_content,
timestamp: Time.current,
description: I18n.t("storages.health.connection_validation.unexpected_content")))
description: I18n.t("storages.health.connection_validation.unexpected_content.one_drive")))
end

# rubocop:enable Metrics/AbcSize
Expand Down
4 changes: 3 additions & 1 deletion modules/storages/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,9 @@ en:
placeholder: Check your connection against the server.
subtitle: Connection validation
tenant_id_wrong: The configured directory (tenant) id is invalid. Please check the configuration.
unexpected_content: Unexpected content found in the drive.
unexpected_content:
nextcloud: Unexpected content found in the managed folder.
one_drive: Unexpected content found in the drive.
unknown_error: The connection could not be validated. An unknown error occurred. Please check the server logs for further information.
label_error: Error
label_healthy: Healthy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@

RSpec.describe Storages::Peripherals::NextcloudConnectionValidator do
before do
Storages::Peripherals::Registry.stub("#{storage.short_provider_type}.queries.capabilities", ->(_) { response })
Storages::Peripherals::Registry.stub("#{storage.short_provider_type}.queries.capabilities", ->(_) { capabilities_response })
Storages::Peripherals::Registry.stub("#{storage.short_provider_type}.queries.files", ->(_) { files_response })
end

subject { described_class.new(storage:).validate }
Expand All @@ -48,7 +49,7 @@

context "if nextcloud host url could not be found" do
let(:storage) { create(:nextcloud_storage_configured) }
let(:response) { build_failure(code: :not_found, payload: nil) }
let(:capabilities_response) { build_failure(code: :not_found, payload: nil) }

it "returns a validation failure" do
expect(subject.type).to eq(:error)
Expand All @@ -64,14 +65,22 @@
let(:app_version) { Storages::SemanticVersion.parse("2.6.3") }
let(:group_folder_enabled) { true }
let(:group_folder_version) { Storages::SemanticVersion.parse("17.0.1") }
let(:response) do
let(:project_folder_id) { "1337" }
let(:capabilities_response) do
ServiceResult.success(result: Storages::NextcloudCapabilities.new(
app_enabled?: app_enabled,
app_version:,
group_folder_enabled?: group_folder_enabled,
group_folder_version:
))
end
let(:files_response) do
ServiceResult.success(result: Storages::StorageFiles.new(
[],
Storages::StorageFile.new(id: "root", name: "root"),
[]
))
end

it "returns a healthy validation" do
expect(subject.type).to eq(:healthy)
Expand Down Expand Up @@ -141,11 +150,42 @@
end
end
end

context "if the request returns unexpected files" do
let(:storage) { create(:nextcloud_storage_configured, :as_automatically_managed) }
let(:project_storage) do
create(:project_storage,
:as_automatically_managed,
project_folder_id:,
storage:,
project: create(:project))
end
let(:files_response) do
ServiceResult.success(result: Storages::StorageFiles.new(
[
Storages::StorageFile.new(id: project_folder_id, name: "I am your father"),
Storages::StorageFile.new(id: "noooooooooo", name: "testimony_of_luke_skywalker.md")
],
Storages::StorageFile.new(id: "root", name: "root"),
[]
))
end

before do
project_storage
end

it "returns a validation failure" do
expect(subject.type).to eq(:warning)
expect(subject.error_code).to eq(:wrn_unexpected_content)
expect(subject.description).to eq("Unexpected content found in the managed folder.")
end
end
end

context "if query returns an unhandled error" do
let(:storage) { create(:nextcloud_storage_configured) }
let(:response) { build_failure(code: :error, payload: nil) }
let(:capabilities_response) { build_failure(code: :error, payload: nil) }

before do
allow(Rails.logger).to receive(:error)
Expand Down

0 comments on commit 21e5536

Please sign in to comment.