mirror of
https://github.com/internetee/registry.git
synced 2025-07-24 11:38:30 +02:00
Merge pull request #2201 from internetee/optimize-validation-event-model
Optimize verify email
This commit is contained in:
commit
9bdcc9e6b4
8 changed files with 177 additions and 104 deletions
|
@ -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
|
||||
|
|
|
@ -31,13 +31,115 @@ class VerifyEmailTaskTest < ActiveJob::TestCase
|
|||
[domain(@invalid_contact.email)].reject(&:blank?)
|
||||
end
|
||||
|
||||
def test_tasks_verifies_emails
|
||||
capture_io { run_task }
|
||||
def test_should_be_verified_duplicate_emails
|
||||
william = Contact.where(email: "william@inbox.test").count
|
||||
|
||||
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
|
||||
assert_equal william, 2
|
||||
assert_equal Contact.all.count, 9
|
||||
run_task
|
||||
assert_equal ValidationEvent.count, Contact.count - 1
|
||||
end
|
||||
|
||||
def test_should_not_affect_to_successfully_verified_emails
|
||||
assert_equal ValidationEvent.count, 0
|
||||
run_task
|
||||
assert_equal ValidationEvent.count, Contact.count - 1 # Contact has duplicate email and it is skip
|
||||
|
||||
run_task
|
||||
assert_equal ValidationEvent.count, Contact.count - 1
|
||||
end
|
||||
|
||||
def test_should_verify_contact_which_was_not_verified
|
||||
bestnames = registrars(:bestnames)
|
||||
assert_equal ValidationEvent.count, 0
|
||||
run_task
|
||||
assert_equal ValidationEvent.count, Contact.count - 1 # Contact has duplicate email and it is skip
|
||||
|
||||
assert_equal Contact.count, 9
|
||||
c = Contact.create(name: 'Jeembo',
|
||||
email: 'heey@jeembo.com',
|
||||
phone: '+555.555',
|
||||
ident: '1234',
|
||||
ident_type: 'priv',
|
||||
ident_country_code: 'US',
|
||||
registrar: bestnames,
|
||||
code: 'jeembo-01')
|
||||
|
||||
assert_equal Contact.count, 10
|
||||
run_task
|
||||
assert_equal ValidationEvent.count, Contact.count - 1
|
||||
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
|
||||
|
||||
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!(created_at: expired_date)
|
||||
|
||||
run_task
|
||||
assert_equal ValidationEvent.all.count, 9
|
||||
end
|
||||
|
||||
def test_should_set_fd_for_failed_email_after_several_times
|
||||
contact = contacts(:john)
|
||||
trumail_results = OpenStruct.new(success: false,
|
||||
email: contact.email,
|
||||
domain: "inbox.tests",
|
||||
errors: {:mx=>"target host(s) not found"},
|
||||
)
|
||||
Spy.on_instance_method(Actions::EmailCheck, :check_email).and_return(trumail_results)
|
||||
|
||||
|
||||
assert_not contact.domains.last.force_delete_scheduled?
|
||||
|
||||
2.times do
|
||||
run_task
|
||||
end
|
||||
|
||||
assert contact.domains.last.force_delete_scheduled?
|
||||
end
|
||||
|
||||
def test_fd_should_not_removed_if_change_email_to_another_invalid_one
|
||||
contact = contacts(:john)
|
||||
|
||||
contact.domains.last.schedule_force_delete(type: :soft)
|
||||
assert contact.domains.last.force_delete_scheduled?
|
||||
|
||||
contact.update(email: "test@box.test")
|
||||
contact.reload
|
||||
|
||||
trumail_results = OpenStruct.new(success: false,
|
||||
email: contact.email,
|
||||
domain: "box.tests",
|
||||
errors: {:mx=>"target host(s) not found"},
|
||||
)
|
||||
Spy.on_instance_method(Actions::EmailCheck, :check_email).and_return(trumail_results)
|
||||
|
||||
1.times do
|
||||
run_task
|
||||
end
|
||||
|
||||
assert contact.domains.last.force_delete_scheduled?
|
||||
end
|
||||
|
||||
def run_task
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue