diff --git a/test/integration/epp/domain/delete/base_test.rb b/test/integration/epp/domain/delete/base_test.rb index 3b5ef5032..0a2a4308a 100644 --- a/test/integration/epp/domain/delete/base_test.rb +++ b/test/integration/epp/domain/delete/base_test.rb @@ -1,8 +1,16 @@ require 'test_helper' class EppDomainDeleteBaseTest < ActionDispatch::IntegrationTest - def setup + include ActionMailer::TestHelper + + setup do @domain = domains(:shop) + @original_confirmation_setting = Setting.request_confirmation_on_domain_deletion_enabled + ActionMailer::Base.deliveries.clear + end + + teardown do + Setting.request_confirmation_on_domain_deletion_enabled = @original_confirmation_setting end def test_bypasses_domain_and_registrant_and_contacts_validation @@ -59,4 +67,181 @@ class EppDomainDeleteBaseTest < ActionDispatch::IntegrationTest end assert_equal '2105', Nokogiri::XML(response.body).at_css('result')[:code] end + + def test_requests_registrant_confirmation_when_required + assert_equal 'shop.test', @domain.name + Setting.request_confirmation_on_domain_deletion_enabled = true + + request_xml = <<-XML + + + + + + shop.test + + + + + dGVzdCBmYWlsCg== + + + + + XML + + post '/epp/command/delete', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' + @domain.reload + + assert @domain.registrant_verification_asked? + assert @domain.pending_delete_confirmation? + assert_emails 1 + response_xml = Nokogiri::XML(response.body) + assert_equal '1001', response_xml.at_css('result')[:code] + end + + def test_skips_registrant_confirmation_when_not_required + assert_equal 'shop.test', @domain.name + Setting.request_confirmation_on_domain_deletion_enabled = false + + request_xml = <<-XML + + + + + + shop.test + + + + + dGVzdCBmYWlsCg== + + + + + XML + + post '/epp/command/delete', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' + @domain.reload + + assert_not @domain.registrant_verification_asked? + assert_not @domain.pending_delete_confirmation? + assert_no_emails + response_xml = Nokogiri::XML(response.body) + assert_equal '1000', response_xml.at_css('result')[:code] + end + + def test_skips_registrant_confirmation_when_required_but_already_verified_by_registrar + assert_equal 'shop.test', @domain.name + Setting.request_confirmation_on_domain_deletion_enabled = true + + request_xml = <<-XML + + + + + + shop.test + + + + + dGVzdCBmYWlsCg== + + + + + XML + + post '/epp/command/delete', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' + @domain.reload + + assert_not @domain.registrant_verification_asked? + assert_not @domain.pending_delete_confirmation? + assert_no_emails + response_xml = Nokogiri::XML(response.body) + assert_equal '1000', response_xml.at_css('result')[:code] + end + + def test_legal_document_is_required + assert_equal 'shop.test', @domain.name + + request_xml = <<-XML + + + + + + shop.test + + + + + XML + + post '/epp/command/delete', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' + + response_xml = Nokogiri::XML(response.body) + assert_equal '2003', response_xml.at_css('result')[:code] + assert_equal 'Required parameter missing: extension > extdata > legalDocument [legal_document]', + response_xml.at_css('result msg').text + end + + def test_domain_cannot_be_deleted_when_explicitly_prohibited_by_registrar + assert_equal 'shop.test', @domain.name + @domain.update!(statuses: [DomainStatus::CLIENT_DELETE_PROHIBITED]) + + request_xml = <<-XML + + + + + + shop.test + + + + + dGVzdCBmYWlsCg== + + + + + XML + + post '/epp/command/delete', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' + + response_xml = Nokogiri::XML(response.body) + assert_equal '2304', response_xml.at_css('result')[:code] + assert_equal 'Domain status prohibits operation', response_xml.at_css('result msg').text + end + + def test_domain_not_found + assert_nil Domain.find_by(name: 'non-existing.test') + + request_xml = <<-XML + + + + + + non-existing.test + + + + + dGVzdCBmYWlsCg== + + + + + XML + + post '/epp/command/delete', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' + + response_xml = Nokogiri::XML(response.body) + assert_equal '2303', response_xml.at_css('result')[:code] + assert_equal 'Domain not found', response_xml.at_css('result msg').text + end end \ No newline at end of file