Skip to content

Commit

Permalink
Add test for clear force delete on registrar change
Browse files Browse the repository at this point in the history
  • Loading branch information
yulgolem committed Jan 17, 2020
1 parent c252d80 commit e758124
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/models/concerns/domain/force_delete.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def force_delete_scheduled?

def should_notify_on_soft_force_delete?
force_delete_scheduled? && contact_notification_sent_date.blank? &&
force_delete_start.to_date == Time.zone.now.to_date && force_delete_type.to_sym == :soft
force_delete_start.to_date <= Time.zone.now.to_date && force_delete_type.to_sym == :soft
end

def client_holdable?
Expand Down
1 change: 1 addition & 0 deletions test/models/domain/force_delete_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def test_force_delete_soft_year_ahead_sets_client_hold
asserted_status = DomainStatus::CLIENT_HOLD

@domain.update(valid_to: Time.zone.parse('2012-08-05'))
@domain.update(template_name: 'legal_person')
assert_not @domain.force_delete_scheduled?
travel_to Time.zone.parse('2010-07-05')
@domain.schedule_force_delete(type: :soft)
Expand Down
17 changes: 16 additions & 1 deletion test/models/domain_cron_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,19 @@ def test_clean_expired_pendings_notifies_registrant_by_email

assert_emails 1
end
end

def test_client_hold
Setting.redemption_grace_period = 30

@domain.update(valid_to: Time.zone.parse('2012-08-05'))
assert_not @domain.force_delete_scheduled?
travel_to Time.zone.parse('2010-07-05')
@domain.schedule_force_delete(type: :soft)
@domain.reload
@domain.update(template_name: 'legal_person')
travel_to Time.zone.parse('2010-08-06')
DomainCron.start_client_hold

assert_emails 1
end
end
16 changes: 16 additions & 0 deletions test/models/domain_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,22 @@ def test_deactivation
assert_not domain.active?
end

def test_registrant_change_removes_force_delete
@domain.update_columns(valid_to: Time.zone.parse('2010-10-05'),
force_delete_date: nil)
@domain.update(template_name: 'legal_person')
travel_to Time.zone.parse('2010-07-05')
@domain.schedule_force_delete(type: :fast_track)
assert(@domain.force_delete_scheduled?)
other_registrant = Registrant.find_by(code: 'jane-001')
@domain.pending_json['new_registrant_id'] = other_registrant.id

@domain.registrant = other_registrant
@domain.save!

assert_not(@domain.force_delete_scheduled?)
end

private

def valid_domain
Expand Down
10 changes: 9 additions & 1 deletion test/system/admin_area/domains/force_delete_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,22 @@ def test_notifies_registrar
end
end

def test_notifies_registrant_and_admin_contacts_by_email_by_default
def test_notifies_registrant_and_admin_contacts_by_email_if_fast_delete
assert_emails 1 do
visit edit_admin_domain_url(@domain)
find(:css, '#soft_delete').set(false)
click_link_or_button 'Force delete domain'
end
end

def test_notifies_registrant_and_admin_contacts_by_email_if_soft_delete
assert_emails 0 do
visit edit_admin_domain_url(@domain)
find(:css, '#soft_delete').set(true)
click_link_or_button 'Force delete domain'
end
end

def test_allows_to_skip_notifying_registrant_and_admin_contacts_by_email
assert_no_emails do
visit edit_admin_domain_url(@domain)
Expand Down

0 comments on commit e758124

Please sign in to comment.