discourse-chat-integration/spec/dummy_provider.rb
Michael K Johnson da9106127a
FEATURE: Enable optional support for threading slack posts (#38)
When creating a new Discourse post from slack with the `post` feature, record the
slack `ts` thread ID for the resulting topic post using an HTML comment to pass
the `ts` through.

When notifying slack of new Discourse posts, record the slack `ts` thread ID in
the post's topic if it has not yet been recorded. (Normally, this will be done
for the topic post, except where notifications are being posted for old topics
before this feature was created.)

Add a new rule filter `thread` which posts threaded responses to slack if there
is a `ts` recorded for the post topic.

Modify the `trigger_notifications` interface to enable other integrations to
implement similar functionality.

Present the `thread` rule in the help text and admin UI only for the slack
providers.

https://meta.discourse.org/t/optionally-threading-posts-to-parent-topic-in-slack-integration/150759
2020-06-15 16:45:25 +01:00

68 lines
1.7 KiB
Ruby

# frozen_string_literal: true
RSpec.shared_context "dummy provider" do
before(:each) do
module ::DiscourseChat::Provider::DummyProvider
PROVIDER_NAME = "dummy".freeze
PROVIDER_ENABLED_SETTING = :chat_integration_enabled # Tie to main plugin enabled setting
CHANNEL_PARAMETERS = []
@@sent_messages = []
@@raise_exception = nil
def self.trigger_notification(post, channel, rule)
if @@raise_exception
raise @@raise_exception
end
@@sent_messages.push(post: post.id, channel: channel)
end
def self.sent_messages
@@sent_messages
end
def self.sent_to_channel_ids
@@sent_messages.map { |x| x[:channel].id }
end
def self.set_raise_exception(bool)
@@raise_exception = bool
end
end
end
after(:each) do
::DiscourseChat::Provider.send(:remove_const, :DummyProvider)
end
let(:provider) { ::DiscourseChat::Provider::DummyProvider }
end
RSpec.shared_context "validated dummy provider" do
before(:each) do
module ::DiscourseChat::Provider::Dummy2Provider
PROVIDER_NAME = "dummy2".freeze
PROVIDER_ENABLED_SETTING = :chat_integration_enabled # Tie to main plugin enabled setting
CHANNEL_PARAMETERS = [
{ key: "val", regex: '^\S+$', unique: true }
]
@@sent_messages = []
def self.trigger_notification(post, channel, rule)
@@sent_messages.push(post: post.id, channel: channel)
end
def self.sent_messages
@@sent_messages
end
end
end
after(:each) do
::DiscourseChat::Provider.send(:remove_const, :Dummy2Provider)
end
end