-
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.
Add force_delete_start field to ForceDelete & add tests
Add new test file new_force_delete_test.rb to check if new ForceDeleteProcedures are correct. ATM it's just a scaffold of some sort, all tests are red, magic numbers and so - just a proof of concept. See #1428
- Loading branch information
Showing
4 changed files
with
208 additions
and
2 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
5 changes: 5 additions & 0 deletions
5
db/migrate/20191203083643_add_force_delete_start_to_domains.rb
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,5 @@ | ||
class AddForceDeleteStartToDomains < ActiveRecord::Migration[5.0] | ||
def change | ||
add_column :domains, :force_delete_start, :datetime | ||
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
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,189 @@ | ||
require 'test_helper' | ||
|
||
class NewDomainForceDeleteTest < ActiveSupport::TestCase | ||
setup do | ||
@domain = domains(:shop) | ||
@original_redemption_grace_period = Setting.redemption_grace_period | ||
end | ||
|
||
teardown do | ||
Setting.redemption_grace_period = @original_redemption_grace_period | ||
end | ||
|
||
def test_force_delete_raises_on_wrong_type | ||
assert_raises StandardError do | ||
@domain.schedule_force_delete(type: :wrong_type) | ||
end | ||
end | ||
|
||
def test_schedules_force_delete_fast_track | ||
assert_not @domain.force_delete_scheduled? | ||
Setting.redemption_grace_period = 45 | ||
travel_to Time.zone.parse('2010-07-05') | ||
|
||
@domain.schedule_force_delete(type: :fast_track) | ||
@domain.reload | ||
|
||
assert @domain.force_delete_scheduled? | ||
assert_equal Date.parse('2010-08-19'), @domain.force_delete_date | ||
assert_equal Date.parse('2010-07-05'), @domain.force_delete_start | ||
end | ||
|
||
def test_schedules_force_delete_soft_year_ahead | ||
@domain.update(valid_to: Time.zone.parse('2012-08-05')) | ||
assert_not @domain.force_delete_scheduled? | ||
Setting.redemption_grace_period = 45 | ||
travel_to Time.zone.parse('2010-07-05') | ||
|
||
@domain.schedule_force_delete(type: :soft) | ||
@domain.reload | ||
|
||
assert @domain.force_delete_scheduled? | ||
assert_equal Date.parse('2010-09-19'), @domain.force_delete_date | ||
assert_equal Date.parse('2010-08-05'), @domain.force_delete_start.to_date | ||
assert (@domain.statuses.include?(DomainStatus::CLIENT_HOLD)) | ||
end | ||
|
||
def test_schedules_force_delete_soft_less_than_year_ahead | ||
@domain.update(valid_to: Time.zone.parse('2011-08-05')) | ||
assert_not @domain.force_delete_scheduled? | ||
Setting.redemption_grace_period = 45 | ||
travel_to Time.zone.parse('2010-07-05') | ||
|
||
@domain.schedule_force_delete(type: :soft) | ||
@domain.reload | ||
|
||
assert @domain.force_delete_scheduled? | ||
assert_equal Date.parse('2010-08-19'), @domain.force_delete_date | ||
assert_equal Date.parse('2010-07-05'), @domain.force_delete_start | ||
end | ||
|
||
def test_scheduling_soft_force_delete_adds_corresponding_statuses | ||
statuses_to_be_added = [ | ||
DomainStatus::FORCE_DELETE, | ||
DomainStatus::SERVER_RENEW_PROHIBITED, | ||
DomainStatus::SERVER_TRANSFER_PROHIBITED, | ||
] | ||
|
||
@domain.schedule_force_delete(type: :soft) | ||
@domain.reload | ||
assert (@domain.statuses & statuses_to_be_added) == statuses_to_be_added | ||
end | ||
|
||
def test_scheduling_fast_track_force_delete_adds_corresponding_statuses | ||
statuses_to_be_added = [ | ||
DomainStatus::FORCE_DELETE, | ||
DomainStatus::SERVER_RENEW_PROHIBITED, | ||
DomainStatus::SERVER_TRANSFER_PROHIBITED, | ||
] | ||
|
||
@domain.schedule_force_delete(type: :fast_track) | ||
@domain.reload | ||
assert (@domain.statuses & statuses_to_be_added) == statuses_to_be_added | ||
end | ||
|
||
def test_scheduling_force_delete_allows_domain_deletion | ||
statuses_to_be_removed = [ | ||
DomainStatus::CLIENT_DELETE_PROHIBITED, | ||
DomainStatus::SERVER_DELETE_PROHIBITED, | ||
] | ||
|
||
@domain.statuses = statuses_to_be_removed + %w[other-status] | ||
@domain.schedule_force_delete(type: :fast_track) | ||
@domain.reload | ||
assert_empty @domain.statuses & statuses_to_be_removed | ||
end | ||
|
||
def test_scheduling_force_delete_stops_pending_actions | ||
Setting.redemption_grace_period = 45 | ||
statuses_to_be_removed = [ | ||
DomainStatus::PENDING_UPDATE, | ||
DomainStatus::PENDING_TRANSFER, | ||
DomainStatus::PENDING_RENEW, | ||
DomainStatus::PENDING_CREATE, | ||
] | ||
|
||
@domain.statuses = statuses_to_be_removed + %w[other-status] | ||
@domain.schedule_force_delete(type: :fast_track) | ||
@domain.reload | ||
assert_empty @domain.statuses & statuses_to_be_removed, 'Pending actions should be stopped' | ||
end | ||
|
||
def test_scheduling_force_delete_preserves_current_statuses | ||
@domain.statuses = %w[test1 test2] | ||
@domain.schedule_force_delete(type: :fast_track) | ||
@domain.reload | ||
assert_equal %w[test1 test2], @domain.statuses_before_force_delete | ||
end | ||
|
||
def test_scheduling_force_delete_bypasses_validation | ||
@domain = domains(:invalid) | ||
@domain.schedule_force_delete(type: :fast_track) | ||
assert @domain.force_delete_scheduled? | ||
end | ||
|
||
def test_force_delete_cannot_be_scheduled_when_a_domain_is_discarded | ||
@domain.update!(statuses: [DomainStatus::DELETE_CANDIDATE]) | ||
assert_raises StandardError do | ||
@domain.schedule_force_delete(type: :fast_track) | ||
end | ||
end | ||
|
||
def test_force_delete_sets_client_hold_on_condition | ||
statuses_to_be_added = [DomainStatus::CLIENT_HOLD] | ||
@domain.update_columns(statuses: [DomainStatus::FORCE_DELETE], | ||
force_delete_date: Time.zone.parse('2010-08-05'), | ||
force_delete_start: Time.zone.parse('2010-08-05') - 45.days) | ||
travel_to Time.zone.parse('2010-07-05') | ||
assert @domain.force_delete_scheduled? | ||
|
||
@domain.check_hold | ||
assert (@domain.statuses & statuses_to_be_added) == statuses_to_be_added | ||
end | ||
|
||
def test_cancels_force_delete | ||
@domain.update_columns(statuses: [DomainStatus::FORCE_DELETE], | ||
force_delete_date: Time.zone.parse('2010-07-05'), | ||
force_delete_start: Time.zone.parse('2010-07-05') - 45.days) | ||
assert @domain.force_delete_scheduled? | ||
|
||
@domain.cancel_force_delete | ||
@domain.reload | ||
|
||
assert_not @domain.force_delete_scheduled? | ||
assert_nil @domain.force_delete_date | ||
assert_nil @domain.force_delete_start | ||
end | ||
|
||
def test_cancelling_force_delete_bypasses_validation | ||
@domain = domains(:invalid) | ||
@domain.schedule_force_delete(type: :fast_track) | ||
@domain.cancel_force_delete | ||
assert_not @domain.force_delete_scheduled? | ||
end | ||
|
||
def test_cancelling_force_delete_removes_statuses_that_were_set_on_force_delete | ||
statuses = [ | ||
DomainStatus::FORCE_DELETE, | ||
DomainStatus::SERVER_RENEW_PROHIBITED, | ||
DomainStatus::SERVER_TRANSFER_PROHIBITED, | ||
] | ||
@domain.statuses = @domain.statuses + statuses | ||
@domain.schedule_force_delete(type: :fast_track) | ||
|
||
@domain.cancel_force_delete | ||
@domain.reload | ||
|
||
assert_empty @domain.statuses & statuses | ||
end | ||
|
||
def test_cancelling_force_delete_restores_statuses_that_a_domain_had_before_force_delete | ||
@domain.statuses_before_force_delete = ['test1', DomainStatus::DELETE_CANDIDATE] | ||
|
||
@domain.cancel_force_delete | ||
@domain.reload | ||
|
||
assert_equal ['test1', DomainStatus::DELETE_CANDIDATE], @domain.statuses | ||
assert_nil @domain.statuses_before_force_delete | ||
end | ||
end |