require 'test_helper' class EppDomainTransferRequestTest < ActionDispatch::IntegrationTest def setup @domain = domains(:shop) Setting.transfer_wait_time = 0 end def test_transfers_domain_at_once post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_goodnames' } assert_equal '1000', Nokogiri::XML(response.body).at_css('result')[:code] assert_equal 1, Nokogiri::XML(response.body).css('result').size end def test_creates_new_domain_transfer assert_difference -> { @domain.transfers.size } do post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_goodnames' } end end def test_approves_automatically_if_auto_approval_is_enabled post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_goodnames' } assert_equal 'serverApproved', Nokogiri::XML(response.body).xpath('//domain:trStatus', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text end def test_changes_registrar post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_goodnames' } @domain.reload assert_equal registrars(:goodnames), @domain.registrar end def test_regenerates_transfer_code @old_transfer_code = @domain.transfer_code post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_goodnames' } @domain.reload refute_equal @domain.transfer_code, @old_transfer_code end def test_notifies_old_registrar @old_registrar = @domain.registrar assert_difference -> { @old_registrar.messages.count } do post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_goodnames' } end message = 'Domain transfer of shop.test has been approved.' \ ' Old contacts: jane-001, william-001' \ '; old registrant: john-001' assert_equal message, @old_registrar.messages.last.body end def test_duplicates_registrant_admin_and_tech_contacts assert_difference 'Contact.count', 3 do post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_goodnames' } end end def test_saves_legal_document assert_difference -> { @domain.legal_documents(true).size } do post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_goodnames' } end end def test_non_transferable_domain @domain.update!(statuses: [DomainStatus::SERVER_TRANSFER_PROHIBITED]) post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_bestnames' } domains(:shop).reload assert_equal registrars(:bestnames), domains(:shop).registrar assert_equal '2304', Nokogiri::XML(response.body).at_css('result')[:code] end def test_discarded_domain @domain.update!(statuses: [DomainStatus::DELETE_CANDIDATE]) post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_bestnames' } @domain.reload assert_equal registrars(:bestnames), @domain.registrar assert_equal '2105', Nokogiri::XML(response.body).at_css('result')[:code] end def test_wrong_transfer_code request_xml = <<-XML shop.test wrong XML post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_bestnames' } @domain.reload refute_equal registrars(:goodnames), @domain.registrar assert_equal '2201', Nokogiri::XML(response.body).at_css('result')[:code] end private def request_xml <<-XML shop.test 65078d5 test XML end end