mirror of
https://github.com/internetee/registry.git
synced 2025-06-06 20:55:44 +02:00
refactored tests, changed condition for validate email data
This commit is contained in:
parent
3a8ab93dd7
commit
1048fbdd35
4 changed files with 36 additions and 7 deletions
|
@ -9,12 +9,20 @@ module EmailVerifable
|
||||||
need_to_start_force_delete?
|
need_to_start_force_delete?
|
||||||
end
|
end
|
||||||
|
|
||||||
def need_to_start_force_delete?
|
def validate_email_data(level:, count:)
|
||||||
ValidationEvent::INVALID_EVENTS_COUNT_BY_LEVEL.any? do |level, count|
|
|
||||||
validation_events.recent.order(id: :desc).limit(count).all? do |event|
|
validation_events.recent.order(id: :desc).limit(count).all? do |event|
|
||||||
event.check_level == level.to_s && event.failed?
|
event.check_level == level.to_s && event.failed?
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
def need_to_lift_force_delete?
|
def need_to_lift_force_delete?
|
||||||
|
|
|
@ -50,7 +50,7 @@ def prepare_contacts(options)
|
||||||
if options[:domain_name].present?
|
if options[:domain_name].present?
|
||||||
contacts_by_domain(options[:domain_name])
|
contacts_by_domain(options[:domain_name])
|
||||||
else
|
else
|
||||||
Contact.recently_not_validated
|
Contact.all
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ def contacts_by_domain(domain_name)
|
||||||
domain = ::Domain.find_by(name: domain_name)
|
domain = ::Domain.find_by(name: domain_name)
|
||||||
return unless domain
|
return unless domain
|
||||||
|
|
||||||
domain.contacts.recently_not_validated
|
domain.contacts
|
||||||
end
|
end
|
||||||
|
|
||||||
def opts_hash
|
def opts_hash
|
||||||
|
|
|
@ -136,6 +136,7 @@ class BouncedMailAddressTest < ActiveSupport::TestCase
|
||||||
BouncedMailAddress.record(sns_bounce_payload)
|
BouncedMailAddress.record(sns_bounce_payload)
|
||||||
bounced_mail = BouncedMailAddress.last
|
bounced_mail = BouncedMailAddress.last
|
||||||
registrant = domains(:shop).registrant
|
registrant = domains(:shop).registrant
|
||||||
|
registrant.verify_email(check_level: 'smtp')
|
||||||
|
|
||||||
assert_equal registrant.email, bounced_mail.email
|
assert_equal registrant.email, bounced_mail.email
|
||||||
assert registrant.email_verification_failed?
|
assert registrant.email_verification_failed?
|
||||||
|
|
|
@ -20,7 +20,9 @@ class ValidationEventTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
contact = @domain.admin_contacts.first
|
contact = @domain.admin_contacts.first
|
||||||
contact.update_attribute(:email, email)
|
contact.update_attribute(:email, email)
|
||||||
|
(ValidationEvent::VALID_EVENTS_COUNT_THRESHOLD).times do
|
||||||
contact.verify_email
|
contact.verify_email
|
||||||
|
end
|
||||||
contact.reload
|
contact.reload
|
||||||
|
|
||||||
refute contact.validation_events.last.success?
|
refute contact.validation_events.last.success?
|
||||||
|
@ -42,6 +44,24 @@ class ValidationEventTest < ActiveSupport::TestCase
|
||||||
assert contact.validation_events.last.success?
|
assert contact.validation_events.last.success?
|
||||||
end
|
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
|
def test_if_fd_need_to_be_set_if_invalid_mx
|
||||||
@domain.update(valid_to: Time.zone.parse('2012-08-05'))
|
@domain.update(valid_to: Time.zone.parse('2012-08-05'))
|
||||||
assert_not @domain.force_delete_scheduled?
|
assert_not @domain.force_delete_scheduled?
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue