discourse-chat-integration/spec/integration/automation_spec.rb

89 lines
2.8 KiB
Ruby
Raw Normal View History

Feature: add chat integration reference post (#216) * FEATURE: Add chat integration reference post This class works similar to a post but it is not a post. * DEV: change how `excerpt` method works * feature: Add `send_chat_integration_message` scriptable add `send_chat_integration_message` scriptable that uses the rules to send a message to the chat provider add locale strings for the new scriptable update `ChatIntegrationReferencePost` `excerpt` method add tests for `ChatIntegrationReferencePost` * DEV: Add `get_channel_by_name` to every provider This makes using `trigger_notification` easier with every provider as well. * DEV: Add `get_channel_name` to all providers This method gets the name of the channel based on how the provider identifies it. Updates channel_name in locales yaml Adds migrate_tag_added_filter_to_all_providers.rb to move all existing rules to use Automation * DEV: Add removal of old migration data Update small action locales with strings from core * DEV: solve review comments * DEV: update test locale strings * DEV: remove empty line to trigger lint * DEV: lint applied * DEV: Add tests for automation integration * DEV: add rails logger for when automatio error occurs * DEV: move migration to be SQL only Update provider helper to use hashes instead of dot notation * DEV: update migration with correct table names * DEV: Update migrate_tag_added_filter_to_all_providers to use smaller SQL queries Commented out migrate_tag_added_from_filter_to_automation.rb * DEV: update comments in migration file * DEV: update indentation in client.en.yml * DEV: update with review comments * Update spec/lib/discourse_chat_integration/chat_integration_reference_post_spec.rb Co-authored-by: Jarek Radosz <jradosz@gmail.com> * Update spec/lib/discourse_chat_integration/chat_integration_reference_post_spec.rb Co-authored-by: Jarek Radosz <jradosz@gmail.com> * Update spec/lib/discourse_chat_integration/chat_integration_reference_post_spec.rb Co-authored-by: Jarek Radosz <jradosz@gmail.com> * Update spec/integration/automation_spec.rb Co-authored-by: Jarek Radosz <jradosz@gmail.com> * Update lib/discourse_chat_integration/chat_integration_reference_post.rb Co-authored-by: Jarek Radosz <jradosz@gmail.com> * DEV: update specs with review comments * DEV: update typos in tests * DEV: inlined functions for getting channel name for provider in migration --------- Co-authored-by: Jarek Radosz <jradosz@gmail.com>
2024-09-11 09:42:52 -04:00
# frozen_string_literal: true
require_relative "../dummy_provider"
RSpec.describe "Triggering notifications" do
include_context "with validated dummy provider"
context "with automation installed", if: defined?(DiscourseAutomation) do
fab!(:admin)
fab!(:category)
fab!(:tag)
let(:valid_attrs) { Fabricate.attributes_for(:topic) }
Feature: add chat integration reference post (#216) * FEATURE: Add chat integration reference post This class works similar to a post but it is not a post. * DEV: change how `excerpt` method works * feature: Add `send_chat_integration_message` scriptable add `send_chat_integration_message` scriptable that uses the rules to send a message to the chat provider add locale strings for the new scriptable update `ChatIntegrationReferencePost` `excerpt` method add tests for `ChatIntegrationReferencePost` * DEV: Add `get_channel_by_name` to every provider This makes using `trigger_notification` easier with every provider as well. * DEV: Add `get_channel_name` to all providers This method gets the name of the channel based on how the provider identifies it. Updates channel_name in locales yaml Adds migrate_tag_added_filter_to_all_providers.rb to move all existing rules to use Automation * DEV: Add removal of old migration data Update small action locales with strings from core * DEV: solve review comments * DEV: update test locale strings * DEV: remove empty line to trigger lint * DEV: lint applied * DEV: Add tests for automation integration * DEV: add rails logger for when automatio error occurs * DEV: move migration to be SQL only Update provider helper to use hashes instead of dot notation * DEV: update migration with correct table names * DEV: Update migrate_tag_added_filter_to_all_providers to use smaller SQL queries Commented out migrate_tag_added_from_filter_to_automation.rb * DEV: update comments in migration file * DEV: update indentation in client.en.yml * DEV: update with review comments * Update spec/lib/discourse_chat_integration/chat_integration_reference_post_spec.rb Co-authored-by: Jarek Radosz <jradosz@gmail.com> * Update spec/lib/discourse_chat_integration/chat_integration_reference_post_spec.rb Co-authored-by: Jarek Radosz <jradosz@gmail.com> * Update spec/lib/discourse_chat_integration/chat_integration_reference_post_spec.rb Co-authored-by: Jarek Radosz <jradosz@gmail.com> * Update spec/integration/automation_spec.rb Co-authored-by: Jarek Radosz <jradosz@gmail.com> * Update lib/discourse_chat_integration/chat_integration_reference_post.rb Co-authored-by: Jarek Radosz <jradosz@gmail.com> * DEV: update specs with review comments * DEV: update typos in tests * DEV: inlined functions for getting channel name for provider in migration --------- Co-authored-by: Jarek Radosz <jradosz@gmail.com>
2024-09-11 09:42:52 -04:00
fab!(:automation) do
Fabricate(
:automation,
script: "send_chat_integration_message",
trigger: "topic_tags_changed",
enabled: true,
)
end
let(:channel1) do
DiscourseChatIntegration::Channel.create!(provider: "dummy2", data: { val: "channel" })
end
before do
SiteSetting.chat_integration_enabled = true
SiteSetting.discourse_automation_enabled = true
SiteSetting.tagging_enabled = true
SiteSetting.create_tag_allowed_groups = Group::AUTO_GROUPS[:everyone]
SiteSetting.tag_topic_allowed_groups = Group::AUTO_GROUPS[:everyone]
automation.upsert_field!(
"watching_categories",
"categories",
{ "value" => [category.id] },
target: "trigger",
)
automation.upsert_field!(
"watching_tags",
"tags",
{ "value" => [tag.name] },
target: "trigger",
)
automation.upsert_field!(
"provider",
"choices",
{ "value" => channel1.provider },
target: "script",
)
automation.upsert_field!("channel_name", "text", { "value" => "channel" }, target: "script")
end
it "triggers a notification" do
topic = Fabricate(:topic, user: admin, tags: [], category: category)
DiscourseTagging.tag_topic_by_names(topic, Guardian.new(admin), [tag.name])
expect(validated_provider.sent_messages.length).to eq(1)
expect(validated_provider.sent_messages.first[:post]).to eq(topic.id)
expect(validated_provider.sent_messages.first[:channel]).to eq(channel1)
end
it "only triggers for the correct tag" do
topic = Fabricate(:topic, user: admin, tags: [], category: category)
DiscourseTagging.tag_topic_by_names(topic, Guardian.new(admin), ["other_tag"])
expect(validated_provider.sent_messages.length).to eq(0)
end
it "only triggers for the correct category" do
topic = Fabricate(:topic, user: admin, tags: [], category: Fabricate(:category))
DiscourseTagging.tag_topic_by_names(topic, Guardian.new(admin), [tag.name])
expect(validated_provider.sent_messages.length).to eq(0)
end
it "should not trigger a provider notification on topic creation for topic_tags_changed script" do
TopicCreator.create(
admin,
Guardian.new(admin),
valid_attrs.merge(tags: [tag.name], category: category.id),
)
expect(validated_provider.sent_messages.length).to eq(0)
end
Feature: add chat integration reference post (#216) * FEATURE: Add chat integration reference post This class works similar to a post but it is not a post. * DEV: change how `excerpt` method works * feature: Add `send_chat_integration_message` scriptable add `send_chat_integration_message` scriptable that uses the rules to send a message to the chat provider add locale strings for the new scriptable update `ChatIntegrationReferencePost` `excerpt` method add tests for `ChatIntegrationReferencePost` * DEV: Add `get_channel_by_name` to every provider This makes using `trigger_notification` easier with every provider as well. * DEV: Add `get_channel_name` to all providers This method gets the name of the channel based on how the provider identifies it. Updates channel_name in locales yaml Adds migrate_tag_added_filter_to_all_providers.rb to move all existing rules to use Automation * DEV: Add removal of old migration data Update small action locales with strings from core * DEV: solve review comments * DEV: update test locale strings * DEV: remove empty line to trigger lint * DEV: lint applied * DEV: Add tests for automation integration * DEV: add rails logger for when automatio error occurs * DEV: move migration to be SQL only Update provider helper to use hashes instead of dot notation * DEV: update migration with correct table names * DEV: Update migrate_tag_added_filter_to_all_providers to use smaller SQL queries Commented out migrate_tag_added_from_filter_to_automation.rb * DEV: update comments in migration file * DEV: update indentation in client.en.yml * DEV: update with review comments * Update spec/lib/discourse_chat_integration/chat_integration_reference_post_spec.rb Co-authored-by: Jarek Radosz <jradosz@gmail.com> * Update spec/lib/discourse_chat_integration/chat_integration_reference_post_spec.rb Co-authored-by: Jarek Radosz <jradosz@gmail.com> * Update spec/lib/discourse_chat_integration/chat_integration_reference_post_spec.rb Co-authored-by: Jarek Radosz <jradosz@gmail.com> * Update spec/integration/automation_spec.rb Co-authored-by: Jarek Radosz <jradosz@gmail.com> * Update lib/discourse_chat_integration/chat_integration_reference_post.rb Co-authored-by: Jarek Radosz <jradosz@gmail.com> * DEV: update specs with review comments * DEV: update typos in tests * DEV: inlined functions for getting channel name for provider in migration --------- Co-authored-by: Jarek Radosz <jradosz@gmail.com>
2024-09-11 09:42:52 -04:00
end
end