From 64dfbb60fdf59879dd8f43277b331ab9ec88c471 Mon Sep 17 00:00:00 2001 From: keiz1213 Date: Mon, 29 Aug 2022 22:52:38 +0900 Subject: [PATCH 01/10] =?UTF-8?q?=E3=83=A6=E3=83=BC=E3=82=B6=E3=83=BC?= =?UTF-8?q?=E3=81=8C=E4=BC=91=E4=BC=9A=E3=81=97=E3=81=9F=E6=99=82=E3=81=AB?= =?UTF-8?q?=E3=83=A1=E3=83=B3=E3=82=BF=E3=83=BC=E3=81=A8=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E8=80=85=E3=81=AB=E3=82=B5=E3=82=A4=E3=83=88=E5=86=85=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E3=81=A8=E3=83=A1=E3=83=BC=E3=83=AB=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E3=81=8C=E8=A1=8C=E3=81=8F=E3=82=88=E3=81=86=E3=81=AB=E3=81=97?= =?UTF-8?q?=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/hibernation_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/hibernation_controller.rb b/app/controllers/hibernation_controller.rb index f32db28dae0..54762be9413 100644 --- a/app/controllers/hibernation_controller.rb +++ b/app/controllers/hibernation_controller.rb @@ -16,6 +16,7 @@ def create if @hibernation.save update_hibernated_at! destroy_subscription! + notify_to_mentors_and_admins logout redirect_to hibernation_path else @@ -42,7 +43,7 @@ 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 end From 93b2c6ff5155ba20152ee595b5332fb0804c5e71 Mon Sep 17 00:00:00 2001 From: keiz1213 Date: Fri, 2 Sep 2022 08:00:47 +0900 Subject: [PATCH 02/10] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/mailers/notification_mailer_test.rb | 28 ++++++++++++++++ test/notifiers/activity_notifier_test.rb | 12 +++++++ test/system/notification/hibernation_test.rb | 35 ++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 test/system/notification/hibernation_test.rb diff --git a/test/mailers/notification_mailer_test.rb b/test/mailers/notification_mailer_test.rb index b58dca0a7ec..f5fcf0a7924 100644 --- a/test/mailers/notification_mailer_test.rb +++ b/test/mailers/notification_mailer_test.rb @@ -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 ['mentormentaro@fjord.jp'], email.to + assert_equal '[FBC] kimuraさんが休会しました。', email.subject + assert_match(/休会/, email.body.to_s) + end end diff --git a/test/notifiers/activity_notifier_test.rb b/test/notifiers/activity_notifier_test.rb index 5ba6d5ebf77..fc3c0e39176 100644 --- a/test/notifiers/activity_notifier_test.rb +++ b/test/notifiers/activity_notifier_test.rb @@ -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.deliveries.count }, 1 do + notification.notify_later + end + end + test '#retired' do notification = ActivityNotifier.with(sender: users(:kimura), receiver: users(:komagata)).retired diff --git a/test/system/notification/hibernation_test.rb b/test/system/notification/hibernation_test.rb new file mode 100644 index 00000000000..e28b6506a5c --- /dev/null +++ b/test/system/notification/hibernation_test.rb @@ -0,0 +1,35 @@ +# 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 user 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: 'テストのため' + click_button '休会する' + page.driver.browser.switch_to.alert.accept + 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 +end From 1632dbc7ff94d2997a5bd3ae5d5b73d312c027de Mon Sep 17 00:00:00 2001 From: keiz1213 Date: Sat, 3 Sep 2022 15:30:30 +0900 Subject: [PATCH 03/10] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/mailers/notification_mailer_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/mailers/notification_mailer_test.rb b/test/mailers/notification_mailer_test.rb index f5fcf0a7924..6eb35fbd9fa 100644 --- a/test/mailers/notification_mailer_test.rb +++ b/test/mailers/notification_mailer_test.rb @@ -408,7 +408,7 @@ class NotificationMailerTest < ActionMailer::TestCase assert_not ActionMailer::Base.deliveries.empty? email = ActionMailer::Base.deliveries.last assert_equal ['noreply@bootcamp.fjord.jp'], email.from - assert_equal ['mentormentaro@fjord.jp'], email.to + assert_equal ['komagata@fjord.jp'], email.to assert_equal '[FBC] kimuraさんが休会しました。', email.subject assert_match(/休会/, email.body.to_s) end From f2998ca8a303eeff330bbb1d7b0fba3a4f5a462e Mon Sep 17 00:00:00 2001 From: keiz1213 Date: Sun, 4 Sep 2022 10:39:53 +0900 Subject: [PATCH 04/10] =?UTF-8?q?=E7=A0=94=E4=BF=AE=E7=94=9F=E3=81=A8?= =?UTF-8?q?=E3=82=A2=E3=83=89=E3=83=90=E3=82=A4=E3=82=B6=E3=83=BC=E3=81=AE?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=82=B7=E3=83=8A=E3=83=AA=E3=82=AA?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/system/notification/hibernation_test.rb | 44 +++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/test/system/notification/hibernation_test.rb b/test/system/notification/hibernation_test.rb index e28b6506a5c..da79f34185b 100644 --- a/test/system/notification/hibernation_test.rb +++ b/test/system/notification/hibernation_test.rb @@ -12,7 +12,7 @@ class Notification::HibernationTest < ApplicationSystemTestCase AbstractNotifier.delivery_mode = @delivery_mode end - test 'notify admins and mentors when a user hibernate' do + 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 @@ -32,4 +32,46 @@ class Notification::HibernationTest < ApplicationSystemTestCase 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: 'テストのため' + click_button '休会する' + page.driver.browser.switch_to.alert.accept + 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: 'テストのため' + click_button '休会する' + page.driver.browser.switch_to.alert.accept + 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 From cc888f7a87bfb602bc9492b03a359ad7d3a2c7cb Mon Sep 17 00:00:00 2001 From: keiz1213 Date: Sun, 11 Sep 2022 12:08:50 +0900 Subject: [PATCH 05/10] =?UTF-8?q?DiscordNotifier=E3=82=92NotificationFacad?= =?UTF-8?q?e=E3=81=AEhibernated=E3=81=8B=E3=82=89=E5=88=86=E9=9B=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 分離せずにNotificationFacade経由で呼び出すと同じ通知が複数回discordに飛ぶため --- app/controllers/hibernation_controller.rb | 5 +++++ app/models/notification_facade.rb | 1 - 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/controllers/hibernation_controller.rb b/app/controllers/hibernation_controller.rb index 54762be9413..f03d99f0609 100644 --- a/app/controllers/hibernation_controller.rb +++ b/app/controllers/hibernation_controller.rb @@ -16,6 +16,7 @@ def create if @hibernation.save update_hibernated_at! destroy_subscription! + notify_to_chat notify_to_mentors_and_admins logout redirect_to hibernation_path @@ -46,4 +47,8 @@ def notify_to_mentors_and_admins NotificationFacade.hibernated(current_user, admin_or_mentor) end end + + def notify_to_chat + DiscordNotifier.with(sender: current_user).hibernated.notify_now + end end diff --git a/app/models/notification_facade.rb b/app/models/notification_facade.rb index e5cabbc1190..d3ae715db1d 100644 --- a/app/models/notification_facade.rb +++ b/app/models/notification_facade.rb @@ -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( From 269ceb1a15f2cbd07e4c218110471b85ac7c9975 Mon Sep 17 00:00:00 2001 From: keiz1213 Date: Mon, 12 Sep 2022 14:29:03 +0900 Subject: [PATCH 06/10] =?UTF-8?q?activity=5Fnotifier=E3=81=AE=E9=9D=9E?= =?UTF-8?q?=E5=90=8C=E6=9C=9F=E9=80=9A=E7=9F=A5=E3=81=AE=E3=83=86=E3=82=B9?= =?UTF-8?q?=E3=83=88=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/notifiers/activity_notifier_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/notifiers/activity_notifier_test.rb b/test/notifiers/activity_notifier_test.rb index fc3c0e39176..8b8ef368b9f 100644 --- a/test/notifiers/activity_notifier_test.rb +++ b/test/notifiers/activity_notifier_test.rb @@ -81,7 +81,7 @@ class ActivityNotifierTest < ActiveSupport::TestCase notification.notify_now end - assert_difference -> { AbstractNotifier::Testing::Driver.deliveries.count }, 1 do + assert_difference -> { AbstractNotifier::Testing::Driver.enqueued_deliveries.count }, 1 do notification.notify_later end end From 90ba6b566a44afb8a2eb52a236bb29747e5d5c95 Mon Sep 17 00:00:00 2001 From: keiz1213 Date: Mon, 12 Sep 2022 15:41:45 +0900 Subject: [PATCH 07/10] =?UTF-8?q?=E3=82=A8=E3=83=A9=E3=83=BC=E3=83=A1?= =?UTF-8?q?=E3=83=83=E3=82=BB=E3=83=BC=E3=82=B8=E3=81=AE=E4=B8=8D=E8=A6=81?= =?UTF-8?q?=E3=81=AA=E3=82=B9=E3=83=9A=E3=83=BC=E3=82=B9=E3=82=92=E5=89=8A?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/system/current_user_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/system/current_user_test.rb b/test/system/current_user_test.rb index 30c3a5e4d7f..180c4000fbc 100644 --- a/test/system/current_user_test.rb +++ b/test/system/current_user_test.rb @@ -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を入力してください' end test 'Do not show after graduation hope when advisor' do From f12032f5a52c070dfe23b46644f6b479e67366db Mon Sep 17 00:00:00 2001 From: keiz1213 Date: Mon, 12 Sep 2022 16:06:12 +0900 Subject: [PATCH 08/10] =?UTF-8?q?discord=E9=80=9A=E7=9F=A5=E3=81=AE?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/notifiers/discord_notifier_test.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/notifiers/discord_notifier_test.rb b/test/notifiers/discord_notifier_test.rb index e2beb3dc65d..b10853193ee 100644 --- a/test/notifiers/discord_notifier_test.rb +++ b/test/notifiers/discord_notifier_test.rb @@ -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 From 013ff46abd5bdd08ffe905ead72d1694c1b0727a Mon Sep 17 00:00:00 2001 From: keiz1213 Date: Tue, 13 Sep 2022 21:35:12 +0900 Subject: [PATCH 09/10] =?UTF-8?q?=E3=82=B7=E3=82=B9=E3=83=86=E3=83=A0?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=81=AE=E4=B8=8D=E8=A6=81=E3=81=AA?= =?UTF-8?q?=E3=82=B9=E3=83=9A=E3=83=BC=E3=82=B9=E3=81=AE=E5=89=8A=E9=99=A4?= =?UTF-8?q?=E3=81=A8accept=5Fconfirm=E3=81=AE=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/system/notification/hibernation_test.rb | 21 +++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/test/system/notification/hibernation_test.rb b/test/system/notification/hibernation_test.rb index da79f34185b..81ba2a5a22b 100644 --- a/test/system/notification/hibernation_test.rb +++ b/test/system/notification/hibernation_test.rb @@ -16,14 +16,15 @@ class Notification::HibernationTest < ApplicationSystemTestCase 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さんが休会しました。' + 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: 'テストのため' - click_button '休会する' - page.driver.browser.switch_to.alert.accept + accept_confirm do + click_button '休会する' + end assert_text '休会処理が完了しました' visit_with_auth notifications_path, 'komagata' @@ -37,14 +38,15 @@ class Notification::HibernationTest < ApplicationSystemTestCase 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さんが休会しました。' + 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: 'テストのため' - click_button '休会する' - page.driver.browser.switch_to.alert.accept + accept_confirm do + click_button '休会する' + end assert_text '休会処理が完了しました' visit_with_auth notifications_path, 'komagata' @@ -58,14 +60,15 @@ class Notification::HibernationTest < ApplicationSystemTestCase 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さんが休会しました。' + 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: 'テストのため' - click_button '休会する' - page.driver.browser.switch_to.alert.accept + accept_confirm do + click_button '休会する' + end assert_text '休会処理が完了しました' visit_with_auth notifications_path, 'komagata' From 8cd9e74239f41774448dac245453eee142b16e7e Mon Sep 17 00:00:00 2001 From: keiz1213 Date: Tue, 13 Sep 2022 21:49:17 +0900 Subject: [PATCH 10/10] =?UTF-8?q?lint=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/system/notification/hibernation_test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/system/notification/hibernation_test.rb b/test/system/notification/hibernation_test.rb index 81ba2a5a22b..37d03a3eb9f 100644 --- a/test/system/notification/hibernation_test.rb +++ b/test/system/notification/hibernation_test.rb @@ -24,7 +24,7 @@ class Notification::HibernationTest < ApplicationSystemTestCase fill_in 'hibernation[reason]', with: 'テストのため' accept_confirm do click_button '休会する' - end + end assert_text '休会処理が完了しました' visit_with_auth notifications_path, 'komagata' @@ -46,7 +46,7 @@ class Notification::HibernationTest < ApplicationSystemTestCase fill_in 'hibernation[reason]', with: 'テストのため' accept_confirm do click_button '休会する' - end + end assert_text '休会処理が完了しました' visit_with_auth notifications_path, 'komagata' @@ -68,7 +68,7 @@ class Notification::HibernationTest < ApplicationSystemTestCase fill_in 'hibernation[reason]', with: 'テストのため' accept_confirm do click_button '休会する' - end + end assert_text '休会処理が完了しました' visit_with_auth notifications_path, 'komagata'