-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2437 from internetee/2436-fd-process-for-long-ter…
…m-registrations outzone rake task for invalid email domains
- Loading branch information
Showing
5 changed files
with
139 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class OutzoneInvalidEmailDomainsJob < ApplicationJob | ||
queue_as :default | ||
|
||
def perform | ||
domains = Domain.where("force_delete_data->'template_name' = ?", 'invalid_email') | ||
.where(outzone_at: nil) | ||
.where('Date(force_delete_start) <= ?', Time.zone.now) | ||
|
||
domains.each do |domain| | ||
outzone(domain) | ||
end | ||
end | ||
|
||
private | ||
|
||
def outzone(domain) | ||
domain.outzone_at = domain.force_delete_start + Domain.expire_warning_period | ||
domain.delete_date = domain.outzone_at + Domain.redemption_grace_period | ||
domain.save | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
desc 'Rake task run outzone setter task for force deleted domains by invalid emails' | ||
|
||
task outzone_invalid_email_domains: :environment do | ||
OutzoneInvalidEmailDomainsJob.perform_later | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,92 @@ | ||
require 'test_helper' | ||
|
||
class BaseTest < ActiveSupport::TestCase | ||
setup do | ||
@domain = domains(:shop) | ||
@domain_airport = domains(:airport) | ||
end | ||
|
||
def test_hold_domains_force_delete_email | ||
domain = domains(:shop) | ||
domain.update!(statuses: [DomainStatus::SERVER_HOLD]) | ||
domain.update!(expire_time: Time.zone.now + 1.year) | ||
@domain.update!(statuses: [DomainStatus::SERVER_HOLD]) | ||
@domain.update!(expire_time: Time.zone.now + 1.year) | ||
|
||
registrant = domain.registrant | ||
registrant.update!(email: "#{registrant.email.split('@').first}@#{domain.name}") | ||
registrant = @domain.registrant | ||
registrant.update!(email: "#{registrant.email.split('@').first}@#{@domain.name}") | ||
|
||
Domains::ForceDeleteEmail::Base.run(email: registrant.email) | ||
|
||
domain.reload | ||
@domain.reload | ||
|
||
assert_not @domain.force_delete_scheduled? | ||
end | ||
|
||
def test_more_that_year_until_valid_to_date | ||
refute @domain_airport.force_delete_scheduled? | ||
@domain_airport.update!(valid_to: Time.zone.now + 3.years + 1.month + 1.day) | ||
@domain_airport.reload | ||
prepare_contact | ||
|
||
contact = @domain_airport.admin_contacts.first | ||
|
||
Domains::ForceDeleteEmail::Base.run(email: contact.email) | ||
@domain_airport.reload | ||
|
||
assert @domain_airport.force_delete_scheduled? | ||
assert @domain_airport.valid_to > Time.zone.now + 1.year | ||
assert_equal @domain_airport.force_delete_start.to_date, (Time.zone.now + 1.month + 1.day).to_date | ||
assert_equal @domain_airport.force_delete_date, (@domain_airport.force_delete_start + | ||
Setting.expire_warning_period.days + | ||
Setting.redemption_grace_period.days).to_date | ||
end | ||
|
||
def test_more_that_year_until_valid_to_date_but_month_is_previous | ||
refute @domain_airport.force_delete_scheduled? | ||
@domain_airport.update!(valid_to: Time.zone.now + 3.years - 1.month - 4.days) | ||
@domain_airport.reload | ||
prepare_contact | ||
|
||
contact = @domain_airport.admin_contacts.first | ||
|
||
Domains::ForceDeleteEmail::Base.run(email: contact.email) | ||
@domain_airport.reload | ||
|
||
assert @domain_airport.force_delete_scheduled? | ||
assert @domain_airport.valid_to > Time.zone.now + 1.year | ||
assert_equal @domain_airport.force_delete_start.to_date, (Time.zone.now + 1.year - 1.month - 4.days).to_date | ||
assert_equal @domain_airport.force_delete_date, (@domain_airport.force_delete_start + | ||
Setting.expire_warning_period.days + | ||
Setting.redemption_grace_period.days).to_date | ||
end | ||
|
||
def test_should_send_poll_message_about_45_days_to_registrar | ||
refute @domain_airport.force_delete_scheduled? | ||
@domain_airport.update!(valid_to: Time.zone.now + 3.years - 1.month - 4.days) | ||
@domain_airport.reload | ||
prepare_contact | ||
|
||
contact = @domain_airport.admin_contacts.first | ||
|
||
assert_difference -> { @domain_airport.registrar.notifications.count } do | ||
Domains::ForceDeleteEmail::Base.run(email: contact.email) | ||
end | ||
|
||
@domain_airport.reload | ||
end | ||
|
||
private | ||
|
||
def prepare_contact | ||
assert_not @domain_airport.force_delete_scheduled? | ||
email = '~@internet.ee' | ||
|
||
contact = @domain_airport.admin_contacts.first | ||
contact.update_attribute(:email, email) | ||
(ValidationEvent::VALID_EVENTS_COUNT_THRESHOLD).times do | ||
contact.verify_email | ||
end | ||
contact.reload | ||
|
||
assert_not domain.force_delete_scheduled? | ||
refute contact.validation_events.last.success? | ||
assert contact.need_to_start_force_delete? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require 'test_helper' | ||
|
||
class OutzoneInvalidEmailDomainsJobTest < ActiveJob::TestCase | ||
include ActionMailer::TestHelper | ||
|
||
setup do | ||
ActionMailer::Base.deliveries.clear | ||
@domain = domains(:airport) | ||
end | ||
|
||
def test_set_outzone_datetime_for_fd_domains_by_invalid_emails | ||
@domain.update(valid_to: Time.zone.now + 3.years) | ||
@domain.reload | ||
|
||
assert_nil @domain.outzone_at | ||
|
||
@domain.schedule_force_delete(type: :soft) | ||
@domain.force_delete_data = {"template_name"=>"invalid_email", "force_delete_type"=>"soft"} | ||
@domain.save | ||
|
||
OutzoneInvalidEmailDomainsJob.perform_now | ||
@domain.reload | ||
|
||
assert @domain.force_delete_scheduled? | ||
assert @domain.valid_to > Time.zone.now + 1.year | ||
assert_equal @domain.outzone_at, @domain.force_delete_start + Setting.expire_warning_period.day | ||
end | ||
end |