Class: ChatSDK::Testing::FakeAdapter
- Inherits:
-
Adapter::Base
- Object
- Adapter::Base
- ChatSDK::Testing::FakeAdapter
- Defined in:
- lib/chat_sdk/testing/fake_adapter.rb
Constant Summary
Constants included from Adapter::Capabilities
Instance Attribute Summary collapse
-
#deleted_messages ⇒ Object
readonly
Returns the value of attribute deleted_messages.
-
#dm_channels ⇒ Object
readonly
Returns the value of attribute dm_channels.
-
#edited_messages ⇒ Object
readonly
Returns the value of attribute edited_messages.
-
#ephemeral_messages_sent ⇒ Object
readonly
Returns the value of attribute ephemeral_messages_sent.
-
#files_uploaded ⇒ Object
readonly
Returns the value of attribute files_uploaded.
-
#modals_opened ⇒ Object
readonly
Returns the value of attribute modals_opened.
-
#posted_messages ⇒ Object
readonly
Returns the value of attribute posted_messages.
-
#reactions_added ⇒ Object
readonly
Returns the value of attribute reactions_added.
-
#reactions_removed ⇒ Object
readonly
Returns the value of attribute reactions_removed.
-
#typing_started ⇒ Object
readonly
Returns the value of attribute typing_started.
Instance Method Summary collapse
- #ack_response(rack_request) ⇒ Object
- #add_reaction(channel_id:, message_id:, emoji:) ⇒ Object
- #client ⇒ Object
- #delete_message(channel_id:, message_id:) ⇒ Object
- #edit_message(channel_id:, message_id:, message:) ⇒ Object
- #fetch_messages(channel_id:, thread_id: nil, cursor: nil, limit: 50) ⇒ Object
-
#initialize ⇒ FakeAdapter
constructor
A new instance of FakeAdapter.
- #mention(user_id) ⇒ Object
- #name ⇒ Object
- #open_dm(user_id) ⇒ Object
- #open_modal(trigger_id:, modal:) ⇒ Object
- #parse_events(rack_request) ⇒ Object
- #post_ephemeral(channel_id:, user_id:, message:, thread_id: nil) ⇒ Object
- #post_message(channel_id:, message:, thread_id: nil) ⇒ Object
- #remove_reaction(channel_id:, message_id:, emoji:) ⇒ Object
- #render(postable_message) ⇒ Object
- #reset! ⇒ Object
- #simulate_action(chat, action_id:, value: nil, user_id: "U123", channel_id: "C123", thread_id: "T123", trigger_id: nil) ⇒ Object
-
#simulate_mention(chat, text:, user_id: "U123", user_name: "testuser", channel_id: "C123", thread_id: nil) ⇒ Object
Simulation helpers.
- #simulate_reaction(chat, emoji:, user_id: "U123", message_id: "M123", channel_id: "C123", thread_id: "T123", added: true) ⇒ Object
- #simulate_slash_command(chat, command:, text: "", user_id: "U123", channel_id: "C123", trigger_id: nil) ⇒ Object
- #start_typing(channel_id:, thread_id: nil) ⇒ Object
- #upload_file(channel_id:, io:, filename:, thread_id: nil, comment: nil) ⇒ Object
- #verify_request!(rack_request) ⇒ Object
Methods included from Adapter::Capabilities
Constructor Details
#initialize ⇒ FakeAdapter
Returns a new instance of FakeAdapter.
14 15 16 |
# File 'lib/chat_sdk/testing/fake_adapter.rb', line 14 def initialize reset! end |
Instance Attribute Details
#deleted_messages ⇒ Object (readonly)
Returns the value of attribute deleted_messages.
10 11 12 |
# File 'lib/chat_sdk/testing/fake_adapter.rb', line 10 def @deleted_messages end |
#dm_channels ⇒ Object (readonly)
Returns the value of attribute dm_channels.
10 11 12 |
# File 'lib/chat_sdk/testing/fake_adapter.rb', line 10 def dm_channels @dm_channels end |
#edited_messages ⇒ Object (readonly)
Returns the value of attribute edited_messages.
10 11 12 |
# File 'lib/chat_sdk/testing/fake_adapter.rb', line 10 def @edited_messages end |
#ephemeral_messages_sent ⇒ Object (readonly)
Returns the value of attribute ephemeral_messages_sent.
10 11 12 |
# File 'lib/chat_sdk/testing/fake_adapter.rb', line 10 def @ephemeral_messages_sent end |
#files_uploaded ⇒ Object (readonly)
Returns the value of attribute files_uploaded.
10 11 12 |
# File 'lib/chat_sdk/testing/fake_adapter.rb', line 10 def files_uploaded @files_uploaded end |
#modals_opened ⇒ Object (readonly)
Returns the value of attribute modals_opened.
10 11 12 |
# File 'lib/chat_sdk/testing/fake_adapter.rb', line 10 def modals_opened @modals_opened end |
#posted_messages ⇒ Object (readonly)
Returns the value of attribute posted_messages.
10 11 12 |
# File 'lib/chat_sdk/testing/fake_adapter.rb', line 10 def @posted_messages end |
#reactions_added ⇒ Object (readonly)
Returns the value of attribute reactions_added.
10 11 12 |
# File 'lib/chat_sdk/testing/fake_adapter.rb', line 10 def reactions_added @reactions_added end |
#reactions_removed ⇒ Object (readonly)
Returns the value of attribute reactions_removed.
10 11 12 |
# File 'lib/chat_sdk/testing/fake_adapter.rb', line 10 def reactions_removed @reactions_removed end |
#typing_started ⇒ Object (readonly)
Returns the value of attribute typing_started.
10 11 12 |
# File 'lib/chat_sdk/testing/fake_adapter.rb', line 10 def typing_started @typing_started end |
Instance Method Details
#ack_response(rack_request) ⇒ Object
30 31 32 |
# File 'lib/chat_sdk/testing/fake_adapter.rb', line 30 def ack_response(rack_request) nil end |
#add_reaction(channel_id:, message_id:, emoji:) ⇒ Object
75 76 77 78 79 |
# File 'lib/chat_sdk/testing/fake_adapter.rb', line 75 def add_reaction(channel_id:, message_id:, emoji:) record = RecordedCall.new(:add_reaction, channel_id: channel_id, message_id: , emoji: emoji) @reactions_added << record record end |
#client ⇒ Object
22 23 24 |
# File 'lib/chat_sdk/testing/fake_adapter.rb', line 22 def client self end |
#delete_message(channel_id:, message_id:) ⇒ Object
57 58 59 60 61 |
# File 'lib/chat_sdk/testing/fake_adapter.rb', line 57 def (channel_id:, message_id:) record = RecordedCall.new(:delete_message, channel_id: channel_id, message_id: ) @deleted_messages << record record end |
#edit_message(channel_id:, message_id:, message:) ⇒ Object
51 52 53 54 55 |
# File 'lib/chat_sdk/testing/fake_adapter.rb', line 51 def (channel_id:, message_id:, message:) record = RecordedCall.new(:edit_message, channel_id: channel_id, message_id: , message: ) @edited_messages << record record end |
#fetch_messages(channel_id:, thread_id: nil, cursor: nil, limit: 50) ⇒ Object
93 94 95 |
# File 'lib/chat_sdk/testing/fake_adapter.rb', line 93 def (channel_id:, thread_id: nil, cursor: nil, limit: 50) [[], nil] end |
#mention(user_id) ⇒ Object
109 110 111 |
# File 'lib/chat_sdk/testing/fake_adapter.rb', line 109 def mention(user_id) "<@#{user_id}>" end |
#name ⇒ Object
18 19 20 |
# File 'lib/chat_sdk/testing/fake_adapter.rb', line 18 def name :test end |
#open_dm(user_id) ⇒ Object
87 88 89 90 91 |
# File 'lib/chat_sdk/testing/fake_adapter.rb', line 87 def open_dm(user_id) channel_id = "dm_#{user_id}" @dm_channels << RecordedCall.new(:open_dm, user_id: user_id, channel_id: channel_id) channel_id end |
#open_modal(trigger_id:, modal:) ⇒ Object
97 98 99 100 101 |
# File 'lib/chat_sdk/testing/fake_adapter.rb', line 97 def open_modal(trigger_id:, modal:) record = RecordedCall.new(:open_modal, trigger_id: trigger_id, modal: modal) @modals_opened << record record end |
#parse_events(rack_request) ⇒ Object
34 35 36 |
# File 'lib/chat_sdk/testing/fake_adapter.rb', line 34 def parse_events(rack_request) [] end |
#post_ephemeral(channel_id:, user_id:, message:, thread_id: nil) ⇒ Object
63 64 65 66 67 |
# File 'lib/chat_sdk/testing/fake_adapter.rb', line 63 def post_ephemeral(channel_id:, user_id:, message:, thread_id: nil) record = RecordedCall.new(:post_ephemeral, channel_id: channel_id, user_id: user_id, message: , thread_id: thread_id) @ephemeral_messages_sent << record record end |
#post_message(channel_id:, message:, thread_id: nil) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/chat_sdk/testing/fake_adapter.rb', line 38 def (channel_id:, message:, thread_id: nil) record = RecordedCall.new(:post_message, channel_id: channel_id, message: , thread_id: thread_id) @posted_messages << record Message.new( id: "msg_#{@posted_messages.size}", text: .is_a?(PostableMessage) ? .text : .to_s, author: Author.new(id: "bot", name: "test-bot", platform: :test, bot: true), thread_id: thread_id, channel_id: channel_id, platform: :test ) end |
#remove_reaction(channel_id:, message_id:, emoji:) ⇒ Object
81 82 83 84 85 |
# File 'lib/chat_sdk/testing/fake_adapter.rb', line 81 def remove_reaction(channel_id:, message_id:, emoji:) record = RecordedCall.new(:remove_reaction, channel_id: channel_id, message_id: , emoji: emoji) @reactions_removed << record record end |
#render(postable_message) ⇒ Object
113 114 115 |
# File 'lib/chat_sdk/testing/fake_adapter.rb', line 113 def render() Cards::Renderer.new.render(.card) end |
#reset! ⇒ Object
181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/chat_sdk/testing/fake_adapter.rb', line 181 def reset! @posted_messages = [] @edited_messages = [] @deleted_messages = [] @ephemeral_messages_sent = [] @reactions_added = [] @reactions_removed = [] @files_uploaded = [] @modals_opened = [] @typing_started = [] @dm_channels = [] end |
#simulate_action(chat, action_id:, value: nil, user_id: "U123", channel_id: "C123", thread_id: "T123", trigger_id: nil) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/chat_sdk/testing/fake_adapter.rb', line 139 def simulate_action(chat, action_id:, value: nil, user_id: "U123", channel_id: "C123", thread_id: "T123", trigger_id: nil) user = Author.new(id: user_id, name: "testuser", platform: :test) event = Events::Action.new( action_id: action_id, value: value, user: user, thread_id: thread_id, channel_id: channel_id, trigger_id: trigger_id, platform: :test, adapter_name: :test ) chat.dispatch(event, adapter_name: :test) end |
#simulate_mention(chat, text:, user_id: "U123", user_name: "testuser", channel_id: "C123", thread_id: nil) ⇒ Object
Simulation helpers
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/chat_sdk/testing/fake_adapter.rb', line 118 def simulate_mention(chat, text:, user_id: "U123", user_name: "testuser", channel_id: "C123", thread_id: nil) thread_id ||= "T#{rand(1000..9999)}" = Author.new(id: user_id, name: user_name, platform: :test) = Message.new( id: "evt_#{rand(10000..99999)}", text: text, author: , thread_id: thread_id, channel_id: channel_id, platform: :test ) event = Events::Mention.new( message: , thread_id: thread_id, channel_id: channel_id, platform: :test, adapter_name: :test ) chat.dispatch(event, adapter_name: :test) end |
#simulate_reaction(chat, emoji:, user_id: "U123", message_id: "M123", channel_id: "C123", thread_id: "T123", added: true) ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/chat_sdk/testing/fake_adapter.rb', line 154 def simulate_reaction(chat, emoji:, user_id: "U123", message_id: "M123", channel_id: "C123", thread_id: "T123", added: true) event = Events::Reaction.new( emoji: emoji, user_id: user_id, message_id: , thread_id: thread_id, channel_id: channel_id, added: added, platform: :test, adapter_name: :test ) chat.dispatch(event, adapter_name: :test) end |
#simulate_slash_command(chat, command:, text: "", user_id: "U123", channel_id: "C123", trigger_id: nil) ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/chat_sdk/testing/fake_adapter.rb', line 168 def simulate_slash_command(chat, command:, text: "", user_id: "U123", channel_id: "C123", trigger_id: nil) event = Events::SlashCommand.new( command: command, text: text, user_id: user_id, channel_id: channel_id, trigger_id: trigger_id, platform: :test, adapter_name: :test ) chat.dispatch(event, adapter_name: :test) end |
#start_typing(channel_id:, thread_id: nil) ⇒ Object
103 104 105 106 107 |
# File 'lib/chat_sdk/testing/fake_adapter.rb', line 103 def start_typing(channel_id:, thread_id: nil) record = RecordedCall.new(:start_typing, channel_id: channel_id, thread_id: thread_id) @typing_started << record record end |
#upload_file(channel_id:, io:, filename:, thread_id: nil, comment: nil) ⇒ Object
69 70 71 72 73 |
# File 'lib/chat_sdk/testing/fake_adapter.rb', line 69 def upload_file(channel_id:, io:, filename:, thread_id: nil, comment: nil) record = RecordedCall.new(:upload_file, channel_id: channel_id, filename: filename, thread_id: thread_id, comment: comment) @files_uploaded << record record end |
#verify_request!(rack_request) ⇒ Object
26 27 28 |
# File 'lib/chat_sdk/testing/fake_adapter.rb', line 26 def verify_request!(rack_request) true end |