1 # frozen_string_literal: true
5 class ChangesetCommentNotifierTest < ActiveSupport::TestCase
7 ActionMailer::Base.deliveries.clear
10 def test_send_email_when_subscribed
11 candidate_recipient = create(:user)
12 candidate_recipient.notification_preferences.update("changeset_comment" => ["email"])
14 trigger_notification(candidate_recipient)
16 email = ActionMailer::Base.deliveries.first
17 assert_equal [candidate_recipient.email], email.to
20 def test_do_not_send_email_when_not_subscribed
21 candidate_recipient = create(:user)
22 candidate_recipient.notification_preferences.update("changeset_comment" => [])
24 trigger_notification(candidate_recipient)
26 assert_empty ActionMailer::Base.deliveries
31 def trigger_notification(changeset_author)
32 changeset = create(:changeset, :user => changeset_author)
33 create(:changeset_subscription, :changeset => changeset, :subscriber => changeset_author)
35 comment_author = create(:user)
36 changeset_comment = create(:changeset_comment, :author => comment_author, :changeset => changeset)
38 perform_enqueued_jobs do
39 Nominatim.stub :describe_location, nil do
40 ChangesetCommentNotifier.with(:record => changeset_comment).deliver