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

日報が公開されたらDiscordの専用チャンネルに通知する機能の実装 #4325

Merged
merged 3 commits into from
Mar 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/models/report_callbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
26 changes: 26 additions & 0 deletions test/system/reports_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down