diff --git a/app/services/interaction_tracking_service.rb b/app/services/interaction_tracking_service.rb index 0a84855b3f..e0da5254af 100644 --- a/app/services/interaction_tracking_service.rb +++ b/app/services/interaction_tracking_service.rb @@ -10,7 +10,7 @@ def self.record_incoming_interaction(client, set_flag: true, **attrs) should_record_interaction = interaction_type.present? && interaction_type != 'unfilled' if should_record_interaction && Flipper.enabled?(:hub_email_notifications) users_to_contact = client.tax_returns.pluck(:assigned_user_id).compact - users_to_contact = User.where(id: users_to_contact, "#{interaction_type}_notification" => "yes") + users_to_contact = User.active.where(id: users_to_contact, "#{interaction_type}_notification" => "yes") unless users_to_contact.empty? email_attrs = { received_at: attrs[:received_at] || interaction.created_at @@ -45,7 +45,7 @@ def self.record_internal_interaction(client, **attrs) if interaction_type == "tagged_in_note" user = attrs[:user] - if user&.tagged_in_note_notification_yes? && Flipper.enabled?(:hub_email_notifications) + if user&.tagged_in_note_notification_yes? && Flipper.enabled?(:hub_email_notifications) && user&.active? internal_email = InternalEmail.create!( mail_class: UserMailer, mail_method: :internal_interaction_notification_email, diff --git a/spec/services/interaction_tracking_service_spec.rb b/spec/services/interaction_tracking_service_spec.rb index a244695d77..9940d2ff76 100644 --- a/spec/services/interaction_tracking_service_spec.rb +++ b/spec/services/interaction_tracking_service_spec.rb @@ -152,6 +152,17 @@ expect(job).not_to have_received(:perform_later) end end + + context "user that has been suspended" do + let!(:suspended_user) { create(:admin_user, new_client_message_notification: "yes", suspended_at: 1.day.ago) } + let!(:tax_return_3) { create(:tax_return, assigned_user_id: suspended_user.id, year: Rails.configuration.product_year-2, client: client) } + + it "doesn't send a message to suspended user" do + described_class.record_incoming_interaction(client, received_at: fake_time, interaction_type: "new_client_message") + expect(job).not_to have_received(:perform_later).with(anything, suspended_user, hash_including(received_at: fake_time)) + expect(job).to have_received(:perform_later).with(anything, user, hash_including(received_at: fake_time)) + end + end end describe "#record_internal_interaction" do @@ -214,6 +225,15 @@ expect(SendInternalEmailJob).not_to have_received(:perform_later) end end + + context "user has been suspended" do + let(:user) { create(:admin_user, tagged_in_note_notification: "yes", suspended_at: 1.day.ago) } + + it "doesn't send a message" do + described_class.record_internal_interaction(client, interaction_type: "tagged_in_note", user: user, received_at: received_at) + expect(SendInternalEmailJob).not_to have_received(:perform_later) + end + end end end end