-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathexample.spec.rb
60 lines (50 loc) · 1.76 KB
/
example.spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
RSpec.describe 'client' do
require 'mailslurp_client'
# configure the mailslurp client with an API Key
MailSlurpClient.configure do |config|
config.api_key['x-api-key'] = ENV['API_KEY']
end
it 'can create email addresses' do
inbox_controller = MailSlurpClient::InboxControllerApi.new
inbox = inbox_controller.create_inbox
expect(inbox.id).not_to be_nil
expect(inbox.email_address).to include("mailslurp.com")
end
it 'can send an email' do
# create an inbox
inbox_controller = MailSlurpClient::InboxControllerApi.new
inbox = inbox_controller.create_inbox
# send an email from the inbox (to the inbox's own address)
inbox_controller.send_email(inbox.id, {
send_email_options: {
to: [inbox.email_address],
subject: "Test",
isHTML: true,
body: <<-HEREDOC
<h1>Hello!</h1>
<p>MailSlurp supports HTML</p>
HEREDOC
}
})
end
it 'can receive emails and extract content' do
# create two inboxes
inbox_controller = MailSlurpClient::InboxControllerApi.new
inbox_1 = inbox_controller.create_inbox
inbox_2 = inbox_controller.create_inbox
# send an email from inbox 1 to inbox 2 (sends a real email)
inbox_controller.send_email(inbox_1.id, {
send_email_options: {
to: [inbox_2.email_address],
subject: "Test",
body: "Your code is 123",
}
})
# get emails from inbox2
waitfor_controller = MailSlurpClient::WaitForControllerApi.new
email = waitfor_controller.wait_for_latest_email({ inbox_id: inbox_2.id, unread_only: true })
# verify email contents
expect(email.subject).to include("Test")
expect(email.body).to include("Your code is")
end
end