mirror of
https://github.com/internetee/registry.git
synced 2025-07-28 21:46:24 +02:00
Refactored and corrected code for domain force delete
This commit is contained in:
parent
316f00cadc
commit
d3bca1434c
10 changed files with 223 additions and 259 deletions
|
@ -1,7 +1,6 @@
|
|||
require 'test_helper'
|
||||
|
||||
class EmailCheckTest < ActiveSupport::TestCase
|
||||
|
||||
setup do
|
||||
WebMock.disable_net_connect!
|
||||
|
||||
|
@ -9,104 +8,67 @@ class EmailCheckTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
def test_invalid_email_in_mx_level_with_a_and_aaaa_records
|
||||
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)
|
||||
Spy.on_instance_method(Actions::EmailCheck, :check_email).and_return(trumail_result)
|
||||
Spy.on_instance_method(Actions::AAndAaaaEmailValidation, :call).and_return([true])
|
||||
|
||||
action = Actions::EmailCheck.new(email: @contact.email,
|
||||
validation_eventable: @contact,
|
||||
check_level: 'mx')
|
||||
action.call
|
||||
Actions::EmailCheck.new(email: @contact.email,
|
||||
validation_eventable: @contact,
|
||||
check_level: 'mx').call
|
||||
|
||||
assert_equal @contact.validation_events.count, 1
|
||||
assert @contact.validation_events.last.success
|
||||
end
|
||||
|
||||
def test_invalid_email_in_mx_level_with_empty_a_and_aaaa_records
|
||||
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)
|
||||
Spy.on_instance_method(Actions::EmailCheck, :check_email).and_return(trumail_result)
|
||||
Spy.on_instance_method(Actions::AAndAaaaEmailValidation, :call).and_return([])
|
||||
|
||||
action = Actions::EmailCheck.new(email: @contact.email,
|
||||
validation_eventable: @contact,
|
||||
check_level: 'mx')
|
||||
action.call
|
||||
Actions::EmailCheck.new(email: @contact.email,
|
||||
validation_eventable: @contact,
|
||||
check_level: 'mx').call
|
||||
|
||||
assert_equal @contact.validation_events.count, 1
|
||||
refute @contact.validation_events.last.success
|
||||
end
|
||||
|
||||
def test_should_remove_invalid_validation_record_if_there_count_more_than_three
|
||||
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)
|
||||
def test_should_remove_invalid_validation_records_if_there_count_more_than_three
|
||||
Spy.on_instance_method(Actions::EmailCheck, :check_email).and_return(trumail_result)
|
||||
Spy.on_instance_method(Actions::AAndAaaaEmailValidation, :call).and_return([])
|
||||
|
||||
action = Actions::EmailCheck.new(email: @contact.email,
|
||||
validation_eventable: @contact,
|
||||
check_level: 'mx')
|
||||
3.times do
|
||||
action.call
|
||||
end
|
||||
3.times { action.call }
|
||||
|
||||
assert_equal @contact.validation_events.count, 3
|
||||
refute @contact.validation_events.last.success
|
||||
|
||||
3.times do
|
||||
action.call
|
||||
end
|
||||
3.times { action.call }
|
||||
|
||||
assert_equal @contact.validation_events.count, 3
|
||||
refute @contact.validation_events.last.success
|
||||
end
|
||||
|
||||
def test_should_remove_valid_validation_record_if_there_count_more_than_one
|
||||
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)
|
||||
Spy.on_instance_method(Actions::EmailCheck, :check_email).and_return(trumail_result)
|
||||
Spy.on_instance_method(Actions::AAndAaaaEmailValidation, :call).and_return([true])
|
||||
|
||||
action = Actions::EmailCheck.new(email: @contact.email,
|
||||
validation_eventable: @contact,
|
||||
check_level: 'mx')
|
||||
|
||||
3.times do
|
||||
action.call
|
||||
end
|
||||
3.times { action.call }
|
||||
|
||||
assert_equal @contact.validation_events.count, 1
|
||||
assert @contact.validation_events.last.success
|
||||
end
|
||||
|
||||
def test_should_remove_old_record_if_validation_pass_the_limit
|
||||
trumail_results = OpenStruct.new(success: false,
|
||||
email: @contact.email,
|
||||
domain: "box.tests",
|
||||
errors: {:mx=>"target host(s) not found"})
|
||||
|
||||
action = Actions::EmailCheck.new(email: @contact.email,
|
||||
validation_eventable: @contact,
|
||||
check_level: 'mx')
|
||||
|
||||
action.stub :check_email, trumail_results do
|
||||
action.stub :check_email, trumail_result do
|
||||
4.times do
|
||||
action.call
|
||||
end
|
||||
|
@ -119,17 +81,13 @@ class EmailCheckTest < ActiveSupport::TestCase
|
|||
contact_two = contacts(:william)
|
||||
contact_two.update(email: @contact.email)
|
||||
contact_two.reload
|
||||
trumail_results = OpenStruct.new(success: false,
|
||||
email: @contact.email,
|
||||
domain: "box.tests",
|
||||
errors: {:mx=>"target host(s) not found"})
|
||||
|
||||
action = Actions::EmailCheck.new(email: @contact.email,
|
||||
validation_eventable: @contact,
|
||||
check_level: 'mx')
|
||||
|
||||
action.stub :check_email, trumail_results do
|
||||
4.times do
|
||||
action.stub :check_email, trumail_result do
|
||||
4.times do
|
||||
action.call
|
||||
end
|
||||
end
|
||||
|
@ -137,4 +95,13 @@ class EmailCheckTest < ActiveSupport::TestCase
|
|||
assert_equal @contact.validation_events.count, 3
|
||||
assert_equal contact_two.validation_events.count, 3
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def trumail_result
|
||||
OpenStruct.new(success: false,
|
||||
email: @contact.email,
|
||||
domain: 'box.tests',
|
||||
errors: { mx: 'target host(s) not found' })
|
||||
end
|
||||
end
|
||||
|
|
|
@ -82,7 +82,7 @@ class ForceDeleteTest < ActionMailer::TestCase
|
|||
statuses_to_be_added = [
|
||||
DomainStatus::FORCE_DELETE,
|
||||
DomainStatus::SERVER_RENEW_PROHIBITED,
|
||||
DomainStatus::SERVER_TRANSFER_PROHIBITED
|
||||
DomainStatus::SERVER_TRANSFER_PROHIBITED,
|
||||
]
|
||||
|
||||
@domain.schedule_force_delete(type: :soft)
|
||||
|
@ -94,7 +94,7 @@ class ForceDeleteTest < ActionMailer::TestCase
|
|||
statuses_to_be_added = [
|
||||
DomainStatus::FORCE_DELETE,
|
||||
DomainStatus::SERVER_RENEW_PROHIBITED,
|
||||
DomainStatus::SERVER_TRANSFER_PROHIBITED
|
||||
DomainStatus::SERVER_TRANSFER_PROHIBITED,
|
||||
]
|
||||
|
||||
@domain.schedule_force_delete(type: :fast_track)
|
||||
|
@ -104,7 +104,7 @@ class ForceDeleteTest < ActionMailer::TestCase
|
|||
|
||||
def test_scheduling_force_delete_allows_domain_deletion
|
||||
statuses_to_be_removed = [
|
||||
DomainStatus::CLIENT_DELETE_PROHIBITED
|
||||
DomainStatus::CLIENT_DELETE_PROHIBITED,
|
||||
]
|
||||
|
||||
@domain.statuses = statuses_to_be_removed + %w[other-status]
|
||||
|
@ -119,7 +119,7 @@ class ForceDeleteTest < ActionMailer::TestCase
|
|||
DomainStatus::PENDING_UPDATE,
|
||||
DomainStatus::PENDING_TRANSFER,
|
||||
DomainStatus::PENDING_RENEW,
|
||||
DomainStatus::PENDING_CREATE
|
||||
DomainStatus::PENDING_CREATE,
|
||||
]
|
||||
|
||||
@domain.statuses = statuses_to_be_removed + %w[other-status]
|
||||
|
@ -169,7 +169,7 @@ class ForceDeleteTest < ActionMailer::TestCase
|
|||
statuses = [
|
||||
DomainStatus::FORCE_DELETE,
|
||||
DomainStatus::SERVER_RENEW_PROHIBITED,
|
||||
DomainStatus::SERVER_TRANSFER_PROHIBITED
|
||||
DomainStatus::SERVER_TRANSFER_PROHIBITED,
|
||||
]
|
||||
@domain.statuses = @domain.statuses + statuses
|
||||
@domain.save!
|
||||
|
@ -196,7 +196,7 @@ class ForceDeleteTest < ActionMailer::TestCase
|
|||
def test_cancelling_force_delete_keeps_previous_statuses
|
||||
statuses = [
|
||||
DomainStatus::SERVER_RENEW_PROHIBITED,
|
||||
DomainStatus::SERVER_TRANSFER_PROHIBITED
|
||||
DomainStatus::SERVER_TRANSFER_PROHIBITED,
|
||||
]
|
||||
|
||||
@domain.statuses = statuses
|
||||
|
@ -441,8 +441,8 @@ class ForceDeleteTest < ActionMailer::TestCase
|
|||
|
||||
travel_to Time.zone.parse('2010-07-05')
|
||||
email = '`@internet2.ee'
|
||||
invalid_email = '`@internet.ee'
|
||||
asserted_text = "Invalid email: #{invalid_email}"
|
||||
# invalid_email = '`@internet.ee'
|
||||
# asserted_text = "Invalid email: #{invalid_email}"
|
||||
|
||||
Truemail.configure.default_validation_type = :regex
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
require 'test_helper'
|
||||
|
||||
class VerifyEmailTaskTest < ActiveJob::TestCase
|
||||
|
||||
def setup
|
||||
@contact = contacts(:john)
|
||||
@invalid_contact = contacts(:invalid_email)
|
||||
@registrar = registrars(:bestnames)
|
||||
|
||||
@default_whitelist = Truemail.configure.whitelisted_domains
|
||||
@default_blacklist = Truemail.configure.blacklisted_domains
|
||||
|
@ -31,89 +31,58 @@ class VerifyEmailTaskTest < ActiveJob::TestCase
|
|||
[domain(@invalid_contact.email)].reject(&:blank?)
|
||||
end
|
||||
|
||||
# def test_should_be_verified_duplicate_emails
|
||||
# william = Contact.where(email: "william@inbox.test").count
|
||||
#
|
||||
# assert_equal william, 2
|
||||
# assert_equal Contact.all.count, 9
|
||||
# run_task
|
||||
# assert_equal ValidationEvent.count, Contact.count - 1
|
||||
# end
|
||||
def test_should_skip_duplicate_emails
|
||||
william_contacts_count = Contact.where(email: 'william@inbox.test').count
|
||||
|
||||
# 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
|
||||
assert_equal william_contacts_count, 2
|
||||
assert_equal Contact.count, 9
|
||||
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_not_affect_successfully_verified_emails
|
||||
assert_equal ValidationEvent.count, 0
|
||||
run_task
|
||||
|
||||
# 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
|
||||
assert_equal ValidationEvent.count, Contact.count - 1
|
||||
assert_equal ValidationEvent.where(success: true).count, 5
|
||||
assert_equal ValidationEvent.where(success: false).count, 3
|
||||
|
||||
# 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
|
||||
run_task
|
||||
assert_equal ValidationEvent.where(success: true).count, 5
|
||||
assert_equal ValidationEvent.where(success: false).count, 6
|
||||
end
|
||||
|
||||
def test_fd_should_not_removed_if_change_email_to_another_invalid_one
|
||||
def test_should_verify_contact_email_which_was_not_verified
|
||||
assert_equal ValidationEvent.count, 0
|
||||
|
||||
run_task
|
||||
|
||||
assert_equal ValidationEvent.count, Contact.count - 1
|
||||
assert_equal Contact.count, 9
|
||||
|
||||
assert_difference 'Contact.count', 1 do
|
||||
create_valid_contact
|
||||
end
|
||||
|
||||
assert_difference 'ValidationEvent.where(success: true).count', 1 do
|
||||
run_task
|
||||
end
|
||||
end
|
||||
|
||||
def test_fd_should_not_be_removed_if_email_changed_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.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"},
|
||||
)
|
||||
domain: 'box.tests',
|
||||
errors: { mx: 'target host(s) not found' })
|
||||
Spy.on_instance_method(Actions::EmailCheck, :check_email).and_return(trumail_results)
|
||||
|
||||
run_task
|
||||
|
@ -147,4 +116,15 @@ class VerifyEmailTaskTest < ActiveJob::TestCase
|
|||
Rake::Task['verify_email:check_all'].execute
|
||||
end
|
||||
end
|
||||
|
||||
def create_valid_contact
|
||||
Contact.create!(name: 'Jeembo',
|
||||
email: 'heey@jeembo.com',
|
||||
phone: '+555.555',
|
||||
ident: '1234',
|
||||
ident_type: 'priv',
|
||||
ident_country_code: 'US',
|
||||
registrar: @registrar,
|
||||
code: 'jeembo-01')
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue