Module: Hephaestus::Webmocks::YettoWebmock

Defined in:
lib/hephaestus/support/hephaestus/webmocks/yetto_webmock.rb

Instance Method Summary collapse

Instance Method Details

#assert_not_requested_update_plug_installation(plug_installation_id) ⇒ Object



43
44
45
# File 'lib/hephaestus/support/hephaestus/webmocks/yetto_webmock.rb', line 43

def assert_not_requested_update_plug_installation(plug_installation_id)
  assert_requested(:patch, "#{Hephaestus::YettoService::YETTO_API_VERSION_TLD}/installations/#{plug_installation_id}", times: 0)
end

#assert_requested_add_message_to_conversation(plug_installation_id, conversation_id) ⇒ Object



140
141
142
# File 'lib/hephaestus/support/hephaestus/webmocks/yetto_webmock.rb', line 140

def assert_requested_add_message_to_conversation(plug_installation_id, conversation_id)
  assert_requested(:post, "#{Hephaestus::YettoService::YETTO_API_VERSION_TLD}/conversations/#{conversation_id}/messages")
end

#assert_requested_create_conversation(plug_installation_id, inbox_id) ⇒ Object



63
64
65
# File 'lib/hephaestus/support/hephaestus/webmocks/yetto_webmock.rb', line 63

def assert_requested_create_conversation(plug_installation_id, inbox_id)
  assert_requested(:post, "#{Hephaestus::YettoService::YETTO_API_VERSION_TLD}/inboxes/#{inbox_id}/conversations")
end

#assert_requested_create_message(plug_installation_id, message_id) ⇒ Object



144
145
146
# File 'lib/hephaestus/support/hephaestus/webmocks/yetto_webmock.rb', line 144

def assert_requested_create_message(plug_installation_id, message_id)
  assert_requested(:post, "#{::Hephaestus::YettoService::YETTO_API_VERSION_TLD}/messages/#{message_id}/replies")
end

#assert_requested_find_message_in_conversation_by_metadata(plug_installation_id, conversation_id) ⇒ Object



179
180
181
# File 'lib/hephaestus/support/hephaestus/webmocks/yetto_webmock.rb', line 179

def (plug_installation_id, conversation_id)
  assert_requested(:get, "#{Hephaestus::YettoService::YETTO_API_VERSION_TLD}/conversations/#{conversation_id}/messages?#{filter}")
end

#assert_requested_get_messages_in_conversation(plug_installation_id, conversation_id, filter: "") ⇒ Object



109
110
111
# File 'lib/hephaestus/support/hephaestus/webmocks/yetto_webmock.rb', line 109

def assert_requested_get_messages_in_conversation(plug_installation_id, conversation_id, filter: "")
  assert_requested(:get, "#{::Hephaestus::YettoService::YETTO_API_VERSION_TLD}/conversations/#{conversation_id}/messages?#{filter}")
end

#assert_requested_get_messages_in_inbox(plug_installation_id, inbox_id, filter: "") ⇒ Object



96
97
98
# File 'lib/hephaestus/support/hephaestus/webmocks/yetto_webmock.rb', line 96

def assert_requested_get_messages_in_inbox(plug_installation_id, inbox_id, filter: "")
  assert_requested(:get, "#{Hephaestus::YettoService::YETTO_API_VERSION_TLD}/inboxes/#{inbox_id}/messages?#{filter}")
end

#assert_requested_get_plug_installation(plug_installation_id, times: 1) ⇒ Object



26
27
28
# File 'lib/hephaestus/support/hephaestus/webmocks/yetto_webmock.rb', line 26

def assert_requested_get_plug_installation(plug_installation_id, times: 1)
  assert_requested(:get, "#{Hephaestus::YettoService::YETTO_API_VERSION_TLD}/installations/#{plug_installation_id}", times:)
end

#assert_requested_get_plug_installations(filter: "") ⇒ Object



83
84
85
# File 'lib/hephaestus/support/hephaestus/webmocks/yetto_webmock.rb', line 83

def assert_requested_get_plug_installations(filter: "")
  assert_requested(:get, "#{Hephaestus::YettoService::YETTO_API_VERSION_TLD}/plug/installations?#{filter}")
end

#assert_requested_post_access_token(plug_installation_id, times: 1) ⇒ Object



11
12
13
# File 'lib/hephaestus/support/hephaestus/webmocks/yetto_webmock.rb', line 11

def assert_requested_post_access_token(plug_installation_id, times: 1)
  assert_requested(:post, "#{Hephaestus::YettoService::YETTO_API_VERSION_TLD}/plug/installations/#{plug_installation_id}/access_tokens", times: times)
end

#assert_requested_update_message(plug_installation_id, message_id) ⇒ Object



162
163
164
# File 'lib/hephaestus/support/hephaestus/webmocks/yetto_webmock.rb', line 162

def assert_requested_update_message(plug_installation_id, message_id)
  assert_requested(:patch, "#{::Hephaestus::YettoService::YETTO_API_VERSION_TLD}/messages/#{message_id}")
end

#assert_requested_update_plug_installation(plug_installation_id) ⇒ Object



39
40
41
# File 'lib/hephaestus/support/hephaestus/webmocks/yetto_webmock.rb', line 39

def assert_requested_update_plug_installation(plug_installation_id)
  assert_requested(:patch, "#{Hephaestus::YettoService::YETTO_API_VERSION_TLD}/installations/#{plug_installation_id}")
end

#stub_add_message_to_conversation(plug_installation_id, conversation_id, payload, response: {}, status: 200) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/hephaestus/support/hephaestus/webmocks/yetto_webmock.rb', line 124

def stub_add_message_to_conversation(plug_installation_id, conversation_id, payload, response: {}, status: 200)
  stub_post_access_token(plug_installation_id)

  response[:plug_installation] = { id: plug_installation_id }

  stub_request(:post, "#{Hephaestus::YettoService::YETTO_API_VERSION_TLD}/conversations/#{conversation_id}/messages")
    .with(
      body: payload,
    )
    .to_return(
      status: status,
      headers: { content_type: "application/json; charset=utf-8" },
      body: response.to_json,
    )
end

#stub_create_conversation(plug_installation_id, inbox_id, payload, response: {}) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/hephaestus/support/hephaestus/webmocks/yetto_webmock.rb', line 67

def stub_create_conversation(plug_installation_id, inbox_id, payload, response: {})
  stub_post_access_token(plug_installation_id)

  response[:plug_installation] = { id: plug_installation_id }

  stub_request(:post, "#{Hephaestus::YettoService::YETTO_API_VERSION_TLD}/inboxes/#{inbox_id}/conversations")
    .with(
      body: payload,
    )
    .to_return(
      status: 200,
      headers: { content_type: "application/json; charset=utf-8" },
      body: response.to_json,
    )
end

#stub_create_message(plug_installation_id, message_id, payload) ⇒ Object



148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/hephaestus/support/hephaestus/webmocks/yetto_webmock.rb', line 148

def stub_create_message(plug_installation_id, message_id, payload)
  stub_post_access_token(plug_installation_id)

  stub_request(:post, "#{::Hephaestus::YettoService::YETTO_API_VERSION_TLD}/messages/#{message_id}/replies")
    .with(
      body: payload,
    )
    .to_return(
      status: 200,
      headers: { content_type: "application/json; charset=utf-8" },
      body: {}.to_json,
    )
end

#stub_find_message_in_conversation(plug_installation_id, conversation_id, response, status: 200, filter: "") ⇒ Object



183
184
185
186
187
188
189
190
191
192
# File 'lib/hephaestus/support/hephaestus/webmocks/yetto_webmock.rb', line 183

def stub_find_message_in_conversation(plug_installation_id, conversation_id, response, status: 200, filter: "")
  stub_post_access_token(plug_installation_id)

  stub_request(:get, "#{Hephaestus::YettoService::YETTO_API_VERSION_TLD}/conversations/#{conversation_id}/messages?#{filter}")
    .to_return(
      status: status,
      headers: { content_type: "application/json; charset=utf-8" },
      body: response.to_json,
    )
end

#stub_get_messages_in_conversation(plug_installation_id, conversation_id, response, status: 200, filter: "") ⇒ Object



113
114
115
116
117
118
119
120
121
122
# File 'lib/hephaestus/support/hephaestus/webmocks/yetto_webmock.rb', line 113

def stub_get_messages_in_conversation(plug_installation_id, conversation_id, response, status: 200, filter: "")
  stub_post_access_token(plug_installation_id)

  stub_request(:get, "#{::Hephaestus::YettoService::YETTO_API_VERSION_TLD}/conversations/#{conversation_id}/messages?#{filter}")
    .to_return(
      status: status,
      headers: { content_type: "application/json; charset=utf-8" },
      body: response.to_json,
    )
end

#stub_get_messages_in_inbox(plug_installation_id, inbox_id, response, filter: "") ⇒ Object



100
101
102
103
104
105
106
107
# File 'lib/hephaestus/support/hephaestus/webmocks/yetto_webmock.rb', line 100

def stub_get_messages_in_inbox(plug_installation_id, inbox_id, response, filter: "")
  stub_post_access_token(plug_installation_id)
  stub_request(:get, "#{Hephaestus::YettoService::YETTO_API_VERSION_TLD}/inboxes/#{inbox_id}/messages?#{filter}")
    .to_return(
      status: 200,
      body: response.to_json,
    )
end

#stub_get_plug_installation(plug_installation_id, response: {}, status: 200) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/hephaestus/support/hephaestus/webmocks/yetto_webmock.rb', line 30

def stub_get_plug_installation(plug_installation_id, response: {}, status: 200)
  stub_request(:get, "#{Hephaestus::YettoService::YETTO_API_VERSION_TLD}/installations/#{plug_installation_id}")
    .to_return(
      status: status,
      headers: { content_type: "application/json; charset=utf-8" },
      body: response.to_json,
    )
end

#stub_get_plug_installations(response, status: 200, filter: "") ⇒ Object



87
88
89
90
91
92
93
94
# File 'lib/hephaestus/support/hephaestus/webmocks/yetto_webmock.rb', line 87

def stub_get_plug_installations(response, status: 200, filter: "")
  stub_request(:get, "#{Hephaestus::YettoService::YETTO_API_VERSION_TLD}/plug/installations?#{filter}")
    .to_return(
      status: status,
      headers: { content_type: "application/json; charset=utf-8" },
      body: response.to_json,
    )
end

#stub_post_access_token(plug_installation_id) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/hephaestus/support/hephaestus/webmocks/yetto_webmock.rb', line 15

def stub_post_access_token(plug_installation_id)
  response = {
    token: Faker::Alphanumeric.alphanumeric(number: 26).upcase,
  }

  stub_request(:post, "#{Hephaestus::YettoService::YETTO_API_VERSION_TLD}/plug/installations/#{plug_installation_id}/access_tokens")
    .to_return(
      body: response.to_json,
    )
end

#stub_update_message(plug_installation_id, message_id, payload) ⇒ Object



166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/hephaestus/support/hephaestus/webmocks/yetto_webmock.rb', line 166

def stub_update_message(plug_installation_id, message_id, payload)
  stub_post_access_token(plug_installation_id)
  stub_request(:patch, "#{::Hephaestus::YettoService::YETTO_API_VERSION_TLD}/messages/#{message_id}")
    .with(
      body: payload,
    )
    .to_return(
      status: 200,
      headers: { content_type: "application/json; charset=utf-8" },
      body: {}.to_json,
    )
end

#stub_update_plug_installation(plug_installation_id, params, response: {}, status: 200) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/hephaestus/support/hephaestus/webmocks/yetto_webmock.rb', line 47

def stub_update_plug_installation(plug_installation_id, params, response: {}, status: 200)
  stub_post_access_token(plug_installation_id)

  response[:plug_installation] = { id: plug_installation_id }

  stub_request(:patch, "#{Hephaestus::YettoService::YETTO_API_VERSION_TLD}/installations/#{plug_installation_id}")
    .with(
      body: params,
    )
    .to_return(
      status: status,
      headers: { content_type: "application/json; charset=utf-8" },
      body: response.to_json,
    )
end

#yetto_auth_header(payload, signing_secret = Hephaestus::YETTO_SIGNING_SECRET) ⇒ Object



7
8
9
# File 'lib/hephaestus/support/hephaestus/webmocks/yetto_webmock.rb', line 7

def yetto_auth_header(payload, signing_secret = Hephaestus::YETTO_SIGNING_SECRET)
  "sha256=#{OpenSSL::HMAC.hexdigest(Hephaestus::ValidatesFromYetto::SHA256_DIGEST, signing_secret, payload.to_json)}"
end