2019-05-12 22:37:49 -04:00
|
|
|
# frozen_string_literal: true
|
2017-07-10 13:19:59 -04:00
|
|
|
|
2022-10-03 15:36:52 -04:00
|
|
|
RSpec.shared_context "with dummy provider" do
|
2017-07-10 13:19:59 -04:00
|
|
|
before(:each) do
|
2021-07-13 15:36:16 -04:00
|
|
|
module ::DiscourseChatIntegration::Provider::DummyProvider
|
2017-07-10 13:19:59 -04:00
|
|
|
PROVIDER_NAME = "dummy".freeze
|
|
|
|
PROVIDER_ENABLED_SETTING = :chat_integration_enabled # Tie to main plugin enabled setting
|
2017-07-17 12:53:32 -04:00
|
|
|
CHANNEL_PARAMETERS = []
|
2017-07-13 15:50:45 -04:00
|
|
|
|
2017-07-10 13:19:59 -04:00
|
|
|
@@sent_messages = []
|
|
|
|
@@raise_exception = nil
|
|
|
|
|
2020-06-15 11:45:25 -04:00
|
|
|
def self.trigger_notification(post, channel, rule)
|
2017-07-10 13:19:59 -04:00
|
|
|
if @@raise_exception
|
|
|
|
raise @@raise_exception
|
|
|
|
end
|
2017-10-03 05:42:07 -04:00
|
|
|
|
2017-07-10 13:19:59 -04:00
|
|
|
@@sent_messages.push(post: post.id, channel: channel)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.sent_messages
|
|
|
|
@@sent_messages
|
|
|
|
end
|
|
|
|
|
2017-07-13 16:47:15 -04:00
|
|
|
def self.sent_to_channel_ids
|
2017-08-01 15:53:39 -04:00
|
|
|
@@sent_messages.map { |x| x[:channel].id }
|
2017-07-13 16:47:15 -04:00
|
|
|
end
|
|
|
|
|
2017-07-10 13:19:59 -04:00
|
|
|
def self.set_raise_exception(bool)
|
|
|
|
@@raise_exception = bool
|
|
|
|
end
|
|
|
|
end
|
2017-07-31 08:12:09 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
after(:each) do
|
2021-07-13 15:36:16 -04:00
|
|
|
::DiscourseChatIntegration::Provider.send(:remove_const, :DummyProvider)
|
2017-07-10 13:19:59 -04:00
|
|
|
end
|
|
|
|
|
2021-07-13 15:36:16 -04:00
|
|
|
let(:provider) { ::DiscourseChatIntegration::Provider::DummyProvider }
|
2017-07-13 15:50:45 -04:00
|
|
|
end
|
|
|
|
|
2022-10-03 15:36:52 -04:00
|
|
|
RSpec.shared_context "with validated dummy provider" do
|
2017-07-13 15:50:45 -04:00
|
|
|
before(:each) do
|
2021-07-13 15:36:16 -04:00
|
|
|
module ::DiscourseChatIntegration::Provider::Dummy2Provider
|
2017-07-13 15:50:45 -04:00
|
|
|
PROVIDER_NAME = "dummy2".freeze
|
|
|
|
PROVIDER_ENABLED_SETTING = :chat_integration_enabled # Tie to main plugin enabled setting
|
2017-07-17 12:53:32 -04:00
|
|
|
CHANNEL_PARAMETERS = [
|
2017-08-01 15:53:39 -04:00
|
|
|
{ key: "val", regex: '^\S+$', unique: true }
|
2017-07-17 12:53:32 -04:00
|
|
|
]
|
2017-07-13 15:50:45 -04:00
|
|
|
|
|
|
|
@@sent_messages = []
|
|
|
|
|
2020-06-15 11:45:25 -04:00
|
|
|
def self.trigger_notification(post, channel, rule)
|
2017-07-13 15:50:45 -04:00
|
|
|
@@sent_messages.push(post: post.id, channel: channel)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.sent_messages
|
|
|
|
@@sent_messages
|
|
|
|
end
|
|
|
|
end
|
2017-08-01 15:53:39 -04:00
|
|
|
|
2017-07-13 15:50:45 -04:00
|
|
|
end
|
|
|
|
|
2017-07-31 08:12:09 -04:00
|
|
|
after(:each) do
|
2021-07-13 15:36:16 -04:00
|
|
|
::DiscourseChatIntegration::Provider.send(:remove_const, :Dummy2Provider)
|
2017-07-31 08:12:09 -04:00
|
|
|
end
|
2017-07-10 13:19:59 -04:00
|
|
|
end
|