Class: ChatSDK::Testing::FakeAdapter

Inherits:
Adapter::Base show all
Defined in:
lib/chat_sdk/testing/fake_adapter.rb

Constant Summary

Constants included from Adapter::Capabilities

Adapter::Capabilities::KNOWN

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Adapter::Capabilities

included, #supports?

Constructor Details

#initializeFakeAdapter

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_messagesObject (readonly)

Returns the value of attribute deleted_messages.



10
11
12
# File 'lib/chat_sdk/testing/fake_adapter.rb', line 10

def deleted_messages
  @deleted_messages
end

#dm_channelsObject (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_messagesObject (readonly)

Returns the value of attribute edited_messages.



10
11
12
# File 'lib/chat_sdk/testing/fake_adapter.rb', line 10

def edited_messages
  @edited_messages
end

#ephemeral_messages_sentObject (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
  @ephemeral_messages_sent
end

#files_uploadedObject (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_openedObject (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_messagesObject (readonly)

Returns the value of attribute posted_messages.



10
11
12
# File 'lib/chat_sdk/testing/fake_adapter.rb', line 10

def posted_messages
  @posted_messages
end

#reactions_addedObject (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_removedObject (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_startedObject (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: message_id, emoji: emoji)
  @reactions_added << record
  record
end

#clientObject



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 delete_message(channel_id:, message_id:)
  record = RecordedCall.new(:delete_message, channel_id: channel_id, message_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 edit_message(channel_id:, message_id:, message:)
  record = RecordedCall.new(:edit_message, channel_id: channel_id, message_id: message_id, message: 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 fetch_messages(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

#nameObject



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: 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 post_message(channel_id:, message:, thread_id: nil)
  record = RecordedCall.new(:post_message, channel_id: channel_id, message: message, thread_id: thread_id)
  @posted_messages << record
  Message.new(
    id: "msg_#{@posted_messages.size}",
    text: message.is_a?(PostableMessage) ? message.text : message.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: 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(postable_message)
  Cards::Renderer.new.render(postable_message.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 = Author.new(id: user_id, name: user_name, platform: :test)
  message = Message.new(
    id: "evt_#{rand(10000..99999)}",
    text: text,
    author: author,
    thread_id: thread_id,
    channel_id: channel_id,
    platform: :test
  )
  event = Events::Mention.new(
    message: 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: 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