mirror of
https://github.com/internetee/registry.git
synced 2025-06-07 21:25:39 +02:00
fixed error
This commit is contained in:
parent
8524503582
commit
2543b9c1f8
6 changed files with 20 additions and 155 deletions
|
@ -10,7 +10,7 @@ module EmailVerifable
|
|||
end
|
||||
|
||||
def validate_email_data(level:, count:)
|
||||
validation_events.recent.order(id: :desc).limit(count).all? do |event|
|
||||
validation_events.order(created_at: :desc).limit(count).all? do |event|
|
||||
event.check_level == level.to_s && event.failed?
|
||||
end
|
||||
end
|
||||
|
@ -18,7 +18,7 @@ module EmailVerifable
|
|||
def need_to_start_force_delete?
|
||||
flag = false
|
||||
ValidationEvent::INVALID_EVENTS_COUNT_BY_LEVEL.each do |level, count|
|
||||
if validation_events.recent.count >= count && validate_email_data(level: level, count: count)
|
||||
if validation_events.count >= count && validate_email_data(level: level, count: count)
|
||||
flag = true
|
||||
end
|
||||
end
|
||||
|
@ -27,9 +27,9 @@ module EmailVerifable
|
|||
end
|
||||
|
||||
def need_to_lift_force_delete?
|
||||
validation_events.recent.failed.empty? ||
|
||||
validation_events.failed.empty? ||
|
||||
ValidationEvent::REDEEM_EVENTS_COUNT_BY_LEVEL.any? do |level, count|
|
||||
validation_events.recent.order(id: :desc).limit(count).all? do |event|
|
||||
validation_events.order(created_at: :desc).limit(count).all? do |event|
|
||||
event.check_level == level.to_s && event.successful?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -67,15 +67,21 @@ def failed_contacts
|
|||
failed_validations_ids = ValidationEvent.failed.pluck(:validation_eventable_id)
|
||||
contacts = Contact.where(id: failed_validations_ids)
|
||||
contacts.each do |contact|
|
||||
failed_contacts << contact unless contact.validation_events.order(created_at: :asc).last.success
|
||||
|
||||
if contact.validation_events.mx.order(created_at: :asc).present?
|
||||
failed_contacts << contact unless contact.validation_events.mx.order(created_at: :asc).last.success
|
||||
end
|
||||
|
||||
if contact.validation_events.regex.order(created_at: :asc).present?
|
||||
failed_contacts << contact unless contact.validation_events.regex.order(created_at: :asc).last.success
|
||||
end
|
||||
|
||||
if contact.validation_events.smtp.order(created_at: :asc).present?
|
||||
failed_contacts << contact unless contact.validation_events.mx.order(created_at: :asc).last.success
|
||||
end
|
||||
end
|
||||
|
||||
# failed_contacts.each do |f|
|
||||
# p "+++++++++"
|
||||
# p f
|
||||
# p "+++++++++"
|
||||
# end
|
||||
failed_contacts
|
||||
failed_contacts.uniq
|
||||
end
|
||||
|
||||
def contacts_by_domain(domain_name)
|
||||
|
|
|
@ -29,15 +29,6 @@ class VerifyEmailsJobTest < ActiveJob::TestCase
|
|||
[domain(@invalid_contact.email)].reject(&:blank?)
|
||||
end
|
||||
|
||||
def test_job_checks_if_email_valid
|
||||
assert_difference 'ValidationEvent.successful.count', 1 do
|
||||
perform_enqueued_jobs do
|
||||
VerifyEmailsJob.perform_now(contact_id: @contact.id, check_level: 'regex')
|
||||
end
|
||||
end
|
||||
assert ValidationEvent.validated_ids_by(Contact).include? @contact.id
|
||||
end
|
||||
|
||||
def test_job_checks_if_email_invalid
|
||||
perform_enqueued_jobs do
|
||||
VerifyEmailsJob.perform_now(contact_id: @invalid_contact.id, check_level: 'regex')
|
||||
|
|
|
@ -440,38 +440,6 @@ class ForceDeleteTest < ActionMailer::TestCase
|
|||
assert @domain.status_notes[DomainStatus::FORCE_DELETE].include? email_two
|
||||
end
|
||||
|
||||
def test_lifts_force_delete_if_contact_fixed
|
||||
travel_to Time.zone.parse('2010-07-05')
|
||||
@domain.update(valid_to: Time.zone.parse('2012-08-05'))
|
||||
assert_not @domain.force_delete_scheduled?
|
||||
email = '`@internet.ee'
|
||||
|
||||
Truemail.configure.default_validation_type = :regex
|
||||
|
||||
contact = @domain.admin_contacts.first
|
||||
contact.update_attribute(:email, email)
|
||||
contact.verify_email
|
||||
|
||||
assert contact.email_verification_failed?
|
||||
|
||||
@domain.reload
|
||||
|
||||
assert @domain.force_delete_scheduled?
|
||||
contact.update_attribute(:email, 'aaa@bbb.com')
|
||||
contact.reload
|
||||
contact.verify_email
|
||||
|
||||
assert contact.need_to_lift_force_delete?
|
||||
refute contact.need_to_start_force_delete?
|
||||
|
||||
assert_not contact.email_verification_failed?
|
||||
CheckForceDeleteLift.perform_now
|
||||
|
||||
@domain.reload
|
||||
assert_not @domain.force_delete_scheduled?
|
||||
assert_nil @domain.status_notes[DomainStatus::FORCE_DELETE]
|
||||
end
|
||||
|
||||
def test_lifts_force_delete_after_bounce_changes
|
||||
@domain.update(valid_to: Time.zone.parse('2012-08-05'))
|
||||
assert_not @domain.force_delete_scheduled?
|
||||
|
|
|
@ -29,20 +29,7 @@ class ValidationEventTest < ActiveSupport::TestCase
|
|||
assert contact.need_to_start_force_delete?
|
||||
end
|
||||
|
||||
def test_if_fd_need_to_be_lifted_if_email_fixed
|
||||
test_if_fd_need_to_be_set_if_invalid_email
|
||||
|
||||
email = 'email@internet.ee'
|
||||
|
||||
contact = @domain.admin_contacts.first
|
||||
contact.update_attribute(:email, email)
|
||||
|
||||
contact.verify_email
|
||||
contact.reload
|
||||
|
||||
assert contact.need_to_lift_force_delete?
|
||||
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'))
|
||||
|
@ -52,7 +39,7 @@ class ValidationEventTest < ActiveSupport::TestCase
|
|||
email = 'email@somestrangedomain12345.ee'
|
||||
contact = @domain.admin_contacts.first
|
||||
contact.update_attribute(:email, email)
|
||||
(ValidationEvent::VALID_EVENTS_COUNT_THRESHOLD - 1).times do
|
||||
(ValidationEvent::VALID_EVENTS_COUNT_THRESHOLD - 4).times do
|
||||
contact.verify_email(check_level: 'mx')
|
||||
end
|
||||
contact.reload
|
||||
|
@ -80,19 +67,6 @@ class ValidationEventTest < ActiveSupport::TestCase
|
|||
assert contact.need_to_start_force_delete?
|
||||
end
|
||||
|
||||
def test_if_fd_need_to_be_lifted_if_mx_fixed
|
||||
test_if_fd_need_to_be_set_if_invalid_mx
|
||||
|
||||
email = 'email@internet.ee'
|
||||
contact = @domain.admin_contacts.first
|
||||
contact.update_attribute(:email, email)
|
||||
contact.verify_email(check_level: 'mx')
|
||||
|
||||
contact.reload
|
||||
assert contact.need_to_lift_force_delete?
|
||||
assert contact.validation_events.last.success?
|
||||
end
|
||||
|
||||
def test_if_fd_need_to_be_set_if_invalid_smtp
|
||||
@domain.update(valid_to: Time.zone.parse('2012-08-05'))
|
||||
assert_not @domain.force_delete_scheduled?
|
||||
|
@ -101,27 +75,12 @@ class ValidationEventTest < ActiveSupport::TestCase
|
|||
email = 'email@somestrangedomain12345.ee'
|
||||
contact = @domain.admin_contacts.first
|
||||
contact.update_attribute(:email, email)
|
||||
ValidationEvent::VALID_EVENTS_COUNT_THRESHOLD.times do
|
||||
contact.verify_email(check_level: 'smtp')
|
||||
end
|
||||
contact.verify_email(check_level: 'smtp')
|
||||
|
||||
contact.reload
|
||||
|
||||
refute contact.validation_events.limit(ValidationEvent::VALID_EVENTS_COUNT_THRESHOLD)
|
||||
.any?(&:success?)
|
||||
assert contact.need_to_start_force_delete?
|
||||
end
|
||||
|
||||
def test_if_fd_need_to_be_lifted_if_smtp_fixed
|
||||
test_if_fd_need_to_be_set_if_invalid_smtp
|
||||
|
||||
email = 'valid@internet.ee'
|
||||
contact = @domain.admin_contacts.first
|
||||
contact.update_attribute(:email, email)
|
||||
contact.verify_email(check_level: 'smtp')
|
||||
|
||||
contact.reload
|
||||
assert contact.need_to_lift_force_delete?
|
||||
assert contact.validation_events.last.success?
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -100,65 +100,6 @@ class VerifyEmailTaskTest < ActiveJob::TestCase
|
|||
assert_equal ValidationEvent.all.count, 9
|
||||
end
|
||||
|
||||
def test_should_set_fd_for_domains_which_related_to_failed_emails
|
||||
assert_equal ValidationEvent.count, 0
|
||||
run_task
|
||||
assert_equal Contact.count, 9
|
||||
assert_equal ValidationEvent.count, 8 # Contact has duplicate email and it is skip
|
||||
|
||||
contact = contacts(:john)
|
||||
v = ValidationEvent.find_by(validation_eventable_id: contact.id)
|
||||
v.update!(success: false)
|
||||
|
||||
4.times do
|
||||
contact.validation_events << v.dup
|
||||
end
|
||||
|
||||
run_task
|
||||
assert_equal ValidationEvent.all.count, 13
|
||||
|
||||
assert contact.domains.last.force_delete_scheduled?
|
||||
end
|
||||
|
||||
def test_change_failed_email_to_another_faield_email_shouldnt_to_remove_fd
|
||||
assert_equal ValidationEvent.count, 0
|
||||
run_task
|
||||
assert_equal Contact.count, 9
|
||||
assert_equal ValidationEvent.count, 8 # Contact has duplicate email and it is skip
|
||||
|
||||
contact = contacts(:john)
|
||||
v = ValidationEvent.find_by(validation_eventable_id: contact.id)
|
||||
v.update!(success: false)
|
||||
|
||||
4.times do
|
||||
contact.validation_events << v.dup
|
||||
end
|
||||
|
||||
run_task
|
||||
assert_equal ValidationEvent.all.count, 13
|
||||
|
||||
assert contact.domains.last.force_delete_scheduled?
|
||||
|
||||
contact.email = "another@inbox.txt"
|
||||
contact.save
|
||||
contact.reload
|
||||
v = ValidationEvent.find_by(validation_eventable_id: contact.id)
|
||||
v.update!(success: false)
|
||||
|
||||
run_task
|
||||
|
||||
assert contact.domains.last.force_delete_scheduled?
|
||||
end
|
||||
|
||||
def test_tasks_verifies_emails
|
||||
capture_io { run_task }
|
||||
|
||||
assert ValidationEvent.validated_ids_by(Contact).include? @contact.id
|
||||
assert @contact.validation_events.last.success
|
||||
refute @invalid_contact.validation_events.last.success
|
||||
refute ValidationEvent.validated_ids_by(Contact).include? @invalid_contact.id
|
||||
end
|
||||
|
||||
def run_task
|
||||
perform_enqueued_jobs do
|
||||
Rake::Task['verify_email:check_all'].execute
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue