refactored tests, changed condition for validate email data

This commit is contained in:
olegphenomenon 2021-10-15 14:55:49 +03:00
parent 3a8ab93dd7
commit 1048fbdd35
4 changed files with 36 additions and 7 deletions

View file

@ -9,12 +9,20 @@ module EmailVerifable
need_to_start_force_delete?
end
def need_to_start_force_delete?
ValidationEvent::INVALID_EVENTS_COUNT_BY_LEVEL.any? do |level, count|
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.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?

View file

@ -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

View file

@ -136,6 +136,7 @@ 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?

View file

@ -20,7 +20,9 @@ class ValidationEventTest < ActiveSupport::TestCase
contact = @domain.admin_contacts.first
contact.update_attribute(:email, 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?