From 4ab6821d8a21e7c2b57d6d7f9b47b08787795632 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sun, 18 Feb 2018 05:08:28 +0200 Subject: [PATCH] Improve tests #694 --- test/fixtures/contacts.yml | 11 +++ test/fixtures/domain_contacts.yml | 5 ++ test/fixtures/domain_transfers.yml | 7 ++ test/integration/api/domain_transfers_test.rb | 49 ++++++++-- .../{transfer_code_test.rb => base_test.rb} | 11 ++- .../domain/transfer/domain_transfer_test.rb | 49 ---------- .../epp/domain/transfer/query_test.rb | 74 +++++++++++++++ .../epp/domain/transfer/request_test.rb | 90 +++++++++++++++++++ ...main_transfer_test.rb => transfer_test.rb} | 18 ---- 9 files changed, 236 insertions(+), 78 deletions(-) create mode 100644 test/fixtures/domain_transfers.yml rename test/integration/epp/domain/transfer/{transfer_code_test.rb => base_test.rb} (65%) delete mode 100644 test/integration/epp/domain/transfer/domain_transfer_test.rb create mode 100644 test/integration/epp/domain/transfer/query_test.rb create mode 100644 test/integration/epp/domain/transfer/request_test.rb rename test/models/domain/{domain_transfer_test.rb => transfer_test.rb} (78%) diff --git a/test/fixtures/contacts.yml b/test/fixtures/contacts.yml index 8c0fb4e10..eaf4401b7 100644 --- a/test/fixtures/contacts.yml +++ b/test/fixtures/contacts.yml @@ -9,6 +9,17 @@ john: code: john-001 auth_info: cacb5b +william: + name: William + email: william@inbox.test + phone: '+555.555' + ident: 1234 + ident_type: priv + ident_country_code: US + registrar: bestnames + code: william-001 + auth_info: 6573d0 + jane: name: Jane email: jane@mail.test diff --git a/test/fixtures/domain_contacts.yml b/test/fixtures/domain_contacts.yml index fd60e8c99..3442278a1 100644 --- a/test/fixtures/domain_contacts.yml +++ b/test/fixtures/domain_contacts.yml @@ -3,6 +3,11 @@ shop_jane: contact: jane type: AdminDomainContact +shop_william: + domain: shop + contact: william + type: TechDomainContact + airport_john: domain: airport contact: john diff --git a/test/fixtures/domain_transfers.yml b/test/fixtures/domain_transfers.yml new file mode 100644 index 000000000..c8b4181f2 --- /dev/null +++ b/test/fixtures/domain_transfers.yml @@ -0,0 +1,7 @@ +shop: + status: serverApproved + transfer_requested_at: 2010-07-05 + transferred_at: 2010-07-05 + domain: shop + old_registrar: bestnames + new_registrar: goodnames diff --git a/test/integration/api/domain_transfers_test.rb b/test/integration/api/domain_transfers_test.rb index 8d6cd6c5e..80c637eaa 100644 --- a/test/integration/api/domain_transfers_test.rb +++ b/test/integration/api/domain_transfers_test.rb @@ -1,11 +1,12 @@ require 'test_helper' class APIDomainTransfersTest < ActionDispatch::IntegrationTest - def test_transfers_domain - request_params = { format: :json, - data: { domainTransfers: [{ domainName: 'shop.test', transferCode: '65078d5' }] } } + def setup + @domain = domains(:shop) + end + + def test_returns_domain_transfers post '/repp/v1/domain_transfers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key } - assert_equal registrars(:goodnames), domains(:shop).registrar assert_response 200 assert_equal ({ data: [{ type: 'domain_transfer' @@ -13,6 +14,39 @@ class APIDomainTransfersTest < ActionDispatch::IntegrationTest JSON.parse(response.body, symbolize_names: true) end + def test_approves_automatically + post '/repp/v1/domain_transfers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key } + assert @domain.domain_transfers.last.approved? + end + + def test_changes_registrar + post '/repp/v1/domain_transfers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key } + @domain.reload + assert_equal registrars(:goodnames), @domain.registrar + end + + def test_regenerates_transfer_code + @old_transfer_code = @domain.transfer_code + + post '/repp/v1/domain_transfers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key } + @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 '/repp/v1/domain_transfers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key } + end + end + + def test_creates_copy_of_registrant_admin_and_tech_contacts + assert_difference 'Contact.count', 3 do + post '/repp/v1/domain_transfers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key } + end + end + def test_fails_if_domain_does_not_exist request_params = { format: :json, data: { domainTransfers: [{ domainName: 'non-existent.test', transferCode: 'any' }] } } @@ -27,13 +61,18 @@ class APIDomainTransfersTest < ActionDispatch::IntegrationTest data: { domainTransfers: [{ domainName: 'shop.test', transferCode: 'wrong' }] } } post '/repp/v1/domain_transfers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key } assert_response 400 - refute_equal registrars(:goodnames), domains(:shop).registrar + refute_equal registrars(:goodnames), @domain.registrar assert_equal ({ errors: [{ title: 'shop.test transfer code is wrong' }] }), JSON.parse(response.body, symbolize_names: true) end private + def request_params + { format: :json, + data: { domainTransfers: [{ domainName: 'shop.test', transferCode: '65078d5' }] } } + end + def http_auth_key ActionController::HttpAuthentication::Basic.encode_credentials('test_goodnames', 'testtest') end diff --git a/test/integration/epp/domain/transfer/transfer_code_test.rb b/test/integration/epp/domain/transfer/base_test.rb similarity index 65% rename from test/integration/epp/domain/transfer/transfer_code_test.rb rename to test/integration/epp/domain/transfer/base_test.rb index 0509d632a..aa9f841b6 100644 --- a/test/integration/epp/domain/transfer/transfer_code_test.rb +++ b/test/integration/epp/domain/transfer/base_test.rb @@ -1,16 +1,16 @@ require 'test_helper' -class EppDomainTransferTransferCodeTest < ActionDispatch::IntegrationTest - def test_wrong +class EppDomainTransferBaseTest < ActionDispatch::IntegrationTest + def test_non_existent_domain request_xml = <<-XML - shop.test + non-existent.test - wrong + any @@ -19,7 +19,6 @@ class EppDomainTransferTransferCodeTest < ActionDispatch::IntegrationTest XML post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_goodnames' } - refute_equal registrars(:goodnames), domains(:shop).registrar - assert_equal '2201', Nokogiri::XML(response.body).at_css('result')[:code] + assert_equal '2303', Nokogiri::XML(response.body).at_css('result')[:code] end end diff --git a/test/integration/epp/domain/transfer/domain_transfer_test.rb b/test/integration/epp/domain/transfer/domain_transfer_test.rb deleted file mode 100644 index 38b7a2757..000000000 --- a/test/integration/epp/domain/transfer/domain_transfer_test.rb +++ /dev/null @@ -1,49 +0,0 @@ -require 'test_helper' - -class EppDomainTransferTest < ActionDispatch::IntegrationTest - def test_transfers_domain_at_once_if_auto_confirm_is_enabled - Setting.transfer_wait_time = 0 - - request_xml = <<-XML - - - - - - shop.test - - 65078d5 - - - - - - XML - - post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_goodnames' } - assert_equal registrars(:goodnames), domains(:shop).registrar - assert_equal '1000', Nokogiri::XML(response.body).at_css('result')[:code] - assert_equal 1, Nokogiri::XML(response.body).css('result').size - end - - def test_non_existent_domain - request_xml = <<-XML - - - - - - non-existent.test - - any - - - - - - XML - - post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_goodnames' } - assert_equal '2303', Nokogiri::XML(response.body).at_css('result')[:code] - end -end diff --git a/test/integration/epp/domain/transfer/query_test.rb b/test/integration/epp/domain/transfer/query_test.rb new file mode 100644 index 000000000..0097a43f4 --- /dev/null +++ b/test/integration/epp/domain/transfer/query_test.rb @@ -0,0 +1,74 @@ +require 'test_helper' + +class EppDomainTransferQueryTest < ActionDispatch::IntegrationTest + def test_domain_transfer_details + request_xml = <<-XML + + + + + + shop.test + + 65078d5 + + + + + + XML + + post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_bestnames' } + xml_doc = Nokogiri::XML(response.body) + assert_equal '1000', xml_doc.at_css('result')[:code] + assert_equal 1, xml_doc.css('result').size + assert_equal 'shop.test', xml_doc.xpath('//domain:name', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text + assert_equal 'serverApproved', xml_doc.xpath('//domain:trStatus', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text + assert_equal 'goodnames', xml_doc.xpath('//domain:reID', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text + assert_equal 'bestnames', xml_doc.xpath('//domain:acID', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text + 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' } + assert_equal '2201', Nokogiri::XML(response.body).at_css('result')[:code] + end + + def test_no_domain_transfer + domains(:shop).domain_transfers.delete_all + + request_xml = <<-XML + + + + + + shop.test + + 65078d5 + + + + + + XML + + post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_bestnames' } + assert_equal '2303', Nokogiri::XML(response.body).at_css('result')[:code] + end +end diff --git a/test/integration/epp/domain/transfer/request_test.rb b/test/integration/epp/domain/transfer/request_test.rb new file mode 100644 index 000000000..981223d1e --- /dev/null +++ b/test/integration/epp/domain/transfer/request_test.rb @@ -0,0 +1,90 @@ +require 'test_helper' + +class EppDomainTransferRequestTest < ActionDispatch::IntegrationTest + def setup + @domain = domains(:shop) + Setting.transfer_wait_time = 0 + end + + def test_transfers_domain_at_once_if_auto_approval_is_enabled + 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_approves_automatically + post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_goodnames' } + assert @domain.domain_transfers.last.approved? + 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 + end + + def test_creates_copy_of_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_wrong_transfer_code + request_xml = <<-XML + + + + + + shop.test + + wrong + + + + + + XML + + post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_goodnames' } + 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 + + + + + + XML + end +end diff --git a/test/models/domain/domain_transfer_test.rb b/test/models/domain/transfer_test.rb similarity index 78% rename from test/models/domain/domain_transfer_test.rb rename to test/models/domain/transfer_test.rb index 9f86615e3..7b4e83138 100644 --- a/test/models/domain/domain_transfer_test.rb +++ b/test/models/domain/transfer_test.rb @@ -46,24 +46,6 @@ class DomainTransferTest < ActiveSupport::TestCase refute_same old_transfer_code, @domain.transfer_code end - def test_creates_domain_transfer - assert_difference 'DomainTransfer.count' do - @domain.transfer(@new_registrar) - end - end - - def test_notifies_old_registrar - assert_difference 'Message.count' do - @domain.transfer(@new_registrar) - end - end - - def test_copies_contacts - assert_difference 'Contact.count', 2 do - @domain.transfer(@new_registrar) - end - end - def test_bypasses_domain_validation domain = domains(:invalid) domain.transfer(@new_registrar)