0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-06 13:08:40 +08:00
discourse/plugins/discourse-chat-integration/spec/dummy_provider.rb
Martin Brennan 9eef8a8b14
UX: Improve chat integration plugin provider setup (#38892)
Improves some chat integration provider setup UX. First,
we added a quick link to the provider site settings.

Second, we've added a way to quickly turn on each provider
from a quick menu.

Providers which need additional settings before being enabled
(like Telegram and Slack) will show a form in a modal first.
2026-04-17 09:56:05 +10:00

72 lines
2.1 KiB
Ruby
Vendored

# frozen_string_literal: true
RSpec.shared_context "with dummy provider" do
before(:each) do
module DiscourseChatIntegration::Provider::DummyProvider
PROVIDER_NAME = "dummy"
# Fake site settings come from the spec/support/dummy_plugin_site_settings.yml file
PROVIDER_ENABLED_SETTING = :dummy_provider_enabled
POPULARITY_SCORE = 5
CHANNEL_PARAMETERS = []
@@sent_messages = []
@@raise_exception = nil
def self.trigger_notification(post, channel, rule)
raise @@raise_exception if @@raise_exception
@@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) { DiscourseChatIntegration::Provider.send(:remove_const, :DummyProvider) }
let(:provider) { DiscourseChatIntegration::Provider::DummyProvider }
end
RSpec.shared_context "with validated dummy provider" do
before(:each) do
module DiscourseChatIntegration::Provider::Dummy2Provider
PROVIDER_NAME = "dummy2"
# Fake site settings come from the spec/support/dummy_plugin_site_settings.yml file
PROVIDER_ENABLED_SETTING = :other_dummy_provider_enabled
CHANNEL_IDENTIFIER_KEY = "val"
POPULARITY_SCORE = 5
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
def self.get_channel_by_name(name)
DiscourseChatIntegration::Channel
.with_provider(PROVIDER_NAME)
.with_data_value(CHANNEL_IDENTIFIER_KEY, name)
.first
end
end
end
after(:each) { DiscourseChatIntegration::Provider.send(:remove_const, :Dummy2Provider) }
let(:validated_provider) { DiscourseChatIntegration::Provider::Dummy2Provider }
end