From 344434cf446608fc67651bde5186176f5977d488 Mon Sep 17 00:00:00 2001 From: Satoshi Haramura Date: Sun, 10 Jul 2022 00:32:50 +0900 Subject: [PATCH 1/6] =?UTF-8?q?=E3=82=B5=E3=82=A4=E3=83=B3=E3=82=A2?= =?UTF-8?q?=E3=83=83=E3=83=97=E6=99=82=E3=81=AE=E3=82=B5=E3=82=A4=E3=83=88?= =?UTF-8?q?=E5=86=85=E9=80=9A=E7=9F=A5=E3=81=8A=E3=82=88=E3=81=B3=E3=83=A1?= =?UTF-8?q?=E3=83=BC=E3=83=AB=E9=80=9A=E7=9F=A5=E5=87=A6=E7=90=86=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 8 ++++++++ app/models/notification.rb | 3 ++- app/models/notification_facade.rb | 10 ++++++++++ app/notifiers/activity_notifier.rb | 15 +++++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 22fd0ad778e..3f4f23d3b2f 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -76,6 +76,7 @@ def target_allowlist def create_free_user! if @user.save UserMailer.welcome(@user).deliver_now + notify_to_mentors(@user) notify_to_chat(@user) redirect_to root_url, notice: 'サインアップメールをお送りしました。メールからサインアップを完了させてください。' else @@ -115,6 +116,7 @@ def create_user! if @user.save UserMailer.welcome(@user).deliver_now + notify_to_mentors(@user) notify_to_chat(@user) redirect_to root_url, notice: 'サインアップメールをお送りしました。メールからサインアップを完了させてください。' else @@ -124,6 +126,12 @@ def create_user! end # rubocop:enable Metrics/MethodLength, Metrics/BlockLength + def notify_to_mentors(user) + User.mentor.each do |mentor_user| + NotificationFacade.signed_up(user, mentor_user) + end + end + def notify_to_chat(user) ChatNotifier.message "#{user.name}さんが新たなメンバーとしてJOINしました🎉\r#{url_for(user)}" end diff --git a/app/models/notification.rb b/app/models/notification.rb index 64ceafb2700..01fc5b4cde9 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -35,7 +35,8 @@ class Notification < ApplicationRecord assigned_as_checker: 16, product_update: 17, graduated: 18, - hibernated: 19 + hibernated: 19, + signed_up: 20 } scope :unreads, -> { where(read: false) } diff --git a/app/models/notification_facade.rb b/app/models/notification_facade.rb index 76b2e08adda..ccf6ae2cf2a 100644 --- a/app/models/notification_facade.rb +++ b/app/models/notification_facade.rb @@ -210,4 +210,14 @@ def self.hibernated(sender, receiver) def self.tomorrow_regular_event(event) DiscordNotifier.with(event: event).tomorrow_regular_event.notify_now end + + def self.signed_up(sender, receiver) + ActivityNotifier.with(sender: sender, receiver: receiver).signed_up.notify_now + return unless receiver.mail_notification? && !receiver.retired? + + NotificationMailer.with( + sender: sender, + receiver: receiver + ).signed_up.deliver_later(wait: 5) + end end diff --git a/app/notifiers/activity_notifier.rb b/app/notifiers/activity_notifier.rb index 2b40b5dc90c..16cee0c5cd5 100644 --- a/app/notifiers/activity_notifier.rb +++ b/app/notifiers/activity_notifier.rb @@ -171,4 +171,19 @@ def hibernated(params = {}) read: false ) end + + def signed_up(params = {}) + params.merge!(@params) + sender = params[:sender] + receiver = params[:receiver] + + notification( + body: "🎉 #{sender.login_name}さんが新しく入会しました!", + kind: :signed_up, + sender: sender, + receiver: receiver, + link: Rails.application.routes.url_helpers.polymorphic_path(sender), + read: false + ) + end end From 6dd8a1c6599bc98bc4b0f316167dce6e310ff670 Mon Sep 17 00:00:00 2001 From: Satoshi Haramura Date: Sun, 10 Jul 2022 00:36:46 +0900 Subject: [PATCH 2/6] =?UTF-8?q?=E3=82=B5=E3=82=A4=E3=83=B3=E3=82=A2?= =?UTF-8?q?=E3=83=83=E3=83=97=E6=99=82=E3=81=AE=E3=83=A1=E3=83=BC=E3=83=AB?= =?UTF-8?q?=E3=81=AE=E6=96=87=E8=A8=80=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/mailers/notification_mailer.rb | 8 ++++++++ app/views/notification_mailer/signed_up.html.slim | 1 + 2 files changed, 9 insertions(+) create mode 100644 app/views/notification_mailer/signed_up.html.slim diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb index 8207710d199..71ca12fa576 100644 --- a/app/mailers/notification_mailer.rb +++ b/app/mailers/notification_mailer.rb @@ -176,4 +176,12 @@ def hibernated subject = "[FBC] #{@sender.login_name}さんが休会しました。" mail to: @user.email, subject: subject end + + # required params: sender, receiver + def signed_up + @user = @receiver + @notification = @user.notifications.find_by(link: "/users/#{@sender.id}", kind: Notification.kinds[:signed_up]) + subject = "[FBC] #{@sender.login_name}さんが新しく入会しました!" + mail to: @user.email, subject: subject + end end diff --git a/app/views/notification_mailer/signed_up.html.slim b/app/views/notification_mailer/signed_up.html.slim new file mode 100644 index 00000000000..ca46b34dc39 --- /dev/null +++ b/app/views/notification_mailer/signed_up.html.slim @@ -0,0 +1 @@ += render 'notification_mailer_template', title: "#{@sender.login_name}さんが新しく入会しました!", link_url: notification_url(@notification), link_text: "#{@sender.login_name}さんのページへ" From e33bed30ddf815c91baece11f4f2b9e667badf6f Mon Sep 17 00:00:00 2001 From: Satoshi Haramura Date: Fri, 15 Jul 2022 20:17:03 +0900 Subject: [PATCH 3/6] =?UTF-8?q?=E3=83=A1=E3=83=B3=E3=82=BF=E3=83=BC?= =?UTF-8?q?=E5=AE=9B=E3=81=A6=E3=81=AE=E3=82=B5=E3=82=A4=E3=83=88=E5=86=85?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E3=81=AE=E3=83=86=E3=82=B9=E3=83=88=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/notifiers/activity_notifier_test.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/notifiers/activity_notifier_test.rb b/test/notifiers/activity_notifier_test.rb index 7aad91d2173..5ba6d5ebf77 100644 --- a/test/notifiers/activity_notifier_test.rb +++ b/test/notifiers/activity_notifier_test.rb @@ -81,4 +81,16 @@ class ActivityNotifierTest < ActiveSupport::TestCase notification.notify_now end end + + test '#signed_up' do + notification = ActivityNotifier.with(sender: users(:hajime), receiver: users(:mentormentaro)).signed_up + + 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 end From 26a5b5bddf015e911a5c537cd1b42c0e61724dce Mon Sep 17 00:00:00 2001 From: Satoshi Haramura Date: Fri, 15 Jul 2022 20:18:35 +0900 Subject: [PATCH 4/6] =?UTF-8?q?=E3=83=A1=E3=83=B3=E3=82=BF=E3=83=BC?= =?UTF-8?q?=E5=AE=9B=E3=81=A6=E3=81=AE=E3=83=A1=E3=83=BC=E3=83=AB=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E3=81=AE=E3=83=86=E3=82=B9=E3=83=88=E3=82=92=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 ++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/mailers/notification_mailer_test.rb b/test/mailers/notification_mailer_test.rb index 70616c04900..b58dca0a7ec 100644 --- a/test/mailers/notification_mailer_test.rb +++ b/test/mailers/notification_mailer_test.rb @@ -356,4 +356,32 @@ class NotificationMailerTest < ActionMailer::TestCase assert_equal '[FBC] sotugyouさんが卒業しました。', email.subject assert_match(/卒業/, email.body.to_s) end + + test 'signed up' do + user = users(:hajime) + mentor = users(:mentormentaro) + Notification.create!( + kind: 20, + sender: user, + user: mentor, + message: '🎉 hajimeさんが新しく入会しました!', + link: "/users/#{user.id}", + read: false + ) + mailer = NotificationMailer.with( + sender: user, + receiver: mentor + ).signed_up + + 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] hajimeさんが新しく入会しました!', email.subject + assert_match(/入会/, email.body.to_s) + end end From 4eba9a86e1acb7d5f5ba492f0bc929fa1b14438e Mon Sep 17 00:00:00 2001 From: Satoshi Haramura Date: Fri, 12 Aug 2022 19:51:07 +0900 Subject: [PATCH 5/6] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E7=94=A8?= =?UTF-8?q?=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89=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/application_system_test_case.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb index a55ea2a901f..2bd680c0c9f 100644 --- a/test/application_system_test_case.rb +++ b/test/application_system_test_case.rb @@ -27,4 +27,14 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase teardown do ActionMailer::Base.deliveries.clear end + + def vcr_options + { + record: :once, + match_requests_on: [ + :method, + VCR.request_matchers.uri_without_param(:source) + ] + } + end end From 546ddfeb32fa11e1b502965311f17ed61d25231e Mon Sep 17 00:00:00 2001 From: Satoshi Haramura Date: Fri, 15 Jul 2022 20:53:39 +0900 Subject: [PATCH 6/6] =?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=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/signed_up_test.rb | 106 +++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 test/system/notification/signed_up_test.rb diff --git a/test/system/notification/signed_up_test.rb b/test/system/notification/signed_up_test.rb new file mode 100644 index 00000000000..626e805f2d4 --- /dev/null +++ b/test/system/notification/signed_up_test.rb @@ -0,0 +1,106 @@ +# frozen_string_literal: true + +require 'application_system_test_case' + +class Notification::SignedUpTest < ApplicationSystemTestCase + setup do + @delivery_mode = AbstractNotifier.delivery_mode + AbstractNotifier.delivery_mode = :normal + end + + teardown do + AbstractNotifier.delivery_mode = @delivery_mode + end + + test 'notify mentors when signed up as adviser' do + visit '/users/new?role=adviser' + + email = 'haruko@example.com' + + within 'form[name=user]' do + fill_in 'user[login_name]', with: 'haruko' + fill_in 'user[email]', with: email + fill_in 'user[name]', with: 'テスト 春子' + fill_in 'user[name_kana]', with: 'テスト ハルコ' + fill_in 'user[description]', with: 'テスト春子です。' + fill_in 'user[password]', with: 'testtest' + fill_in 'user[password_confirmation]', with: 'testtest' + find('label', text: 'アンチハラスメントポリシーに同意').click + find('label', text: '利用規約に同意').click + end + + click_button 'アドバイザー登録' + assert_text 'サインアップメールをお送りしました。メールからサインアップを完了させてください。' + assert User.find_by(email: email).adviser? + + visit_with_auth notifications_path, 'komagata' + within first('.card-list-item.is-unread') do + assert_selector '.card-list-item-title__link-label', text: '🎉 harukoさんが新しく入会しました!' + end + end + + test 'notify mentors when signed up as trainee' do + visit '/users/new?role=trainee' + + email = 'natsumi@example.com' + + within 'form[name=user]' do + fill_in 'user[login_name]', with: 'natsumi' + fill_in 'user[email]', with: email + fill_in 'user[name]', with: 'テスト 夏美' + fill_in 'user[name_kana]', with: 'テスト ナツミ' + fill_in 'user[description]', with: 'テスト夏美です。' + fill_in 'user[password]', with: 'testtest' + fill_in 'user[password_confirmation]', with: 'testtest' + select '学生', from: 'user[job]' + find('label', text: 'Mac(Apple チップ)').click + select '未経験', from: 'user[experience]' + first('.choices__inner').click + find('.choices__list--dropdown').click + find('.choices__list').click + find('#choices--js-choices-single-select-item-choice-2').click + find('label', text: 'アンチハラスメントポリシーに同意').click + find('label', text: '利用規約に同意').click + end + + click_button '参加する' + assert_text 'サインアップメールをお送りしました。メールからサインアップを完了させてください。' + assert User.find_by(email: email).trainee? + + visit_with_auth notifications_path, 'komagata' + within first('.card-list-item.is-unread') do + assert_selector '.card-list-item-title__link-label', text: '🎉 natsumiさんが新しく入会しました!' + end + end + + test 'notify mentors when signed up as normal user' do + visit '/users/new' + within 'form[name=user]' do + fill_in 'user[login_name]', with: 'taro' + fill_in 'user[email]', with: 'test@example.com' + fill_in 'user[name]', with: 'テスト 太郎' + fill_in 'user[name_kana]', with: 'テスト タロウ' + fill_in 'user[description]', with: 'テスト太郎です。' + fill_in 'user[password]', with: 'testtest' + fill_in 'user[password_confirmation]', with: 'testtest' + fill_in 'user[after_graduation_hope]', with: '起業したいです' + select '学生', from: 'user[job]' + find('label', text: 'Mac(Apple チップ)').click + select '未経験', from: 'user[experience]' + find('label', text: 'アンチハラスメントポリシーに同意').click + find('label', text: '利用規約に同意').click + end + + fill_stripe_element('4242 4242 4242 4242', '12 / 50', '111') + + VCR.use_cassette 'sign_up/valid-card', vcr_options do + click_button '参加する' + assert_text 'サインアップメールをお送りしました。メールからサインアップを完了させてください。' + end + + visit_with_auth notifications_path, 'komagata' + within first('.card-list-item.is-unread') do + assert_selector '.card-list-item-title__link-label', text: '🎉 taroさんが新しく入会しました!' + end + end +end