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

chore[#50921] Add tests for health status

Dominic Bräunlein1fd4d48add63
diff --git a/modules/storages/app/components/storages/admin/health_status_component.html.erb b/modules/storages/app/components/storages/admin/health_status_component.html.erb
index ca512118b1f..362dff286c8 100644
--- a/modules/storages/app/components/storages/admin/health_status_component.html.erb
+++ b/modules/storages/app/components/storages/admin/health_status_component.html.erb
@@ -2,23 +2,23 @@
<%= render(Primer::Beta::Heading.new(tag: :h4, mb: 2)) { I18n.t('storages.health.title') } %>
<%= render(Primer::Box.new(py: 1)) do %>
- <%= render(Primer::Beta::Text.new) { I18n.t('storages.health.checked', datetime: helpers.format_time(storage.health_changed_at)) } %>
+ <%= render(Primer::Beta::Text.new(test_selector: "storage-health-changed-at")) { I18n.t('storages.health.checked', datetime: helpers.format_time(storage.health_changed_at)) } %>
<% if storage.health_healthy? %>
- <%= render(Primer::Beta::Label.new(scheme: :success, test_selector: "label-healthy")) {
+ <%= render(Primer::Beta::Label.new(scheme: :success, test_selector: "storage-health-label-healthy")) {
I18n.t('storages.health.label_healthy')
} %>
<% elsif storage.health_unhealthy? %>
- <%= render(Primer::Beta::Label.new(scheme: :danger, test_selector: "label-error")) {
+ <%= render(Primer::Beta::Label.new(scheme: :danger, test_selector: "storage-health-label-error")) {
I18n.t('storages.health.label_error')
} %>
<% else %>
- <%= render(Primer::Beta::Label.new(scheme: :attention, test_selector: "label-pending")) {
+ <%= render(Primer::Beta::Label.new(scheme: :attention, test_selector: "storage-health-label-pending")) {
I18n.t('storages.health.label_pending')
} %>
<% end %>
<% end %>
<% if storage.health_unhealthy? %>
- <%= render(Primer::Beta::Text.new(tag: :div, color: :muted, py: 1)) { storage.formatted_health_reason } %>
+ <%= render(Primer::Beta::Text.new(tag: :div, color: :muted, py: 1, test_selector: "storage-health-reason")) { storage.formatted_health_reason } %>
<% end %>
<% end %>
diff --git a/modules/storages/app/components/storages/admin/storage_list_component.html.erb b/modules/storages/app/components/storages/admin/storage_list_component.html.erb
index d83bdcb353b..df473eea341 100644
--- a/modules/storages/app/components/storages/admin/storage_list_component.html.erb
+++ b/modules/storages/app/components/storages/admin/storage_list_component.html.erb
@@ -28,11 +28,11 @@
concat(render(Primer::Beta::Link.new(href: edit_admin_settings_storage_path(storage), scheme: :primary, mr: 1, data: { 'test-selector': 'storage-name' })) { storage.name })
unless storage.configured?
- concat(render(Primer::Beta::Label.new(scheme: :attention, test_selector: "label-incomplete", mr: 1)) { I18n.t('storages.label_incomplete') })
+ concat(render(Primer::Beta::Label.new(scheme: :attention, test_selector: "label-incomplete")) { I18n.t('storages.label_incomplete') })
end
if storage.health_unhealthy?
- concat(render(Primer::Beta::Label.new(scheme: :danger, test_selector: "label-error")) { I18n.t('storages.health.label_error') })
+ concat(render(Primer::Beta::Label.new(scheme: :danger, test_selector: "storage-health-label-error")) { I18n.t('storages.health.label_error') })
end
end
diff --git a/modules/storages/app/models/storages/storage.rb b/modules/storages/app/models/storages/storage.rb
index 5bc4d9f0691..90b8c779033 100644
--- a/modules/storages/app/models/storages/storage.rb
+++ b/modules/storages/app/models/storages/storage.rb
@@ -132,6 +132,9 @@ module Storages
provider_type == ::Storages::Storage::PROVIDER_TYPE_ONE_DRIVE
end
+ # Currently the error messages saved look like:
+ # "unauthorized | Outbound request not authorized | #<Storages::StorageErrorData:0x0000ffff646ac570>"
+ # This method returns the first two parts of the error message.
def formatted_health_reason
split_reason = health_reason.split('|')
if split_reason.length === 3
diff --git a/modules/storages/spec/factories/storage_factory.rb b/modules/storages/spec/factories/storage_factory.rb
index 7e1b1e445a8..4d2e3b75858 100644
--- a/modules/storages/spec/factories/storage_factory.rb
+++ b/modules/storages/spec/factories/storage_factory.rb
@@ -54,6 +54,7 @@ FactoryBot.define do
class: '::Storages::NextcloudStorage' do
provider_type { Storages::Storage::PROVIDER_TYPE_NEXTCLOUD }
sequence(:host) { |n| "https://host#{n}.example.com" }
+ sequence(:name) { |n| "Storage #{n}" }
trait :as_automatically_managed do
automatically_managed { true }
@@ -64,6 +65,30 @@ FactoryBot.define do
trait :as_not_automatically_managed do
automatically_managed { false }
end
+
+ trait :as_healthy do
+ health_status { 'healthy' }
+ health_reason { nil }
+ health_changed_at { Time.now.utc }
+ end
+
+ trait :as_unhealthy do
+ health_status { 'unhealthy' }
+ health_reason { 'error reason' }
+ health_changed_at { Time.now.utc }
+ end
+
+ trait :as_unhealthy_long_reason do
+ health_status { 'unhealthy' }
+ health_reason { 'unauthorized | Outbound request not authorized | #<Storages::StorageErrorData:0x0000ffff646ac570>' }
+ health_changed_at { Time.now.utc }
+ end
+
+ trait :as_pending do
+ health_status { 'pending' }
+ health_reason { nil }
+ health_changed_at { Time.now.utc }
+ end
end
factory :nextcloud_storage_with_local_connection,
@@ -106,6 +131,18 @@ FactoryBot.define do
end
end
+ factory :nextcloud_storage_with_complete_configuration,
+ parent: :nextcloud_storage,
+ traits: [:as_automatically_managed] do
+ sequence(:host) { |n| "https://host-complete#{n}.example.com" }
+ sequence(:name) { |n| "Storage complete #{n}" }
+
+ after(:create) do |storage|
+ create(:oauth_client, integration: storage)
+ create(:oauth_application, integration: storage)
+ end
+ end
+
factory :one_drive_storage,
parent: :storage,
class: '::Storages::OneDriveStorage' do
diff --git a/modules/storages/spec/features/admin_storages_spec.rb b/modules/storages/spec/features/admin_storages_spec.rb
index e7eb406c4d8..ffee47cc638 100644
--- a/modules/storages/spec/features/admin_storages_spec.rb
+++ b/modules/storages/spec/features/admin_storages_spec.rb
@@ -34,6 +34,8 @@ require_module_spec_helper
RSpec.describe 'Admin storages',
:js,
:storage_server_helpers do
+ include Redmine::I18n
+
let(:admin) { create(:admin) }
before { login_as admin }
@@ -43,9 +45,16 @@ RSpec.describe 'Admin storages',
let(:complete_storage) { create(:nextcloud_storage_with_local_connection) }
let(:incomplete_storage) { create(:nextcloud_storage) }
+ let(:complete_nextcloud_storage_health_pending) { create(:nextcloud_storage_with_complete_configuration) }
+ let(:complete_nextcloud_storage_health_healthy) { create(:nextcloud_storage_with_complete_configuration, :as_healthy) }
+ let(:complete_nextcloud_storage_health_unhealthy) { create(:nextcloud_storage_with_complete_configuration, :as_unhealthy) }
+
before do
complete_storage
incomplete_storage
+ complete_nextcloud_storage_health_pending
+ complete_nextcloud_storage_health_healthy
+ complete_nextcloud_storage_health_unhealthy
end
it 'renders a list of storages' do
@@ -71,6 +80,24 @@ RSpec.describe 'Admin storages',
expect(page).to have_css('[data-test-selector="storage-host"]', text: incomplete_storage.host)
expect(page).to have_css('.op-principal--name', text: incomplete_storage.creator.name)
end
+
+ within "li#storages_nextcloud_storage_#{complete_nextcloud_storage_health_pending.id}" do
+ expect(page).not_to have_test_selector('storage-health-label-error')
+ expect(page).not_to have_test_selector('storage-health-label-healthy')
+ expect(page).not_to have_test_selector('storage-health-label-pending')
+ end
+
+ within "li#storages_nextcloud_storage_#{complete_nextcloud_storage_health_healthy.id}" do
+ expect(page).not_to have_test_selector('storage-health-label-healthy')
+ expect(page).not_to have_test_selector('storage-health-label-error')
+ expect(page).not_to have_test_selector('storage-health-label-pending')
+ end
+
+ within "li#storages_nextcloud_storage_#{complete_nextcloud_storage_health_unhealthy.id}" do
+ expect(page).to have_test_selector('storage-health-label-error')
+ expect(page).not_to have_test_selector('storage-health-label-healthy')
+ expect(page).not_to have_test_selector('storage-health-label-pending')
+ end
end
end
@@ -543,4 +570,49 @@ RSpec.describe 'Admin storages',
end
end
end
+
+ describe 'health status information in edit page' do
+ frozen_date_time = Time.current
+
+ Timecop.freeze(frozen_date_time) do
+ let(:complete_nextcloud_storage_health_pending) { create(:nextcloud_storage_with_complete_configuration) }
+ let(:complete_nextcloud_storage_health_healthy) { create(:nextcloud_storage_with_complete_configuration, :as_healthy) }
+ let(:complete_nextcloud_storage_health_unhealthy) { create(:nextcloud_storage_with_complete_configuration, :as_unhealthy) }
+ let(:complete_nextcloud_storage_health_unhealthy_long_reason) do
+ create(:nextcloud_storage_with_complete_configuration, :as_unhealthy_long_reason)
+ end
+
+ before do
+ complete_nextcloud_storage_health_pending
+ complete_nextcloud_storage_health_healthy
+ complete_nextcloud_storage_health_unhealthy
+ complete_nextcloud_storage_health_unhealthy_long_reason
+ end
+
+ it 'shows healthy status for storages that are healthy' do
+ visit edit_admin_settings_storage_path(complete_nextcloud_storage_health_healthy)
+ expect(page).to have_css('[data-test-selector="storage-health-label-healthy"]', text: 'Healthy')
+ expect(page).to have_css('[data-test-selector="storage-health-changed-at"]',
+ text: "Checked #{format_time(frozen_date_time)}")
+ end
+
+ it 'shows pending label for a storage that is pending' do
+ visit edit_admin_settings_storage_path(complete_nextcloud_storage_health_pending)
+ expect(page).to have_css('[data-test-selector="storage-health-label-pending"]', text: 'Pending')
+ end
+
+ it 'shows error status for storages that are unhealthy' do
+ visit edit_admin_settings_storage_path(complete_nextcloud_storage_health_unhealthy)
+ expect(page).to have_css('[data-test-selector="storage-health-label-error"]', text: 'Error')
+ expect(page).to have_css('[data-test-selector="storage-health-reason"]', text: 'error reason')
+ end
+
+ it 'shows formatted error reason for storages that are unhealthy' do
+ visit edit_admin_settings_storage_path(complete_nextcloud_storage_health_unhealthy_long_reason)
+ expect(page).to have_css('[data-test-selector="storage-health-label-error"]', text: 'Error')
+ expect(page).to have_css('[data-test-selector="storage-health-reason"]',
+ text: 'Unauthorized: Outbound request not authorized')
+ end
+ end
+ end
end
diff --git a/spec/factories/oauth_application_factory.rb b/spec/factories/oauth_application_factory.rb
index 59d2733c000..cba5e5af5dc 100644
--- a/spec/factories/oauth_application_factory.rb
+++ b/spec/factories/oauth_application_factory.rb
@@ -32,7 +32,7 @@ FactoryBot.define do
confidential { true }
owner factory: :admin
owner_type { 'User' }
- uid { '12345' }
+ sequence(:uid) { |n| "2345678901-#{n}" }
redirect_uri { 'urn:ietf:wg:oauth:2.0:oob' }
scopes { 'api_v3' }
end