Skip to content

Commit

Permalink
通知関連のテストを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
monyatto committed Jul 28, 2023
1 parent 1934bdd commit 938d869
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/deliveries/activity_delivery_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -392,4 +392,27 @@ class ActivityDeliveryTest < ActiveSupport::TestCase
ActivityDelivery.with(**params).notify(:no_correct_answer)
end
end

test '.notify(:product_update)' do
params = {
product: products(:product1),
receiver: users(:komagata)
}

assert_difference -> { AbstractNotifier::Testing::Driver.deliveries.count }, 1 do
ActivityDelivery.notify!(:product_update, **params)
end

assert_difference -> { AbstractNotifier::Testing::Driver.enqueued_deliveries.count }, 1 do
ActivityDelivery.notify(:product_update, **params)
end

assert_difference -> { AbstractNotifier::Testing::Driver.deliveries.count }, 1 do
ActivityDelivery.with(**params).notify!(:product_update)
end

assert_difference -> { AbstractNotifier::Testing::Driver.enqueued_deliveries.count }, 1 do
ActivityDelivery.with(**params).notify(:product_update)
end
end
end
18 changes: 18 additions & 0 deletions test/mailers/activity_mailer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1023,4 +1023,22 @@ class ActivityMailerTest < ActionMailer::TestCase
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 'product_update' do
product = products(:product1)
receiver = users(:komagata)

ActivityMailer.product_update(
product: product,
receiver: receiver
).deliver_now

assert_not ActionMailer::Base.deliveries.empty?
email = ActionMailer::Base.deliveries.last
query = CGI.escapeHTML({ kind: 17, link: "/products/#{product.id}" }.to_param)
assert_equal ['[email protected]'], email.from
assert_equal ['[email protected]'], email.to
assert_equal '[FBC] mentormentaroさんが「OS X Mountain Lionをクリーンインストールする」の提出物を更新しました。', email.subject
assert_match(%r{<a .+ href="http://localhost:3000/notification/redirector\?#{query}">提出物へ</a>}, email.body.to_s)
end
end
7 changes: 7 additions & 0 deletions test/mailers/previews/notification_mailer_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,11 @@ def graduated

NotificationMailer.with(sender: sender, receiver: receiver).graduated
end

def product_update
product = Product.find(ActiveRecord::FixtureSet.identify(:product1))
receiver = User.find(ActiveRecord::FixtureSet.identify(:komagata))

NotificationMailer.with(product: product, receiver: receiver).product_update
end
end

0 comments on commit 938d869

Please sign in to comment.