Skip to content

Commit

Permalink
activity_mailerのテスト
Browse files Browse the repository at this point in the history
  • Loading branch information
ogawa-tomo committed May 30, 2023
1 parent 866478a commit 63861eb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 28 deletions.
34 changes: 34 additions & 0 deletions test/mailers/activity_mailer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -822,4 +822,38 @@ class ActivityMailerTest < ActionMailer::TestCase
assert_equal '[FBC] hajimeさんがはじめての日報を書きました!', email.subject
assert_match(/はじめて/, email.body.to_s)
end

test 'no_correct_answer using synchronous mailer' do
question = questions(:question1)
receiver = question.user

ActivityMailer.no_correct_answer(question: question, receiver: receiver).deliver_now

assert_not ActionMailer::Base.deliveries.empty?
email = ActionMailer::Base.deliveries.last
query = CGI.escapeHTML({ kind: Notification.kinds[:no_correct_answer], link: "/questions/#{question.id}" }.to_param)
assert_equal ['noreply@bootcamp.fjord.jp'], email.from
assert_equal [receiver.email], email.to
assert_equal "[FBC] #{receiver.login_name}さんの質問【 #{question.title} 】のベストアンサーがまだ選ばれていません。", email.subject
assert_match(%r{<a .+ href="http://localhost:3000/notification/redirector\?#{query}">#{receiver.login_name}さんの質問へ</a>}, email.body.to_s)
end

test 'no_correct_answer with params using asynchronous mailer' do
question = questions(:question1)
receiver = question.user

mailer = ActivityMailer.with(question: question, receiver: receiver).no_correct_answer

perform_enqueued_jobs do
mailer.deliver_later
end

assert_not ActionMailer::Base.deliveries.empty?
email = ActionMailer::Base.deliveries.last
query = CGI.escapeHTML({ kind: Notification.kinds[:no_correct_answer], link: "/questions/#{question.id}" }.to_param)
assert_equal ['noreply@bootcamp.fjord.jp'], email.from
assert_equal [receiver.email], email.to
assert_equal "[FBC] #{receiver.login_name}さんの質問【 #{question.title} 】のベストアンサーがまだ選ばれていません。", email.subject
assert_match(%r{<a .+ href="http://localhost:3000/notification/redirector\?#{query}">#{receiver.login_name}さんの質問へ</a>}, email.body.to_s)
end
end
28 changes: 0 additions & 28 deletions test/mailers/notification_mailer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,32 +131,4 @@ class NotificationMailerTest < ActionMailer::TestCase
assert_equal '[FBC] 定期イベント【開発MTG】が更新されました。', email.subject
assert_match(/定期イベント/, email.body.to_s)
end

test 'no_correct_answer' do
user = users(:kimura)
question = questions(:question8)
Notification.create!(
kind: 22,
sender: user,
user: user,
message: 'Q&A「テストの質問」のベストアンサーがまだ選ばれていません。',
link: "/questions/#{question.id}",
read: false
)
mailer = NotificationMailer.with(
question: question,
receiver: user
).no_correct_answer

perform_enqueued_jobs do
mailer.deliver_later
end

assert_not ActionMailer::Base.deliveries.empty?
email = ActionMailer::Base.deliveries.last
assert_equal ['noreply@bootcamp.fjord.jp'], email.from
assert_equal ['kimura@fjord.jp'], email.to
assert_equal '[FBC] kimuraさんの質問【 テストの質問 】のベストアンサーがまだ選ばれていません。', email.subject
assert_match(/まだ選ばれていません/, email.body.to_s)
end
end

0 comments on commit 63861eb

Please sign in to comment.