diff --git a/app/models/report_callbacks.rb b/app/models/report_callbacks.rb index f58921542ef..ece61720cfc 100644 --- a/app/models/report_callbacks.rb +++ b/app/models/report_callbacks.rb @@ -11,6 +11,7 @@ def after_save(report) report.update_column(:published_at, report.updated_at) # rubocop:disable Rails/SkipsModelValidations notify_users(report) + notify_to_chat(report) end def after_create(report) @@ -74,4 +75,12 @@ def create_following_watch(report, follower) def delete_notification(report) Notification.where(link: "/reports/#{report.id}").destroy_all end + + def notify_to_chat(report) + ChatNotifier.message(<<~TEXT, webhook_url: ENV['DISCORD_REPORT_WEBHOOK_URL']) + #{report.user.login_name}さんが#{I18n.l report.reported_on}の日報を公開しました。 + タイトル:「#{report.title}」 + URL: https://bootcamp.fjord.jp/reports/#{report.id} + TEXT + end end diff --git a/test/system/reports_test.rb b/test/system/reports_test.rb index f38f3eb7e3b..eff8adbbb16 100644 --- a/test/system/reports_test.rb +++ b/test/system/reports_test.rb @@ -635,4 +635,30 @@ def wait_for_watch_change visit_with_auth report_path(reports(:report32)), 'komagata' assert_no_selector '.a-page-notice.is-only-mentor.is-danger', text: '9日ぶりの日報です' end + + test 'notify to chat after create a report' do + visit_with_auth '/reports/new', 'kimura' + within('form[name=report]') do + fill_in('report[title]', with: 'test title') + fill_in('report[description]', with: 'test') + fill_in('report[reported_on]', with: Time.current) + end + + first('.learning-time').all('.learning-time__started-at select')[0].select('07') + first('.learning-time').all('.learning-time__started-at select')[1].select('30') + first('.learning-time').all('.learning-time__finished-at select')[0].select('08') + first('.learning-time').all('.learning-time__finished-at select')[1].select('30') + + mock_log = [] + stub_info = proc { |i| mock_log << i } + + Rails.logger.stub(:info, stub_info) do + click_button '提出' + end + + assert_text '日報を保存しました。' + assert_text Time.current.strftime('%Y年%m月%d日') + assert_text 'Watch中' + assert_match 'Message to Discord.', mock_log.to_s + end end diff --git a/test/test_helper.rb b/test/test_helper.rb index b06cfc13fd5..d23aa74969b 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -4,6 +4,7 @@ require_relative '../config/environment' require 'rails/test_help' require 'capybara/rails' +require 'minitest/mock' require 'minitest/retry' require 'supports/api_helper' require 'supports/vcr_helper'