Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/services/interaction_tracking_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
20 changes: 20 additions & 0 deletions spec/services/interaction_tracking_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading