From e843b7293be9bb9771434741f87688c884f43496 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Fri, 9 Apr 2021 13:19:11 +0500 Subject: [PATCH] Add check for bounce presence in #failed? method of verification --- app/models/email_address_verification.rb | 6 +++++- test/models/bounced_mail_address_test.rb | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/models/email_address_verification.rb b/app/models/email_address_verification.rb index c54cd4224..4eba0f3e9 100644 --- a/app/models/email_address_verification.rb +++ b/app/models/email_address_verification.rb @@ -34,13 +34,17 @@ class EmailAddressVerification < ApplicationRecord end def failed? - verified_at.present? && !success + bounce_present? || (verified_at.present? && !success) end def verified? success end + def bounce_present? + BouncedMailAddress.find_by(email: email).present? + end + def check_force_delete return unless failed? diff --git a/test/models/bounced_mail_address_test.rb b/test/models/bounced_mail_address_test.rb index a7288cd01..2a24c00b0 100644 --- a/test/models/bounced_mail_address_test.rb +++ b/test/models/bounced_mail_address_test.rb @@ -117,6 +117,15 @@ class BouncedMailAddressTest < ActiveSupport::TestCase assert_equal 'smtp; 550 5.1.1 user unknown', bounced_mail.diagnostic end + def test_email_with_bounce_considered_nonverified + BouncedMailAddress.record(sns_bounce_payload) + bounced_mail = BouncedMailAddress.last + registrant = domains(:shop).registrant + + assert_equal registrant.email, bounced_mail.email + assert registrant.email_verification.failed? + end + def sns_bounce_payload { "notificationType": "Bounce",