mirror of
https://github.com/internetee/registry.git
synced 2025-06-09 06:04:56 +02:00
updated emails
This commit is contained in:
parent
59fb12b840
commit
c29a35fffb
3 changed files with 40 additions and 7 deletions
|
@ -24,7 +24,8 @@ class VerifyEmailsJob < ApplicationJob
|
||||||
contact = Contact.find(contact_id)
|
contact = Contact.find(contact_id)
|
||||||
contact_ids = Contact.where(email: contact.email).where('created_at > ?', time).pluck(:id)
|
contact_ids = Contact.where(email: contact.email).where('created_at > ?', time).pluck(:id)
|
||||||
|
|
||||||
r = ValidationEvent.where(validation_eventable_id: contact_ids)
|
r = ValidationEvent.where(validation_eventable_id: contact_ids).order(created_at: :desc)
|
||||||
|
# return false if r[0].success == false
|
||||||
|
|
||||||
r.present?
|
r.present?
|
||||||
end
|
end
|
||||||
|
|
|
@ -57,10 +57,15 @@ def prepare_contacts(options)
|
||||||
time = Time.zone.now - ValidationEvent::VALIDATION_PERIOD
|
time = Time.zone.now - ValidationEvent::VALIDATION_PERIOD
|
||||||
validation_events_ids = ValidationEvent.where('created_at > ?', time).pluck(:validation_eventable_id)
|
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)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def failed_contacts
|
||||||
|
ValidationEvent.failed.pluck(:id)
|
||||||
|
end
|
||||||
|
|
||||||
def contacts_by_domain(domain_name)
|
def contacts_by_domain(domain_name)
|
||||||
domain = ::Domain.find_by(name: domain_name)
|
domain = ::Domain.find_by(name: domain_name)
|
||||||
return unless domain
|
return unless domain
|
||||||
|
|
|
@ -31,20 +31,29 @@ class VerifyEmailTaskTest < ActiveJob::TestCase
|
||||||
[domain(@invalid_contact.email)].reject(&:blank?)
|
[domain(@invalid_contact.email)].reject(&:blank?)
|
||||||
end
|
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_not_affect_to_successfully_verified_emails
|
def test_should_not_affect_to_successfully_verified_emails
|
||||||
assert_equal ValidationEvent.count, 0
|
assert_equal ValidationEvent.count, 0
|
||||||
run_task
|
run_task
|
||||||
assert_equal ValidationEvent.count, Contact.count
|
assert_equal ValidationEvent.count, Contact.count - 1 # Contact has duplicate email and it is skip
|
||||||
|
|
||||||
run_task
|
run_task
|
||||||
assert_equal ValidationEvent.count, Contact.count
|
assert_equal ValidationEvent.count, Contact.count - 1
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_should_verify_contact_which_was_not_verified
|
def test_should_verify_contact_which_was_not_verified
|
||||||
bestnames = registrars(:bestnames)
|
bestnames = registrars(:bestnames)
|
||||||
assert_equal ValidationEvent.count, 0
|
assert_equal ValidationEvent.count, 0
|
||||||
run_task
|
run_task
|
||||||
assert_equal ValidationEvent.count, Contact.count
|
assert_equal ValidationEvent.count, Contact.count - 1 # Contact has duplicate email and it is skip
|
||||||
|
|
||||||
assert_equal Contact.count, 9
|
assert_equal Contact.count, 9
|
||||||
c = Contact.create(name: 'Jeembo',
|
c = Contact.create(name: 'Jeembo',
|
||||||
|
@ -58,22 +67,40 @@ class VerifyEmailTaskTest < ActiveJob::TestCase
|
||||||
|
|
||||||
assert_equal Contact.count, 10
|
assert_equal Contact.count, 10
|
||||||
run_task
|
run_task
|
||||||
assert_equal ValidationEvent.count, Contact.count
|
assert_equal ValidationEvent.count, Contact.count - 1
|
||||||
end
|
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_contact_which_has_expired_date_of_verification
|
def test_should_verify_contact_which_has_expired_date_of_verification
|
||||||
expired_date = Time.now - ValidationEvent::VALIDATION_PERIOD - 1.day
|
expired_date = Time.now - ValidationEvent::VALIDATION_PERIOD - 1.day
|
||||||
|
|
||||||
assert_equal ValidationEvent.count, 0
|
assert_equal ValidationEvent.count, 0
|
||||||
run_task
|
run_task
|
||||||
assert_equal ValidationEvent.count, Contact.count
|
assert_equal Contact.count, 9
|
||||||
|
assert_equal ValidationEvent.count, 8 # Contact has duplicate email and it is skip
|
||||||
|
|
||||||
contact = contacts(:john)
|
contact = contacts(:john)
|
||||||
v = ValidationEvent.find_by(validation_eventable_id: contact.id)
|
v = ValidationEvent.find_by(validation_eventable_id: contact.id)
|
||||||
v.update!(created_at: expired_date)
|
v.update!(created_at: expired_date)
|
||||||
|
|
||||||
run_task
|
run_task
|
||||||
assert_equal ValidationEvent.count, Contact.count + 1
|
assert_equal ValidationEvent.all.count, 9
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_tasks_verifies_emails
|
def test_tasks_verifies_emails
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue