Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

休会通知をactive_delivery化する #6506

Merged
merged 7 commits into from
May 17, 2023
2 changes: 1 addition & 1 deletion app/controllers/hibernation_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def destroy_subscription!

def notify_to_mentors_and_admins
User.admins_and_mentors.each do |admin_or_mentor|
NotificationFacade.hibernated(current_user, admin_or_mentor)
ActivityDelivery.with(sender: current_user, receiver: admin_or_mentor).notify(:hibernated)
end
end

Expand Down
18 changes: 18 additions & 0 deletions app/mailers/activity_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,22 @@ def assigned_as_checker(args = {})

message
end

# required params: sender, receiver
def hibernated(args = {})
@sender ||= args[:sender]
@receiver ||= args[:receiver]

@user = @receiver
@link_url = notification_redirector_url(
link: "/users/#{@sender.id}",
kind: Notification.kinds[:hibernated]
)

subject = "[FBC] #{@sender.login_name}さんが休会しました。"
message = mail to: @user.email, subject: subject
message.perform_deliveries = @user.mail_notification? && !@user.retired?

message
end
end
10 changes: 1 addition & 9 deletions app/mailers/notification_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class NotificationMailer < ApplicationMailer # rubocop:disable Metrics/ClassLength
class NotificationMailer < ApplicationMailer
helper ApplicationHelper

before_action do
Expand Down Expand Up @@ -101,14 +101,6 @@ def consecutive_sad_report
subject: "[FBC] #{@report.user.login_name}さんが#{User::DEPRESSED_SIZE}回連続でsadアイコンの日報を提出しました。"
end

# required params: sender, receiver
def hibernated
@user = @receiver
@notification = @user.notifications.find_by(link: "/users/#{@sender.id}", kind: Notification.kinds[:hibernated])
subject = "[FBC] #{@sender.login_name}さんが休会しました。"
mail to: @user.email, subject: subject
end

# required params: sender, receiver
def signed_up
@user = @receiver
Expand Down
10 changes: 0 additions & 10 deletions app/models/notification_facade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,6 @@ def self.consecutive_sad_report(report, receiver)
).consecutive_sad_report.deliver_later(wait: 5)
end

def self.hibernated(sender, receiver)
ActivityNotifier.with(sender: sender, receiver: receiver).hibernated.notify_now
return unless receiver.mail_notification?

NotificationMailer.with(
sender: sender,
receiver: receiver
).hibernated.deliver_later(wait: 5)
end

def self.tomorrow_regular_event(event)
DiscordNotifier.with(event: event).tomorrow_regular_event.notify_now
end
Expand Down
1 change: 1 addition & 0 deletions app/views/activity_mailer/hibernated.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
= render '/notification_mailer/notification_mailer_template', title: "#{@sender.login_name}さんが休会しました。", link_url: @link_url, link_text: "#{@sender.login_name}さんのページへ" do
1 change: 0 additions & 1 deletion app/views/notification_mailer/hibernated.html.slim

This file was deleted.

24 changes: 24 additions & 0 deletions test/deliveries/activity_delivery_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,28 @@ class ActivityDeliveryTest < ActiveSupport::TestCase
ActivityDelivery.with(**params).notify(:assigned_as_checker)
end
end

test '.notify(:hibernated)' do
user = hibernations(:hibernation1).user
params = {
sender: user,
receiver: users(:komagata)
}

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

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

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

assert_difference -> { AbstractNotifier::Testing::Driver.enqueued_deliveries.count }, 1 do
ActivityDelivery.with(**params).notify(:hibernated)
end
end
end
28 changes: 28 additions & 0 deletions test/mailers/activity_mailer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -696,4 +696,32 @@ class ActivityMailerTest < ActionMailer::TestCase
).deliver_now
assert_not ActionMailer::Base.deliveries.empty?
end

test 'hibernated' do
user = users(:kimura)
mentor = users(:komagata)
Notification.create!(
kind: 19,
sender: user,
user: mentor,
message: 'kimuraさんが休会しました。',
link: "/users/#{user.id}",
read: false
)
mailer = ActivityMailer.with(
sender: user,
receiver: mentor
).hibernated

perform_enqueued_jobs do
mailer.deliver_later
Copy link
Contributor

@toke04 toke04 May 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

こちらのテストの同期版も実装されると、さらに良いと思いました😊
deliver_now を使うテストもあった方が良い、という意味になります🙇‍♂️

test 'moved_up_event_waiting_user' do

[ 私のサンプルコード]

test 'moved_up_event_waiting_user' do
    event = events(:event3)
    notification = notifications(:notification_moved_up_event_waiting_user)
    ActivityMailer.moved_up_event_waiting_user(
      receiver: notification.user,
      event: event
    ).deliver_now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ご連絡遅くなりました💦
ご指摘のとおりだと思いますのでテスト追加してみます💪

end

assert_not ActionMailer::Base.deliveries.empty?
email = ActionMailer::Base.deliveries.last
assert_equal ['noreply@bootcamp.fjord.jp'], email.from
assert_equal ['komagata@fjord.jp'], email.to
assert_equal '[FBC] kimuraさんが休会しました。', email.subject
assert_match(/休会/, 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 @@ -152,34 +152,6 @@ class NotificationMailerTest < ActionMailer::TestCase
assert_match(/入会/, email.body.to_s)
end

test 'hibernated' do
user = users(:kimura)
mentor = users(:komagata)
Notification.create!(
kind: 19,
sender: user,
user: mentor,
message: 'kimuraさんが休会しました。',
link: "/users/#{user.id}",
read: false
)
mailer = NotificationMailer.with(
sender: user,
receiver: mentor
).hibernated

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 ['komagata@fjord.jp'], email.to
assert_equal '[FBC] kimuraさんが休会しました。', email.subject
assert_match(/休会/, email.body.to_s)
end

test 'update_regular_event' do
regular_event = regular_events(:regular_event1)
notification = notifications(:notification_regular_event_updated)
Expand Down
7 changes: 7 additions & 0 deletions test/mailers/previews/activity_mailer_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,11 @@ def assigned_as_checker

ActivityMailer.with(product: product, receiver: receiver).assigned_as_checker
end

def hibernated
sender = User.find(ActiveRecord::FixtureSet.identify(:hatsuno))
receiver = User.find(ActiveRecord::FixtureSet.identify(:mentormentaro))

ActivityMailer.with(sender: sender, receiver: receiver).hibernated
end
end
7 changes: 0 additions & 7 deletions test/mailers/previews/notification_mailer_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,6 @@ def graduated
NotificationMailer.with(sender: sender, receiver: receiver).graduated
end

def hibernated
sender = User.find(ActiveRecord::FixtureSet.identify(:hatsuno))
receiver = User.find(ActiveRecord::FixtureSet.identify(:mentormentaro))

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

def update_regular_event
regular_event = RegularEvent.find(ActiveRecord::FixtureSet.identify(:regular_event1))
receiver = User.find(ActiveRecord::FixtureSet.identify(:hatsuno))
Expand Down