mirror of
https://github.com/internetee/registry.git
synced 2025-06-10 22:54:47 +02:00
updated: also validated contacts which was failed without any time limits
This commit is contained in:
parent
8b9fbafeb4
commit
5ea5dd7197
4 changed files with 44 additions and 21 deletions
|
@ -25,7 +25,6 @@ class VerifyEmailsJob < ApplicationJob
|
|||
contact_ids = Contact.where(email: contact.email).where('created_at > ?', time).pluck(:id)
|
||||
|
||||
r = ValidationEvent.where(validation_eventable_id: contact_ids).order(created_at: :desc)
|
||||
# return false if r[0].success == false
|
||||
|
||||
r.present?
|
||||
end
|
||||
|
|
|
@ -12,7 +12,7 @@ class ValidationEvent < ApplicationRecord
|
|||
|
||||
INVALID_EVENTS_COUNT_BY_LEVEL = {
|
||||
regex: 1,
|
||||
mx: 5,
|
||||
mx: 2,
|
||||
smtp: 1,
|
||||
}.freeze
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace :verify_email do
|
|||
contacts = prepare_contacts(options)
|
||||
logger.info 'No contacts to check email selected' and next if contacts.blank?
|
||||
|
||||
contacts.find_each do |contact|
|
||||
contacts.each do |contact|
|
||||
VerifyEmailsJob.set(wait_until: spam_protect_timeout(options)).perform_later(
|
||||
contact_id: contact.id,
|
||||
check_level: check_level(options)
|
||||
|
@ -58,12 +58,19 @@ def prepare_contacts(options)
|
|||
validation_events_ids = ValidationEvent.where('created_at > ?', time).pluck(:validation_eventable_id)
|
||||
|
||||
# Contact.where.not(id: validation_events_ids) + Contact.where(id: failed_contacts)
|
||||
Contact.where.not(id: validation_events_ids)
|
||||
Contact.where.not(id: validation_events_ids) | failed_contacts
|
||||
end
|
||||
end
|
||||
|
||||
def failed_contacts
|
||||
ValidationEvent.failed.pluck(:id)
|
||||
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.last.success
|
||||
end
|
||||
|
||||
failed_contacts
|
||||
end
|
||||
|
||||
def contacts_by_domain(domain_name)
|
||||
|
|
|
@ -70,22 +70,19 @@ class VerifyEmailTaskTest < ActiveJob::TestCase
|
|||
assert_equal ValidationEvent.count, Contact.count - 1
|
||||
end
|
||||
|
||||
# def test_should_verify_again_contact_which_has_faield_verification
|
||||
# expired_date = Time.now - ValidationEvent::VALIDATION_PERIOD - 1.day
|
||||
#
|
||||
# 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)
|
||||
#
|
||||
# run_task
|
||||
# binding.pry
|
||||
# assert_equal ValidationEvent.all.count, 9
|
||||
# end
|
||||
def test_should_verify_again_contact_which_has_faield_verification
|
||||
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)
|
||||
|
||||
run_task
|
||||
assert_equal ValidationEvent.all.count, 9
|
||||
end
|
||||
|
||||
def test_should_verify_contact_which_has_expired_date_of_verification
|
||||
expired_date = Time.now - ValidationEvent::VALIDATION_PERIOD - 1.day
|
||||
|
@ -103,6 +100,26 @@ 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_tasks_verifies_emails
|
||||
capture_io { run_task }
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue