FIX: Topic changing category was not triggering notifications (#244)

We moved `category_changed` notification to be a `whisper` but we forgot to update the check in `manager.rb` to verify not for a `small_post` but for a whisper.

Added a test to cover this case.
This commit is contained in:
Gabriel Grubba 2025-01-16 15:33:49 -03:00 committed by GitHub
parent f0cac677c2
commit 8498d88ccb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 38 additions and 2 deletions

View File

@ -15,10 +15,10 @@ module DiscourseChatIntegration
# Abort if the post is blank
return if post.blank?
# Abort if post is not either regular or a 'category_changed' small action
# Abort if post is not either regular or a 'category_changed' whisper
if (post.post_type != Post.types[:regular]) &&
!(
post.post_type == Post.types[:small_action] &&
post.post_type == Post.types[:whisper] &&
%w[category_changed].include?(post.action_code)
)
return

View File

@ -346,5 +346,41 @@ RSpec.describe DiscourseChatIntegration::Manager do
expect(provider.sent_to_channel_ids).to contain_exactly(chan1.id)
end
end
describe "with whispers and actions enabled" do
before do
SiteSetting.create_post_for_category_and_tag_changes = true
SiteSetting.whispers_allowed_groups = "#{Group::AUTO_GROUPS[:staff]}"
end
it "should notify about category changes" do
DiscourseChatIntegration::Rule.create!(
channel: chan1,
filter: "watch",
category_id: category.id,
)
new_category = Fabricate(:category)
DiscourseChatIntegration::Rule.create!(
channel: chan1,
filter: "watch",
category_id: new_category.id,
)
manager.trigger_notifications(first_post.id)
expect(provider.sent_to_channel_ids).to contain_exactly(chan1.id)
# Change category
PostRevisor.new(first_post, topic).revise!(
Discourse.system_user,
category_id: new_category.id,
)
last_topic_post = topic.posts.last
manager.trigger_notifications(last_topic_post.id)
expect(provider.sent_messages.count).to eq(2)
expect(provider.sent_messages.last).to eq(post: last_topic_post.id, channel: chan1)
end
end
end
end