mirror of
https://github.com/internetee/registry.git
synced 2025-07-28 05:26:17 +02:00
Fix tests
This commit is contained in:
parent
e159821a86
commit
944aba563c
4 changed files with 31 additions and 22 deletions
|
@ -1,33 +1,32 @@
|
|||
class ValidationEventCheckForceDeleteJob < ApplicationJob
|
||||
def perform(contact_id)
|
||||
contact = Contact.find(contact_id)
|
||||
email = contact.email
|
||||
@contact = Contact.find(contact_id)
|
||||
@email = @contact.email
|
||||
|
||||
if contact.need_to_start_force_delete?
|
||||
Domains::ForceDeleteEmail::Base.run(email: email)
|
||||
elsif contact.need_to_lift_force_delete?
|
||||
refresh_status_notes(domain_list(email))
|
||||
if @contact.need_to_start_force_delete?
|
||||
Domains::ForceDeleteEmail::Base.run(email: @email)
|
||||
elsif @contact.need_to_lift_force_delete?
|
||||
refresh_status_notes
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def refresh_status_notes(domain_list)
|
||||
def refresh_status_notes
|
||||
domain_list.each do |domain|
|
||||
force_delete_emails = domain.status_notes[DomainStatus::FORCE_DELETE]
|
||||
next unless force_delete_emails
|
||||
next unless domain.status_notes[DomainStatus::FORCE_DELETE]
|
||||
|
||||
force_delete_emails.slice!(object.email_history)
|
||||
force_delete_emails.lstrip!
|
||||
domain.status_notes[DomainStatus::FORCE_DELETE].slice!(@contact.email_history)
|
||||
domain.status_notes[DomainStatus::FORCE_DELETE].lstrip!
|
||||
domain.save(validate: false)
|
||||
|
||||
notify_registrar(domain) unless domain.status_notes[DomainStatus::FORCE_DELETE].empty?
|
||||
end
|
||||
end
|
||||
|
||||
def domain_list(email)
|
||||
domain_contacts = Contact.where(email: email).map(&:domain_contacts).flatten
|
||||
registrant_ids = Registrant.where(email: email).pluck(:id)
|
||||
def domain_list
|
||||
domain_contacts = Contact.where(email: @email).map(&:domain_contacts).flatten
|
||||
registrant_ids = Registrant.where(email: @email).pluck(:id)
|
||||
|
||||
(domain_contacts.map(&:domain).flatten + Domain.where(registrant_id: registrant_ids)).uniq
|
||||
end
|
||||
|
|
|
@ -12,9 +12,12 @@ module EmailVerifable
|
|||
end
|
||||
|
||||
def need_to_start_force_delete?
|
||||
flag = false
|
||||
ValidationEvent::INVALID_EVENTS_COUNT_BY_LEVEL.each do |level, count|
|
||||
validation_events.count >= count && validate_email_data(level: level, count: count)
|
||||
flag = true if validation_events.count >= count && validate_email_data(level: level, count: count)
|
||||
end
|
||||
|
||||
flag
|
||||
end
|
||||
|
||||
def need_to_lift_force_delete?
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
desc 'Check Force Delete'
|
||||
task :check_force_delete do
|
||||
|
||||
task :check_force_delete, :environment do
|
||||
invalid_contacts = Contact.joins(:validation_events).select do |contact|
|
||||
events = contact.validation_events
|
||||
events.mx.count >= 3 || events.regex.present?
|
||||
|
|
|
@ -398,7 +398,7 @@ class ForceDeleteTest < ActionMailer::TestCase
|
|||
contact.verify_email
|
||||
end
|
||||
|
||||
perform_enqueued_jobs
|
||||
perform_check_force_delete_job(contact.id)
|
||||
@domain.reload
|
||||
|
||||
assert @domain.force_delete_scheduled?
|
||||
|
@ -431,7 +431,7 @@ class ForceDeleteTest < ActionMailer::TestCase
|
|||
contact_first.verify_email
|
||||
end
|
||||
|
||||
perform_enqueued_jobs
|
||||
perform_check_force_delete_job(contact_first.id)
|
||||
domain.reload
|
||||
|
||||
assert_equal domain.status_notes[DomainStatus::FORCE_DELETE], invalid_emails
|
||||
|
@ -460,7 +460,7 @@ class ForceDeleteTest < ActionMailer::TestCase
|
|||
travel_to Time.zone.parse('2010-07-05 0:00:03')
|
||||
contact_first.verify_email
|
||||
|
||||
perform_enqueued_jobs
|
||||
perform_check_force_delete_job(contact_first.id)
|
||||
domain.reload
|
||||
|
||||
assert_equal domain.status_notes[DomainStatus::FORCE_DELETE], invalid_email
|
||||
|
@ -478,14 +478,14 @@ class ForceDeleteTest < ActionMailer::TestCase
|
|||
contact_one = @domain.admin_contacts.first
|
||||
contact_one.update_attribute(:email, email_one)
|
||||
contact_one.verify_email
|
||||
perform_enqueued_jobs
|
||||
perform_check_force_delete_job(contact_one.id)
|
||||
|
||||
assert contact_one.need_to_start_force_delete?
|
||||
|
||||
contact_two = @domain.admin_contacts.first
|
||||
contact_two.update_attribute(:email, email_two)
|
||||
contact_two.verify_email
|
||||
perform_enqueued_jobs
|
||||
perform_check_force_delete_job(contact_two.id)
|
||||
|
||||
assert contact_two.need_to_start_force_delete?
|
||||
|
||||
|
@ -535,4 +535,12 @@ class ForceDeleteTest < ActionMailer::TestCase
|
|||
@bounced_mail.diagnostic = 'smtp; 550 5.1.1 user unknown'
|
||||
@bounced_mail.save!
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def perform_check_force_delete_job(contact_id)
|
||||
perform_enqueued_jobs do
|
||||
ValidationEventCheckForceDeleteJob.perform_now(contact_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue