mailinator_client 1.0.7 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -29,6 +29,7 @@ module MailinatorClient
29
29
  raise ArgumentError.new("whToken is required") unless params.has_key?(:whToken)
30
30
  raise ArgumentError.new("webhook is required") unless params.has_key?(:webhook)
31
31
 
32
+ body = params[:webhook] if params.has_key?(:webhook)
32
33
  query_params[:whtoken] = params[:whToken] if params.has_key?(:whToken)
33
34
 
34
35
  path = "/domains/private/webhook"
@@ -15,11 +15,12 @@ Gem::Specification.new do |gem|
15
15
  gem.version = MailinatorClient::VERSION
16
16
  gem.licenses = ["MIT"]
17
17
 
18
- gem.required_ruby_version = ">= 2.1"
18
+ gem.required_ruby_version = ">= 2.7"
19
19
 
20
- gem.add_dependency "httparty", ">= 0.21", "< 0.22"
20
+ gem.add_dependency "httparty", ">= 0.24", "< 0.25"
21
21
 
22
- gem.add_development_dependency "minitest", ">= 5.25", "< 7.0"
23
- gem.add_development_dependency "rake", ">= 13.0", "< 14.0"
24
- gem.add_development_dependency "webmock", ">= 3.26", "< 4.0"
22
+ gem.add_development_dependency "addressable", ">= 2.9", "< 3.0"
23
+ gem.add_development_dependency "minitest", ">= 5.26", "< 6.0"
24
+ gem.add_development_dependency "rake", ">= 13.4", "< 14.0"
25
+ gem.add_development_dependency "webmock", ">= 3.26.2", "< 4.0"
25
26
  end
@@ -1,136 +1,274 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/test_helper")
2
2
 
3
3
  class MessagesApiTest < Minitest::Test
4
- def test_messages_endpoints
5
- require_env!(
6
- "MAILINATOR_TEST_API_TOKEN",
7
- "MAILINATOR_TEST_INBOX",
8
- "MAILINATOR_TEST_PHONE_NUMBER",
9
- "MAILINATOR_TEST_MESSAGE_WITH_ATTACHMENT_ID",
10
- "MAILINATOR_TEST_ATTACHMENT_ID"
11
- )
4
+ def setup
5
+ super
6
+ @client = integration_client
7
+ @domain_name = first_domain_name(@client)
8
+ @inbox_all = "*"
9
+ end
10
+
11
+ def test_post_message_seed
12
+ require_env!("MAILINATOR_TEST_API_TOKEN")
12
13
 
13
- client = integration_client
14
- domain_name = first_domain_name(client)
15
- inbox_all = "*"
14
+ response = @client.messages.post_message(
15
+ domain: @domain_name,
16
+ inbox: @inbox_all,
17
+ messageToPost: {
18
+ subject: "Testing ruby message",
19
+ from: "test_email_ruby@test.com",
20
+ text: "I love Ruby!"
21
+ }
22
+ )
16
23
 
17
- message_to_post = {
18
- subject: "Testing ruby message",
19
- from: "test_email_ruby@test.com",
20
- text: "I love Ruby!"
21
- }
22
- response = client.messages.post_message(domain: domain_name, inbox: inbox_all, messageToPost: message_to_post)
23
24
  assert response != nil, "Expected post message response to not be nil"
24
25
  assert response["status"] == "ok", "Expected post message response to be ok"
26
+ end
27
+
28
+ def test_fetch_inbox_basic
29
+ require_env!("MAILINATOR_TEST_API_TOKEN")
30
+
31
+ response = @client.messages.fetch_inbox(
32
+ domain: @domain_name,
33
+ inbox: @inbox_all,
34
+ skip: 0,
35
+ limit: 1,
36
+ sort: "ascending",
37
+ decodeSubject: false
38
+ )
25
39
 
26
- response = client.messages.fetch_inbox(domain: domain_name, inbox: inbox_all, skip: 0, limit: 1, sort: "ascending", decodeSubject: false)
27
40
  assert response != nil, "Expected fetch inbox response to not be nil"
28
41
  assert response["msgs"] != nil, "Expected response fetch inbox messages to not be nil"
29
- message = response["msgs"][0]
30
- message_id = message["id"]
42
+ end
43
+
44
+ def test_fetch_inbox_cursor
45
+ require_env!("MAILINATOR_TEST_API_TOKEN")
46
+
47
+ response = @client.messages.fetch_inbox(
48
+ domain: @domain_name,
49
+ inbox: @inbox_all,
50
+ skip: 0,
51
+ limit: 1,
52
+ sort: "ascending",
53
+ decodeSubject: false
54
+ )
55
+ cursor = response["cursor"]
56
+
57
+ response = @client.messages.fetch_inbox(
58
+ domain: @domain_name,
59
+ inbox: @inbox_all,
60
+ limit: 1,
61
+ cursor: cursor
62
+ )
31
63
 
32
- response = client.messages.fetch_inbox(domain: domain_name, inbox: inbox_all, limit: 1, cursor: response["cursor"])
33
64
  assert response != nil, "Expected fetch inbox response to not be nil"
34
65
  assert response["msgs"] != nil, "Expected response fetch inbox messages to not be nil"
66
+ end
67
+
68
+ def test_fetch_inbox_full
69
+ require_env!("MAILINATOR_TEST_API_TOKEN")
70
+
71
+ response = @client.messages.fetch_inbox(
72
+ domain: @domain_name,
73
+ inbox: @inbox_all,
74
+ limit: 1,
75
+ full: true
76
+ )
35
77
 
36
- response = client.messages.fetch_inbox(domain: domain_name, inbox: inbox_all, limit: 1, full: true)
37
78
  assert response != nil, "Expected fetch inbox response to not be nil"
38
79
  assert response["msgs"] != nil, "Expected response fetch inbox messages to not be nil"
80
+ end
81
+
82
+ def test_fetch_inbox_delete
83
+ require_env!("MAILINATOR_TEST_API_TOKEN")
84
+
85
+ response = @client.messages.fetch_inbox(
86
+ domain: @domain_name,
87
+ inbox: @inbox_all,
88
+ limit: 1,
89
+ delete: "1m"
90
+ )
39
91
 
40
- response = client.messages.fetch_inbox(domain: domain_name, inbox: inbox_all, limit: 1, delete: "1m")
41
92
  assert response != nil, "Expected fetch inbox response to not be nil"
42
93
  assert response["msgs"] != nil, "Expected response fetch inbox messages to not be nil"
94
+ end
43
95
 
44
- begin
45
- response = client.messages.fetch_inbox(domain: domain_name, inbox: inbox_all, limit: 1, wait: "1m")
46
- assert response != nil, "Expected fetch inbox response to not be nil"
47
- assert response["msgs"] != nil, "Expected response fetch inbox messages to not be nil"
48
- rescue MailinatorClient::ResponseError => e
49
- if e.code >= 500
50
- warn "Skipping wait query assertion due to server-side error (HTTP #{e.code})"
51
- else
52
- raise
53
- end
54
- end
96
+ def test_fetch_inbox_wait
97
+ require_env!("MAILINATOR_TEST_API_TOKEN")
98
+
99
+ response = @client.messages.fetch_inbox(
100
+ domain: @domain_name,
101
+ inbox: @inbox_all,
102
+ limit: 1,
103
+ wait: "1m"
104
+ )
55
105
 
56
- response = client.messages.fetch_inbox_message(domain: domain_name, inbox: inbox_all, messageId: message_id)
106
+ assert response != nil, "Expected fetch inbox response to not be nil"
107
+ assert response["msgs"] != nil, "Expected response fetch inbox messages to not be nil"
108
+ end
109
+
110
+ def test_fetch_message_variants
111
+ require_env!("MAILINATOR_TEST_API_TOKEN")
112
+
113
+ response = @client.messages.fetch_inbox(
114
+ domain: @domain_name,
115
+ inbox: @inbox_all,
116
+ skip: 0,
117
+ limit: 1,
118
+ sort: "ascending",
119
+ decodeSubject: false
120
+ )
121
+ message_id = response["msgs"][0]["id"]
122
+
123
+ response = @client.messages.fetch_inbox_message(
124
+ domain: @domain_name,
125
+ inbox: @inbox_all,
126
+ messageId: message_id
127
+ )
57
128
  assert response != nil, "Expected fetch inbox message response to not be nil"
58
129
 
59
- response = client.messages.fetch_message(domain: domain_name, messageId: message_id)
130
+ response = @client.messages.fetch_message(domain: @domain_name, messageId: message_id)
60
131
  assert response != nil, "Expected fetch message response to not be nil"
61
132
 
62
- response = client.messages.fetch_message(domain: domain_name, messageId: message_id, delete: "10s")
133
+ response = @client.messages.fetch_message(domain: @domain_name, messageId: message_id, delete: "10s")
63
134
  assert response != nil, "Expected fetch message response to not be nil"
135
+ end
136
+
137
+ def test_fetch_sms_message
138
+ require_env!("MAILINATOR_TEST_API_TOKEN", "MAILINATOR_TEST_PHONE_NUMBER")
139
+
140
+ response = @client.messages.fetch_sms_message(
141
+ domain: @domain_name,
142
+ teamSmsNumber: ENV["MAILINATOR_TEST_PHONE_NUMBER"]
143
+ )
64
144
 
65
- response = client.messages.fetch_sms_message(domain: domain_name, teamSmsNumber: ENV["MAILINATOR_TEST_PHONE_NUMBER"])
66
145
  assert response != nil, "Expected fetch sms message response to not be nil"
146
+ end
147
+
148
+ def test_attachment_list_and_download
149
+ require_env!(
150
+ "MAILINATOR_TEST_API_TOKEN",
151
+ "MAILINATOR_TEST_INBOX",
152
+ "MAILINATOR_TEST_MESSAGE_WITH_ATTACHMENT_ID"
153
+ )
67
154
 
68
- response = client.messages.fetch_inbox_message_attachments(
69
- domain: domain_name,
155
+ response = @client.messages.fetch_inbox_message_attachments(
156
+ domain: @domain_name,
70
157
  inbox: ENV["MAILINATOR_TEST_INBOX"],
71
158
  messageId: ENV["MAILINATOR_TEST_MESSAGE_WITH_ATTACHMENT_ID"]
72
159
  )
73
160
  assert response != nil, "Expected fetch inbox message attachments response to not be nil"
161
+ attachments = response["attachments"]
162
+ assert attachments != nil, "Expected attachments list in fetch inbox message attachments response"
163
+ assert_kind_of(Array, attachments, "Expected attachments to be an array")
164
+ assert !attachments.empty?, "Expected at least one attachment for MAILINATOR_TEST_MESSAGE_WITH_ATTACHMENT_ID"
165
+ attachment = attachments[0]
166
+ attachment_id = attachment["id"] || attachment["attachmentId"] || attachment["attachment_id"] || attachment["name"] || attachment["filename"]
167
+ assert attachment_id != nil, "Expected attachment to include an id or name field"
74
168
 
75
- response = client.messages.fetch_message_attachments(domain: domain_name, messageId: ENV["MAILINATOR_TEST_MESSAGE_WITH_ATTACHMENT_ID"])
169
+ response = @client.messages.fetch_message_attachments(
170
+ domain: @domain_name,
171
+ messageId: ENV["MAILINATOR_TEST_MESSAGE_WITH_ATTACHMENT_ID"]
172
+ )
76
173
  assert response != nil, "Expected fetch message attachments response to not be nil"
77
174
 
78
- response = client.messages.fetch_inbox_message_attachment(
79
- domain: domain_name,
175
+ response = @client.messages.fetch_inbox_message_attachment(
176
+ domain: @domain_name,
80
177
  inbox: ENV["MAILINATOR_TEST_INBOX"],
81
178
  messageId: ENV["MAILINATOR_TEST_MESSAGE_WITH_ATTACHMENT_ID"],
82
- attachmentId: ENV["MAILINATOR_TEST_ATTACHMENT_ID"]
179
+ attachmentId: attachment_id
83
180
  )
84
181
  assert response != nil, "Expected fetch inbox message attachment response to not be nil"
85
182
 
86
- response = client.messages.fetch_message_attachment(
87
- domain: domain_name,
183
+ response = @client.messages.fetch_message_attachment(
184
+ domain: @domain_name,
88
185
  messageId: ENV["MAILINATOR_TEST_MESSAGE_WITH_ATTACHMENT_ID"],
89
- attachmentId: ENV["MAILINATOR_TEST_ATTACHMENT_ID"]
186
+ attachmentId: attachment_id
90
187
  )
91
188
  assert response != nil, "Expected fetch message attachment response to not be nil"
189
+ end
190
+
191
+ def test_links_and_logs
192
+ require_env!("MAILINATOR_TEST_API_TOKEN")
193
+
194
+ response = @client.messages.fetch_inbox(
195
+ domain: @domain_name,
196
+ inbox: @inbox_all,
197
+ skip: 0,
198
+ limit: 1,
199
+ sort: "ascending",
200
+ decodeSubject: false
201
+ )
202
+ message_id = response["msgs"][0]["id"]
92
203
 
93
- response = client.messages.fetch_message_links_full(domain: domain_name, messageId: message_id)
204
+ response = @client.messages.fetch_message_links_full(domain: @domain_name, messageId: message_id)
94
205
  assert response != nil, "Expected fetch message links full response to not be nil"
95
206
  assert response["links"] != nil, "Expected fetch message links links full response to not be nil"
96
207
 
97
- response = client.messages.fetch_message_links(domain: domain_name, messageId: message_id)
208
+ response = @client.messages.fetch_message_links(domain: @domain_name, messageId: message_id)
98
209
  assert response != nil, "Expected fetch message links response to not be nil"
99
210
  assert response["links"] != nil, "Expected fetch message links links response to not be nil"
100
211
 
101
- response = client.messages.fetch_inbox_message_links(domain: domain_name, inbox: inbox_all, messageId: message_id)
212
+ response = @client.messages.fetch_inbox_message_links(domain: @domain_name, inbox: @inbox_all, messageId: message_id)
102
213
  assert response != nil, "Expected fetch inbox message links response to not be nil"
103
214
  assert response["links"] != nil, "Expected fetch inbox message links links response to not be nil"
104
215
 
105
- response = client.messages.fetch_message_smtp_log(domain: domain_name, messageId: message_id)
216
+ response = @client.messages.fetch_message_smtp_log(domain: @domain_name, messageId: message_id)
106
217
  assert response != nil, "Expected fetch message smtp log response to not be nil"
107
218
 
108
- response = client.messages.fetch_inbox_message_smtp_log(domain: domain_name, inbox: inbox_all, messageId: message_id)
219
+ response = @client.messages.fetch_inbox_message_smtp_log(domain: @domain_name, inbox: @inbox_all, messageId: message_id)
109
220
  assert response != nil, "Expected fetch inbox message smtp log response to not be nil"
221
+ end
110
222
 
111
- response = client.messages.fetch_message_raw(domain: domain_name, messageId: message_id)
223
+ def test_raw_message_variants
224
+ require_env!("MAILINATOR_TEST_API_TOKEN")
225
+
226
+ response = @client.messages.fetch_inbox(
227
+ domain: @domain_name,
228
+ inbox: @inbox_all,
229
+ skip: 0,
230
+ limit: 1,
231
+ sort: "ascending",
232
+ decodeSubject: false
233
+ )
234
+ message_id = response["msgs"][0]["id"]
235
+
236
+ response = @client.messages.fetch_message_raw(domain: @domain_name, messageId: message_id)
112
237
  assert response != nil, "Expected fetch message raw response to not be nil"
113
238
 
114
- response = client.messages.fetch_inbox_message_raw(domain: domain_name, inbox: inbox_all, messageId: message_id)
239
+ response = @client.messages.fetch_inbox_message_raw(domain: @domain_name, inbox: @inbox_all, messageId: message_id)
115
240
  assert response != nil, "Expected fetch inbox message raw response to not be nil"
241
+ end
116
242
 
117
- warn "Skipping legacy non-spec endpoints: messages.fetch_latest_messages / messages.fetch_latest_inbox_messages"
243
+ def test_delete_domain_flows
244
+ require_env!("MAILINATOR_TEST_API_TOKEN")
118
245
 
119
246
  delete_domain = ENV["MAILINATOR_TEST_DELETE_DOMAIN"]
120
247
  if delete_domain.to_s.strip.empty?
121
248
  warn "Skipping delete-domain checks: MAILINATOR_TEST_DELETE_DOMAIN is not set"
122
- else
123
- response = client.messages.delete_message(domain: delete_domain, inbox: ENV["MAILINATOR_TEST_INBOX"], messageId: message_id)
124
- assert response != nil, "Expected delete message response to not be nil"
125
- assert response["status"] == "ok", "Expected delete message response to be ok"
126
-
127
- response = client.messages.delete_all_inbox_messages(domain: delete_domain, inbox: ENV["MAILINATOR_TEST_INBOX"])
128
- assert response != nil, "Expected delete all inbox messages response to not be nil"
129
- assert response["status"] == "ok", "Expected delete all inbox messages response to be ok"
130
-
131
- response = client.messages.delete_all_domain_messages(domain: delete_domain)
132
- assert response != nil, "Expected delete all domain messages response to not be nil"
133
- assert response["status"] == "ok", "Expected delete all domain messages response to be ok"
249
+ return
134
250
  end
251
+
252
+ response = @client.messages.fetch_inbox(
253
+ domain: @domain_name,
254
+ inbox: @inbox_all,
255
+ skip: 0,
256
+ limit: 1,
257
+ sort: "ascending",
258
+ decodeSubject: false
259
+ )
260
+ message_id = response["msgs"][0]["id"]
261
+
262
+ response = @client.messages.delete_message(domain: delete_domain, inbox: ENV["MAILINATOR_TEST_INBOX"], messageId: message_id)
263
+ assert response != nil, "Expected delete message response to not be nil"
264
+ assert response["status"] == "ok", "Expected delete message response to be ok"
265
+
266
+ response = @client.messages.delete_all_inbox_messages(domain: delete_domain, inbox: ENV["MAILINATOR_TEST_INBOX"])
267
+ assert response != nil, "Expected delete all inbox messages response to not be nil"
268
+ assert response["status"] == "ok", "Expected delete all inbox messages response to be ok"
269
+
270
+ response = @client.messages.delete_all_domain_messages(domain: delete_domain)
271
+ assert response != nil, "Expected delete all domain messages response to not be nil"
272
+ assert response["status"] == "ok", "Expected delete all domain messages response to be ok"
135
273
  end
136
274
  end
@@ -0,0 +1,30 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/test_helper")
2
+
3
+ class MessagesHeadersApiTest < Minitest::Test
4
+ def test_fetch_message_headers_endpoint
5
+ require_env!(
6
+ "MAILINATOR_TEST_API_TOKEN",
7
+ "MAILINATOR_TEST_MESSAGE_WITH_ATTACHMENT_ID"
8
+ )
9
+
10
+ client = integration_client
11
+ domain_name = ENV["MAILINATOR_TEST_DOMAIN"].to_s.strip
12
+ domain_name = first_domain_name(client) if domain_name.empty?
13
+
14
+ response = client.messages.fetch_message_headers(
15
+ domain: domain_name,
16
+ messageId: ENV["MAILINATOR_TEST_MESSAGE_WITH_ATTACHMENT_ID"]
17
+ ) rescue begin
18
+ e = $!
19
+ if e.is_a?(MailinatorClient::ResponseError)
20
+ flunk "Expected HTTP 200 from message headers endpoint, got HTTP #{e.code}"
21
+ end
22
+ raise
23
+ end
24
+
25
+ assert_kind_of(Hash, response, "Expected message headers response to be a JSON object")
26
+ assert_equal(["headers"], response.keys.sort, "Expected only the headers property")
27
+ assert response["headers"].is_a?(Hash), "Expected headers to be a JSON object"
28
+ assert response["headers"]["subject"] != nil, "Expected headers.subject to not be nil"
29
+ end
30
+ end
@@ -2,53 +2,75 @@ require File.expand_path(File.dirname(__FILE__) + "/test_helper")
2
2
 
3
3
  class MessagesQueryParamsTest < Minitest::Test
4
4
  def test_fetch_inbox_message_accepts_optional_delete
5
- client = MailinatorClient::Client.new(auth_token: "test-token")
6
- request = stub_request(:get, "https://api.mailinator.com/api/v2/domains/private.example/inboxes/inbox/messages/msg-123")
7
- .with(query: { "delete" => "10s" })
8
- .to_return(status: 200, body: "{}", headers: { "Content-Type" => "application/json" })
5
+ require_env!(
6
+ "MAILINATOR_TEST_API_TOKEN",
7
+ "MAILINATOR_TEST_INBOX"
8
+ )
9
9
 
10
- response = client.messages.fetch_inbox_message(
11
- domain: "private.example",
12
- inbox: "inbox",
13
- messageId: "msg-123",
14
- delete: "10s"
10
+ client = integration_client
11
+ domain_name = ENV["MAILINATOR_TEST_DOMAIN"].to_s.strip
12
+ domain_name = first_domain_name(client) if domain_name.empty?
13
+
14
+ message_to_post = {
15
+ subject: "Query param delete test",
16
+ from: "test_email_ruby@test.com",
17
+ text: "Delete param integration test"
18
+ }
19
+ post_response = client.messages.post_message(
20
+ domain: domain_name,
21
+ inbox: "*",
22
+ messageToPost: message_to_post
15
23
  )
24
+ message_id = post_response["id"]
25
+ assert message_id != nil, "Expected posted message id to not be nil"
26
+
27
+ response = client.messages.fetch_inbox_message(
28
+ domain: domain_name,
29
+ inbox: "*",
30
+ messageId: message_id,
31
+ delete: "1m"
32
+ ) rescue begin
33
+ e = $!
34
+ if e.is_a?(MailinatorClient::ResponseError)
35
+ flunk "Expected HTTP 200 for fetch_inbox_message with delete param, got HTTP #{e.code}"
36
+ end
37
+ raise
38
+ end
16
39
 
17
- assert_equal({}, response)
18
- assert_requested(request, times: 1)
40
+ assert_kind_of(Hash, response, "Expected JSON object response for fetch_inbox_message")
41
+ returned_id = response["id"] || response["mrid"]
42
+ assert returned_id != nil, "Expected message id in fetch_inbox_message response"
43
+ assert_equal(message_id, returned_id, "Expected returned message id to match requested message id")
19
44
  end
20
45
 
21
46
  def test_fetch_sms_message_supports_inbox_list_query_params
22
- client = MailinatorClient::Client.new(auth_token: "test-token")
23
- request = stub_request(:get, "https://api.mailinator.com/api/v2/domains/private.example/inboxes/15555550123")
24
- .with(
25
- query: {
26
- "skip" => "5",
27
- "limit" => "10",
28
- "sort" => "descending",
29
- "decode_subject" => "true",
30
- "cursor" => "cursor-1",
31
- "full" => "true",
32
- "delete" => "30s",
33
- "wait" => "20s"
34
- }
35
- )
36
- .to_return(status: 200, body: "{\"msgs\":[]}", headers: { "Content-Type" => "application/json" })
47
+ require_env!(
48
+ "MAILINATOR_TEST_API_TOKEN",
49
+ "MAILINATOR_TEST_PHONE_NUMBER"
50
+ )
51
+
52
+ client = integration_client
53
+ domain_name = ENV["MAILINATOR_TEST_DOMAIN"].to_s.strip
54
+ domain_name = first_domain_name(client) if domain_name.empty?
37
55
 
38
56
  response = client.messages.fetch_sms_message(
39
- domain: "private.example",
40
- teamSmsNumber: "15555550123",
41
- skip: 5,
57
+ domain: domain_name,
58
+ teamSmsNumber: ENV["MAILINATOR_TEST_PHONE_NUMBER"],
59
+ skip: 0,
42
60
  limit: 10,
43
61
  sort: "descending",
44
62
  decode_subject: true,
45
- cursor: "cursor-1",
46
- full: true,
47
- delete: "30s",
48
- wait: "20s"
49
- )
63
+ full: false
64
+ ) rescue begin
65
+ e = $!
66
+ if e.is_a?(MailinatorClient::ResponseError)
67
+ flunk "Expected HTTP 200 for fetch_sms_message query params flow, got HTTP #{e.code}"
68
+ end
69
+ raise
70
+ end
50
71
 
51
- assert_equal({ "msgs" => [] }, response)
52
- assert_requested(request, times: 1)
72
+ assert_kind_of(Hash, response, "Expected JSON object response for fetch_sms_message")
73
+ assert response.key?("msgs"), "Expected msgs key in fetch_sms_message response"
74
+ assert_kind_of(Array, response["msgs"], "Expected msgs to be an array")
53
75
  end
54
76
  end
@@ -0,0 +1,39 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/test_helper")
2
+ require "timeout"
3
+
4
+ class MessagesStreamDomainApiTest < Minitest::Test
5
+ def test_stream_domain_messages_endpoint
6
+ require_env!("MAILINATOR_TEST_API_TOKEN")
7
+
8
+ client = integration_client
9
+ domain_name = "private"
10
+
11
+ response = nil
12
+ # This test requires a real email to arrive while the stream is open.
13
+ stream_thread = Thread.new do
14
+ client.messages.stream_domain_messages(
15
+ domain: domain_name,
16
+ limit: 1,
17
+ throttleInterval: 1000
18
+ )
19
+ end
20
+
21
+ response = Timeout.timeout(20) do
22
+ stream_thread.value
23
+ end rescue begin
24
+ e = $!
25
+ if e.is_a?(Timeout::Error)
26
+ flunk "Expected stream domain messages to return within timeout"
27
+ end
28
+ if e.is_a?(MailinatorClient::ResponseError)
29
+ flunk "Expected HTTP 200 from stream domain messages endpoint, got HTTP #{e.code}"
30
+ end
31
+ raise
32
+ end
33
+
34
+ assert_kind_of(Hash, response, "Expected stream response to be a JSON object")
35
+ assert response.key?("domain"), "Expected response to include domain"
36
+ assert response.key?("to"), "Expected response to include to"
37
+ assert response.key?("msgs"), "Expected response to include msgs"
38
+ end
39
+ end
@@ -0,0 +1,40 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/test_helper")
2
+ require "timeout"
3
+
4
+ class MessagesStreamInboxApiTest < Minitest::Test
5
+ def test_stream_inbox_messages_endpoint
6
+ require_env!("MAILINATOR_TEST_API_TOKEN", "MAILINATOR_TEST_INBOX")
7
+
8
+ client = integration_client
9
+ domain_name = "private"
10
+ inbox_name = ENV["MAILINATOR_TEST_INBOX"]
11
+
12
+ response = nil
13
+ # This test requires a real email to arrive while the stream is open.
14
+ stream_thread = Thread.new do
15
+ client.messages.stream_inbox_messages(
16
+ domain: domain_name,
17
+ inbox: inbox_name,
18
+ limit: 1,
19
+ throttleInterval: 1000
20
+ )
21
+ end
22
+
23
+ response = Timeout.timeout(20) do
24
+ stream_thread.value
25
+ end rescue begin
26
+ e = $!
27
+ if e.is_a?(Timeout::Error)
28
+ flunk "Expected stream inbox messages to return within timeout"
29
+ end
30
+ if e.is_a?(MailinatorClient::ResponseError)
31
+ flunk "Expected HTTP 200 from stream inbox messages endpoint, got HTTP #{e.code}"
32
+ end
33
+ raise
34
+ end
35
+
36
+ assert_kind_of(Hash, response, "Expected stream response to be a JSON object")
37
+ assert response.key?("to"), "Expected response to include to"
38
+ assert response.key?("msgs"), "Expected response to include msgs"
39
+ end
40
+ end
@@ -0,0 +1,28 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/test_helper")
2
+
3
+ class MessagesSummaryApiTest < Minitest::Test
4
+ def test_fetch_message_summary_endpoint
5
+ require_env!(
6
+ "MAILINATOR_TEST_API_TOKEN",
7
+ "MAILINATOR_TEST_MESSAGE_WITH_ATTACHMENT_ID"
8
+ )
9
+
10
+ client = integration_client
11
+ domain_name = ENV["MAILINATOR_TEST_DOMAIN"].to_s.strip
12
+ domain_name = first_domain_name(client) if domain_name.empty?
13
+
14
+ response = client.messages.fetch_message_summary(
15
+ domain: domain_name,
16
+ messageId: ENV["MAILINATOR_TEST_MESSAGE_WITH_ATTACHMENT_ID"]
17
+ ) rescue begin
18
+ e = $!
19
+ if e.is_a?(MailinatorClient::ResponseError)
20
+ flunk "Expected HTTP 200 from message summary endpoint, got HTTP #{e.code}"
21
+ end
22
+ raise
23
+ end
24
+
25
+ assert_kind_of(Hash, response, "Expected message summary endpoint to return a JSON object")
26
+ assert_equal(["summary"], response.keys.sort, "Expected only the summary property")
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/test_helper")
2
+
3
+ class MessagesTextApiTest < Minitest::Test
4
+ def test_fetch_message_text_endpoint
5
+ require_env!(
6
+ "MAILINATOR_TEST_API_TOKEN",
7
+ "MAILINATOR_TEST_MESSAGE_WITH_ATTACHMENT_ID"
8
+ )
9
+
10
+ client = integration_client
11
+ domain_name = ENV["MAILINATOR_TEST_DOMAIN"].to_s.strip
12
+ domain_name = first_domain_name(client) if domain_name.empty?
13
+
14
+ response = client.messages.fetch_message_text(
15
+ domain: domain_name,
16
+ messageId: ENV["MAILINATOR_TEST_MESSAGE_WITH_ATTACHMENT_ID"]
17
+ ) rescue begin
18
+ e = $!
19
+ if e.is_a?(MailinatorClient::ResponseError)
20
+ flunk "Expected HTTP 200 from message text endpoint, got HTTP #{e.code}"
21
+ end
22
+ raise
23
+ end
24
+
25
+ assert_kind_of(Hash, response, "Expected message text response to be a JSON object")
26
+ assert_equal(["text"], response.keys.sort, "Expected only the text property")
27
+ end
28
+ end