diff --git a/app/models/concerns/email_verifable.rb b/app/models/concerns/email_verifable.rb index 02bd8daef..54a945ef8 100644 --- a/app/models/concerns/email_verifable.rb +++ b/app/models/concerns/email_verifable.rb @@ -9,12 +9,20 @@ module EmailVerifable need_to_start_force_delete? end + def validate_email_data(level:, count:) + validation_events.recent.order(id: :desc).limit(count).all? do |event| + event.check_level == level.to_s && event.failed? + end + end + def need_to_start_force_delete? - ValidationEvent::INVALID_EVENTS_COUNT_BY_LEVEL.any? do |level, count| - validation_events.recent.order(id: :desc).limit(count).all? do |event| - event.check_level == level.to_s && event.failed? + ValidationEvent::INVALID_EVENTS_COUNT_BY_LEVEL.each do |level, count| + if validation_events.recent.count >= count && validate_email_data(level: level, count: count) + return true end end + + false end def need_to_lift_force_delete? diff --git a/lib/tasks/verify_email.rake b/lib/tasks/verify_email.rake index af96aa1d4..9ca38199f 100644 --- a/lib/tasks/verify_email.rake +++ b/lib/tasks/verify_email.rake @@ -50,7 +50,7 @@ def prepare_contacts(options) if options[:domain_name].present? contacts_by_domain(options[:domain_name]) else - Contact.recently_not_validated + Contact.all end end @@ -58,7 +58,7 @@ def contacts_by_domain(domain_name) domain = ::Domain.find_by(name: domain_name) return unless domain - domain.contacts.recently_not_validated + domain.contacts end def opts_hash diff --git a/test/models/bounced_mail_address_test.rb b/test/models/bounced_mail_address_test.rb index de7371060..2f266f8bd 100644 --- a/test/models/bounced_mail_address_test.rb +++ b/test/models/bounced_mail_address_test.rb @@ -136,7 +136,8 @@ class BouncedMailAddressTest < ActiveSupport::TestCase BouncedMailAddress.record(sns_bounce_payload) bounced_mail = BouncedMailAddress.last registrant = domains(:shop).registrant - + registrant.verify_email(check_level: 'smtp') + assert_equal registrant.email, bounced_mail.email assert registrant.email_verification_failed? end diff --git a/test/models/validation_event_test.rb b/test/models/validation_event_test.rb index 722a35340..4f2ba7366 100644 --- a/test/models/validation_event_test.rb +++ b/test/models/validation_event_test.rb @@ -20,7 +20,9 @@ class ValidationEventTest < ActiveSupport::TestCase contact = @domain.admin_contacts.first contact.update_attribute(:email, email) - contact.verify_email + (ValidationEvent::VALID_EVENTS_COUNT_THRESHOLD).times do + contact.verify_email + end contact.reload refute contact.validation_events.last.success? @@ -42,6 +44,24 @@ class ValidationEventTest < ActiveSupport::TestCase assert contact.validation_events.last.success? end + def test_fd_didnt_set_if_mx_interation_less_then_value + @domain.update(valid_to: Time.zone.parse('2012-08-05')) + assert_not @domain.force_delete_scheduled? + travel_to Time.zone.parse('2010-07-05') + + email = 'email@somestrangedomain12345.ee' + contact = @domain.admin_contacts.first + contact.update_attribute(:email, email) + (ValidationEvent::VALID_EVENTS_COUNT_THRESHOLD - 1).times do + contact.verify_email(check_level: 'mx') + end + contact.reload + + refute contact.validation_events.limit(ValidationEvent::VALID_EVENTS_COUNT_THRESHOLD) + .any?(&:success?) + assert_not contact.need_to_start_force_delete? + end + def test_if_fd_need_to_be_set_if_invalid_mx @domain.update(valid_to: Time.zone.parse('2012-08-05')) assert_not @domain.force_delete_scheduled?