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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
tests[Op#52449]: Health service should respect notification status
Kabiru Mwenjac9da90074393
diff --git a/modules/storages/app/services/storages/health_service.rb b/modules/storages/app/services/storages/health_service.rbindex ac2ecc02dbf..403b8ccbbdd 100644--- a/modules/storages/app/services/storages/health_service.rb+++ b/modules/storages/app/services/storages/health_service.rb@@ -43,9 +43,7 @@ module Storageshealth_checked_at: Time.now.utc,health_reason: nil)- admin_users.each do |admin|- ::Storages::StoragesMailer.notify_healthy(admin, @storage, reason).deliver_later- end+ notify_healthy_admin_users(reason)endend@@ -76,7 +74,17 @@ module Storagesprivate+ def notify_healthy_admin_users(reason)+ return unless @storage.health_notifications_enabled?++ admin_users.each do |admin|+ ::Storages::StoragesMailer.notify_healthy(admin, @storage, reason).deliver_later+ end+ end+def notify_unhealthy_admin_users+ return unless @storage.health_notifications_enabled?+admin_users.each do |admin|::Storages::StoragesMailer.notify_unhealthy(admin, @storage).deliver_laterenddiff --git a/modules/storages/spec/services/storages/health_service_spec.rb b/modules/storages/spec/services/storages/health_service_spec.rbindex 4d539d808a3..b4103c48d12 100644--- a/modules/storages/spec/services/storages/health_service_spec.rb+++ b/modules/storages/spec/services/storages/health_service_spec.rb@@ -108,4 +108,56 @@ RSpec.describe Storages::HealthService doend# rubocop:enable RSpec/ExampleLengthend++ describe "Health notifications" do+ let(:user) { create(:user) }+ let(:admin_user) { create(:admin) }+ let(:role) { create(:project_role) }+ let(:storage) { create(:nextcloud_storage) }+ let!(:project_storage) { create(:project_storage, project:, storage:) }++ let(:project) do+ create(:project,+ members: { user => role,+ admin_user => role },+ enabled_module_names: %i[storages])+ end++ context "when the storage has notifications enabled" do+ before do+ storage.update(health_notifications_enabled: true)+ end++ it "notifies admin users when the storage becomes healthy" do+ expect do+ health_service.healthy+ end.to have_enqueued_mail(Storages::StorageMailer, :notify_healthy)+ .with(admin_storage, storage, storage.health_reason).at_most(:once)+ end++ it "notifies admin users when the storage becomes unhealthy" do+ expect do+ health_service.unhealthy(reason: "thou_shall_not_pass_error")+ end.to have_enqueued_mail(Storages::StoragesMailer, :notify_unhealthy).with(admin_user, storage).at_most(:once)+ end+ end++ context "when the storage has notifications disabled" do+ before do+ storage.update(health_notifications_enabled: false)+ end++ it "does not notify admin users when the storage becomes healthy" do+ expect do+ health_service.healthy+ end.not_to have_enqueued_mail(Storages::StoragesMailer, :notify_healthy)+ end++ it "does not notify admin users when the storage becomes unhealthy" do+ expect do+ health_service.unhealthy(reason: "thou_shall_not_pass_error")+ end.not_to have_enqueued_mail(Storages::StoragesMailer, :notify_unhealthy)+ end+ end+ endend