mirror of
https://github.com/internetee/registry.git
synced 2025-07-21 02:05:57 +02:00
Bounces: Fix tests
This commit is contained in:
parent
98674ab381
commit
3222a8b9a7
4 changed files with 58 additions and 86 deletions
|
@ -1,11 +1,8 @@
|
|||
class BouncedMailAddress < ApplicationRecord
|
||||
validates :email, :message_id, :bounce_type, :bounce_subtype, :action, :status, presence: true
|
||||
before_validation :assign_bounce_reason
|
||||
|
||||
def assign_bounce_reason
|
||||
return self.bounce_reason = nil unless recipient_json
|
||||
|
||||
self.bounce_reason = "#{action} (#{status} #{diagnostic})"
|
||||
def bounce_reason
|
||||
"#{action} (#{status} #{diagnostic})"
|
||||
end
|
||||
|
||||
def self.record(json)
|
||||
|
@ -17,7 +14,7 @@ class BouncedMailAddress < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def params_from_json(json, bounced_record)
|
||||
def self.params_from_json(json, bounced_record)
|
||||
{
|
||||
email: bounced_record['emailAddress'],
|
||||
message_id: json['mail']['messageId'],
|
||||
|
|
41
test/fixtures/bounced_mail_addresses.yml
vendored
41
test/fixtures/bounced_mail_addresses.yml
vendored
|
@ -1,39 +1,10 @@
|
|||
one:
|
||||
email: bounced@registry.test
|
||||
bounce_reason: failed (5.1.1 smtp; 550 5.1.1 user unknown)
|
||||
recipient_json: {
|
||||
"action": "failed",
|
||||
"status": "5.1.1",
|
||||
"emailAddress": "bounced@registry.test",
|
||||
"diagnosticCode": "smtp; 550 5.1.1 user unknown"
|
||||
}
|
||||
response_json: {
|
||||
"notificationType": "Bounce",
|
||||
"mail": {
|
||||
"source": "noreply@registry.test",
|
||||
"sourceIp": "195.43.86.5",
|
||||
"messageId": "010f0174a0c7d348-ea6e2fc1-0854-4073-b71f-5cecf9b0d0b2-000000",
|
||||
"sourceArn": "arn:aws:ses:us-east-2:65026820000:identity/noreply@registry.test",
|
||||
"timestamp": "2020-09-18T10:34:44.000Z",
|
||||
"destination": [ "bounced@registry.test" ],
|
||||
"sendingAccountId": "650268220000"
|
||||
},
|
||||
"bounce": {
|
||||
"timestamp": "2020-09-18T10:34:44.911Z",
|
||||
"bounceType": "Permanent",
|
||||
"feedbackId": "010f0174a0c7d4f9-27d59756-6111-4d5f-xxxx-26bee0d55fa2-000000",
|
||||
"remoteMtaIp": "127.0.01",
|
||||
"reportingMTA": "dsn; xxx.amazonses.com",
|
||||
"bounceSubType": "General",
|
||||
"bouncedRecipients": [
|
||||
{
|
||||
"action": "failed",
|
||||
"status": "5.1.1",
|
||||
"emailAddress": "bounced@registry.test",
|
||||
"diagnosticCode": "smtp; 550 5.1.1 user unknown"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
message_id: 010f0174a0c7d348-ea6e2fc1-0854-4073-b71f-5cecf9b0d0b2-000000
|
||||
bounce_type: Permanent
|
||||
bounce_subtype: General
|
||||
action: failed
|
||||
status: '5.1.1'
|
||||
diagnostic: 'smtp; 550 5.1.1 user unknown'
|
||||
created_at: <%= Time.zone.parse('2010-07-05').to_s(:db) %>
|
||||
updated_at: <%= Time.zone.parse('2010-07-05').to_s(:db) %>
|
||||
|
|
|
@ -6,56 +6,61 @@ class BouncedMailAddressTest < ActiveSupport::TestCase
|
|||
def setup
|
||||
@bounced_mail = BouncedMailAddress.new
|
||||
@bounced_mail.email = 'recipient@registry.test'
|
||||
@bounced_mail.bounce_reason = 'failed (5.1.1 smtp; 550 5.1.1 user unknown)'
|
||||
@bounced_mail.response_json = {"mail"=>{"source"=>"noreply@internet.test", "sourceIp"=>"195.43.86.5", "messageId"=>"010f0174a0c7d348-ea6e2fc1-0854-4073-b71f-5cecf9b0d0b2-000000", "sourceArn"=>"arn:aws:ses:us-east-2:650268220328:identity/noreply@internet.test", "timestamp"=>"2020-09-18T10:34:44.000Z", "destination"=>["#{@bounced_mail.email}"], "sendingAccountId"=>"650268220328"}, "bounce"=>{"timestamp"=>"2020-09-18T10:34:44.911Z", "bounceType"=>"Permanent", "feedbackId"=>"010f0174a0c7d4f9-27d59756-6111-xxxx-a507-26bee0d55fa2-000000", "remoteMtaIp"=>"127.0.0.1", "reportingMTA"=>"dsn; xxx.amazonses.com", "bounceSubType"=>"General", "bouncedRecipients"=>[{"action"=>"failed", "status"=>"5.1.1", "emailAddress"=>"#{@bounced_mail.email}", "diagnosticCode"=>"smtp; 550 5.1.1 user unknown"}]}, "notificationType"=>"Bounce"}
|
||||
@bounced_mail.recipient_json = {"action"=>"failed", "status"=>"5.1.1", "emailAddress"=>"#{@bounced_mail.email}", "diagnosticCode"=>"smtp; 550 5.1.1 user unknown"}
|
||||
|
||||
@bounced_mail.message_id = '010f0174a0c7d348-ea6e2fc1-0854-4073-b71f-5cecf9b0d0b2-000000'
|
||||
@bounced_mail.bounce_type = 'Permanent'
|
||||
@bounced_mail.bounce_subtype = 'General'
|
||||
@bounced_mail.action = 'failed'
|
||||
@bounced_mail.status = '5.1.1'
|
||||
@bounced_mail.diagnostic = 'smtp; 550 5.1.1 user unknown'
|
||||
end
|
||||
|
||||
def test_bounce_reason_is_autoassigned
|
||||
assert @bounced_mail.valid?
|
||||
@bounced_mail.bounce_reason = nil
|
||||
def test_email_is_required
|
||||
assert @bounced_mail.valid?
|
||||
@bounced_mail.email = nil
|
||||
assert @bounced_mail.invalid?
|
||||
end
|
||||
|
||||
def test_message_id_is_required
|
||||
assert @bounced_mail.valid?
|
||||
@bounced_mail.message_id = nil
|
||||
assert @bounced_mail.invalid?
|
||||
end
|
||||
|
||||
def test_bounce_type_is_required
|
||||
assert @bounced_mail.valid?
|
||||
@bounced_mail.bounce_type = nil
|
||||
assert @bounced_mail.invalid?
|
||||
end
|
||||
|
||||
def test_bounce_subtype_is_required
|
||||
assert @bounced_mail.valid?
|
||||
@bounced_mail.bounce_subtype = nil
|
||||
assert @bounced_mail.invalid?
|
||||
end
|
||||
|
||||
def test_action_is_required
|
||||
assert @bounced_mail.valid?
|
||||
@bounced_mail.action = nil
|
||||
assert @bounced_mail.invalid?
|
||||
end
|
||||
|
||||
def test_status_is_required
|
||||
assert @bounced_mail.valid?
|
||||
@bounced_mail.status = nil
|
||||
assert @bounced_mail.invalid?
|
||||
end
|
||||
|
||||
def test_diagnostic_is_not_required
|
||||
assert @bounced_mail.valid?
|
||||
@bounced_mail.diagnostic = nil
|
||||
assert @bounced_mail.valid?
|
||||
end
|
||||
|
||||
def test_bounce_reason_is_determined_dynamically
|
||||
assert @bounced_mail.valid?
|
||||
assert_equal 'failed (5.1.1 smtp; 550 5.1.1 user unknown)', @bounced_mail.bounce_reason
|
||||
end
|
||||
|
||||
def test_response_json_is_required
|
||||
assert @bounced_mail.valid?
|
||||
@bounced_mail.response_json = nil
|
||||
assert_not @bounced_mail.valid?
|
||||
assert @bounced_mail.errors.full_messages.include? 'Response json is missing'
|
||||
end
|
||||
|
||||
def test_recipient_json_is_required
|
||||
assert @bounced_mail.valid?
|
||||
@bounced_mail.recipient_json = nil
|
||||
assert_not @bounced_mail.valid?
|
||||
|
||||
assert @bounced_mail.errors.full_messages.include? 'Recipient json is missing'
|
||||
end
|
||||
|
||||
def test_status_is_determined_dynamically
|
||||
assert @bounced_mail.valid?
|
||||
assert_equal '5.1.1', @bounced_mail.status
|
||||
@bounced_mail.recipient_json['status'] = 'xxx_status'
|
||||
assert_equal 'xxx_status', @bounced_mail.status
|
||||
end
|
||||
|
||||
def test_action_is_determined_dynamically
|
||||
assert @bounced_mail.valid?
|
||||
assert_equal 'failed', @bounced_mail.action
|
||||
@bounced_mail.recipient_json['action'] = 'xxx_action'
|
||||
assert_equal 'xxx_action', @bounced_mail.action
|
||||
end
|
||||
|
||||
def test_diagnostic_is_determined_dynamically
|
||||
assert @bounced_mail.valid?
|
||||
assert_equal 'smtp; 550 5.1.1 user unknown', @bounced_mail.diagnostic
|
||||
@bounced_mail.recipient_json['diagnosticCode'] = 'xxx_diagnostic'
|
||||
assert_equal 'xxx_diagnostic', @bounced_mail.diagnostic
|
||||
end
|
||||
|
||||
def test_creates_objects_from_sns_json
|
||||
BouncedMailAddress.record(sns_bounce_payload)
|
||||
|
||||
|
|
|
@ -28,8 +28,7 @@ class AdminBouncedMailAddressesTest < ApplicationSystemTestCase
|
|||
assert_text @bounced_mail.diagnostic
|
||||
assert_text @bounced_mail.email
|
||||
|
||||
assert_text 'bouncedRecipients'
|
||||
assert_text '010f0174a0c7d4f9-27d59756-6111-4d5f-xxxx-26bee0d55fa2-000000'
|
||||
assert_text @bounced_mail.message_id
|
||||
end
|
||||
|
||||
def test_deletes_registrar
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue