Skip to content

Commit

Permalink
Merge pull request #252 from internetee/fix_contact_request_readonly
Browse files Browse the repository at this point in the history
Allow saving of contact request AWS message_id
  • Loading branch information
vohmar authored Mar 9, 2021
2 parents 7609de0 + 6f831b0 commit 9c59768
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/mailers/contact_request_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def ses_contact_email(contact_request:, recipients:, mail_body:)
@domain = contact_request.whois_record.name
begin
resp = Aws::SES::Client.new.send_email(ses_request_body(recipients))
contact_request.update(message_id: resp[:message_id])
contact_request.update_registry_message_id(resp[:message_id])
logger.warn("Contact email sent to #{recipients} from #{@contact_request.email}.")
rescue Aws::SES::Errors::ServiceError => e
logger.warn("Email not sent. Error message: #{e}")
Expand Down
7 changes: 7 additions & 0 deletions app/models/contact_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ def update_registry_status(status:, ip:)
RegistryConnector.do_update(id: id, data: data)
end

def update_registry_message_id(message_id)
data = {
message_id: message_id,
}
RegistryConnector.do_update(id: id, data: data)
end

def send_confirmation_email
ContactRequestMailer.confirmation_email(self).deliver_now
end
Expand Down
1 change: 0 additions & 1 deletion app/services/registry_connector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def self.do_save(data)
url = BASE_URL
request = request(url: url, type: :post)
request.body = { contact_request: data }.to_json
# binding.pry
perform_request(request, url)
rescue CommunicationError
false
Expand Down
5 changes: 4 additions & 1 deletion test/mailers/contact_request_mailer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
class ContactRequestMailerTest < ActionMailer::TestCase
def setup
@contact_request = contact_requests(:valid)
stub_request(:put, /http:\/\/registry:3000\/api\/v1\/contact_requests\/\d+/).to_return(status: 200, body: @contact_request.to_json, headers: {})
end

def test_confirmation_email
Expand Down Expand Up @@ -119,6 +120,8 @@ def test_contact_request_email_cuts_off_message_at_2000_characters
end

def test_attempts_to_send_contact_email_via_aws_ses
@contact_request.message_id = 'TESTING'
stub_request(:put, /http:\/\/registry:3000\/api\/v1\/contact_requests\/\d+/).to_return(status: 200, body: @contact_request.to_json, headers: {})
mail_body = begin
"Hi!\n" \
"\n" \
Expand All @@ -132,7 +135,7 @@ def test_attempts_to_send_contact_email_via_aws_ses
region: 'us-east-2',
credentials: Aws::Credentials.new('123', '123'),
stub_responses: {
send_email: { message_id: 'TESTING' }}
send_email: { message_id: @contact_request.message_id }}
)

ApplicationMailer.stub(:ses_configured?, true) do
Expand Down

0 comments on commit 9c59768

Please sign in to comment.