Skip to content
Merged
8 changes: 7 additions & 1 deletion app/controllers/hibernation_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def create
if @hibernation.save
update_hibernated_at!
destroy_subscription!
notify_to_chat
notify_to_mentors_and_admins
logout
redirect_to hibernation_path
else
Expand All @@ -42,7 +44,11 @@ def destroy_subscription!

def notify_to_mentors_and_admins
User.admins_and_mentors.each do |admin_or_mentor|
NotificationFacade.retired(current_user, admin_or_mentor)
NotificationFacade.hibernated(current_user, admin_or_mentor)
end
end

def notify_to_chat
DiscordNotifier.with(sender: current_user).hibernated.notify_now
end
end
1 change: 0 additions & 1 deletion app/models/notification_facade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ def self.graduated(sender, receiver)

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

NotificationMailer.with(
Expand Down
28 changes: 28 additions & 0 deletions test/mailers/notification_mailer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -384,4 +384,32 @@ class NotificationMailerTest < ActionMailer::TestCase
assert_equal '[FBC] hajimeさんが新しく入会しました!', email.subject
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
end
12 changes: 12 additions & 0 deletions test/notifiers/activity_notifier_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ class ActivityNotifierTest < ActiveSupport::TestCase
end
end

test '#hibernated' do
notification = ActivityNotifier.with(sender: users(:kimura), receiver: users(:komagata)).hibernated

assert_difference -> { AbstractNotifier::Testing::Driver.deliveries.count }, 1 do
notification.notify_now
end

assert_difference -> { AbstractNotifier::Testing::Driver.enqueued_deliveries.count }, 1 do
notification.notify_later
end
end

test '#retired' do
notification = ActivityNotifier.with(sender: users(:kimura), receiver: users(:komagata)).retired

Expand Down
25 changes: 25 additions & 0 deletions test/notifiers/discord_notifier_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,29 @@ class DiscordNotifierTest < ActiveSupport::TestCase
DiscordNotifier.with(params).invalid_user.notify_later
end
end

test '.hibernated' do
params = {
body: 'test message',
sender: users(:kimura),
name: 'bob',
webhook_url: 'https://discord.com/api/webhooks/0123456789/xxxxxxxx'
}

expected = {
body: 'kimuraさんが休会しました。',
name: 'ピヨルド',
webhook_url: 'https://discord.com/api/webhooks/0123456789/xxxxxxxx'
}

assert_notifications_sent 2, **expected do
DiscordNotifier.hibernated(params).notify_now
DiscordNotifier.with(params).hibernated.notify_now
end

assert_notifications_enqueued 2, **expected do
DiscordNotifier.hibernated(params).notify_later
DiscordNotifier.with(params).hibernated.notify_later
end
end
end
2 changes: 1 addition & 1 deletion test/system/current_user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class CurrentUserTest < ApplicationSystemTestCase
visit_with_auth '/current_user/edit', 'komagata'
fill_in 'user[times_url]', with: 'https://example.com/channels/1234/5678/'
click_button '更新する'
assert_text '分報チャンネル URL は Discord のチャンネル URL を入力してください'
assert_text '分報チャンネル URLはDiscordのチャンネルURLを入力してください'
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

今回のissueとは関係がありませんが、テストを通すため修正しました

end

test 'Do not show after graduation hope when advisor' do
Expand Down
80 changes: 80 additions & 0 deletions test/system/notification/hibernation_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# frozen_string_literal: true

require 'application_system_test_case'

class Notification::HibernationTest < ApplicationSystemTestCase
setup do
@delivery_mode = AbstractNotifier.delivery_mode
AbstractNotifier.delivery_mode = :normal
end

teardown do
AbstractNotifier.delivery_mode = @delivery_mode
end

test 'notify admins and mentors when a student hibernate' do
visit_with_auth notifications_path, 'komagata'
find('#notifications.loaded', wait: 10)
within first('.card-list-item') do
assert_no_selector '.card-list-item-title__link-label', text: 'kimuraさんが休会しました。'
end

visit_with_auth new_hibernation_path, 'kimura'
fill_in 'hibernation[scheduled_return_on]', with: Time.current.next_month
fill_in 'hibernation[reason]', with: 'テストのため'
accept_confirm do
click_button '休会する'
end
assert_text '休会処理が完了しました'

visit_with_auth notifications_path, 'komagata'
find('#notifications.loaded', wait: 10)
within first('.card-list-item.is-unread') do
assert_selector '.card-list-item-title__link-label', text: 'kimuraさんが休会しました。'
end
end

test 'notify admins and mentors when a trainee hibernate' do
visit_with_auth notifications_path, 'komagata'
find('#notifications.loaded', wait: 10)
within first('.card-list-item') do
assert_no_selector '.card-list-item-title__link-label', text: 'kensyuさんが休会しました。'
end

visit_with_auth new_hibernation_path, 'kensyu'
fill_in 'hibernation[scheduled_return_on]', with: Time.current.next_month
fill_in 'hibernation[reason]', with: 'テストのため'
accept_confirm do
click_button '休会する'
end
assert_text '休会処理が完了しました'

visit_with_auth notifications_path, 'komagata'
find('#notifications.loaded', wait: 10)
within first('.card-list-item.is-unread') do
assert_selector '.card-list-item-title__link-label', text: 'kensyuさんが休会しました。'
end
end

test 'notify admins and mentors when a adviser hibernate' do
visit_with_auth notifications_path, 'komagata'
find('#notifications.loaded', wait: 10)
within first('.card-list-item') do
assert_no_selector '.card-list-item-title__link-label', text: 'senpaiさんが休会しました。'
end

visit_with_auth new_hibernation_path, 'senpai'
fill_in 'hibernation[scheduled_return_on]', with: Time.current.next_month
fill_in 'hibernation[reason]', with: 'テストのため'
accept_confirm do
click_button '休会する'
end
assert_text '休会処理が完了しました'

visit_with_auth notifications_path, 'komagata'
find('#notifications.loaded', wait: 10)
within first('.card-list-item.is-unread') do
assert_selector '.card-list-item-title__link-label', text: 'senpaiさんが休会しました。'
end
end
end