Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Record the SES Message ID in the header :ses_message_id #25

Merged
merged 3 commits into from
Feb 13, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/aws/rails/mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ def deliver!(message)
send_opts[:destinations] = message.destinations
end

@client.send_raw_email(send_opts)

@client.send_raw_email(send_opts).tap do |response|
message.header[:ses_message_id] = response.message_id
end
end

# ActionMailer expects this method to be present and to return a hash.
Expand Down
20 changes: 16 additions & 4 deletions test/aws/rails/mailer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@ module Rails
class MailerTest < Minitest::Test

def setup
@mailer = Mailer.new(stub_responses: true)
@mailer = Mailer.new(
stub_responses: {
send_raw_email: {
message_id: message_id
}
}
)
end

def message_id
'0000000000000000-1111111-2222-3333-4444-555555555555-666666'
end

def sample_message
Expand All @@ -25,9 +35,11 @@ def test_settings_method

def test_deliver
message = sample_message
resp = @mailer.deliver!(message)
assert_equal resp.context.params[:raw_message][:data].to_s, message.to_s
assert_equal resp.context.params[:destinations], message.destinations
data = @mailer.deliver!(message).context.params
body = data[:raw_message][:data].to_s
body.gsub!("\r\nHallo", "ses-message-id: #{message_id}\r\n\r\nHallo")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd actually like the test to mimic the behavior pattern you showed in the PR description. Perhaps retrieve the message body and message headers like a user would?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, that’s pushed.

assert_equal body, message.to_s
assert_equal data[:destinations], message.destinations
end

end
Expand Down