From 89bf6f040194aba7d02e5c388a0eea1a51fe1093 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 17 Sep 2019 13:50:13 +0300 Subject: [PATCH 1/3] Add EPP domain:renew tests --- .../epp/domain/domain_renew_test.rb | 127 ++++++++++++++++++ 1 file changed, 127 insertions(+) diff --git a/test/integration/epp/domain/domain_renew_test.rb b/test/integration/epp/domain/domain_renew_test.rb index e1dfbdae1b..8ab598102c 100644 --- a/test/integration/epp/domain/domain_renew_test.rb +++ b/test/integration/epp/domain/domain_renew_test.rb @@ -4,9 +4,36 @@ class EppDomainRenewTest < EppTestCase self.use_transactional_fixtures = false setup do + @domain = domains(:shop) travel_to Time.zone.parse('2010-07-05') end + def test_renews_domain + travel_to Time.zone.parse('2010-07-05') + original_valid_to = @domain.valid_to + default_renewal_period = 1.year + request_xml = <<-XML + + + + + + #{@domain.name} + #{@domain.expire_time.to_date} + 1 + + + + + XML + + post '/epp/command/renew', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' + @domain.reload + + assert_epp_response :completed_successfully + assert_equal original_valid_to + default_renewal_period, @domain.valid_to + end + def test_domain_cannot_be_renewed_when_invalid request_xml = <<-XML @@ -28,4 +55,104 @@ def test_domain_cannot_be_renewed_when_invalid end assert_epp_response :object_status_prohibits_operation end + + def test_domain_cannot_be_renewed_when_belongs_to_another_registrar + session = epp_sessions(:api_bestnames) + domain = domains(:metro) + assert_not_equal session.user.registrar, domain.registrar + + request_xml = <<-XML + + + + + + #{domain.name} + #{domain.valid_to.to_date} + 1 + + + + + XML + + assert_no_changes -> { domains(:invalid).valid_to } do + post '/epp/command/renew', { frame: request_xml }, + 'HTTP_COOKIE' => "session=#{session.session_id}" + end + assert_epp_response :authorization_error + end + + def test_insufficient_funds + session = epp_sessions(:api_bestnames) + session.user.registrar.accounts.first.update!(balance: 0) + request_xml = <<-XML + + + + + + #{@domain.name} + #{@domain.expire_time.to_date} + 1 + + + + + XML + + @domain.reload + assert_no_difference -> { @domain.valid_to } do + post '/epp/command/renew', { frame: request_xml }, 'HTTP_COOKIE' => "session=#{session.session_id}" + end + assert_epp_response :billing_failure + end + + def test_no_price + assert_nil Billing::Price.find_by(duration: '2 months') + + request_xml = <<-XML + + + + + + #{@domain.name} + #{@domain.expire_time.to_date} + 2 + + + + + XML + + assert_no_changes -> { @domain.valid_to } do + post '/epp/command/renew', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' + end + assert_epp_response :billing_failure + end + + def test_fails_when_provided_expiration_date_is_wrong + provided_expiration_date = Date.parse('2010-07-06') + assert_not_equal provided_expiration_date, @domain.valid_to + + request_xml = <<-XML + + + + + + #{@domain.name} + #{provided_expiration_date} + + + + + XML + + assert_no_changes -> { @domain.valid_to } do + post '/epp/command/renew', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' + end + assert_epp_response :parameter_value_policy_error + end end From 06cc6430be95ea8bd59f0452e9c6928f4c77c9fb Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 17 Sep 2019 13:58:07 +0300 Subject: [PATCH 2/3] Improve readability --- .../epp/domain/domain_renew_test.rb | 60 +++++++++++-------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/test/integration/epp/domain/domain_renew_test.rb b/test/integration/epp/domain/domain_renew_test.rb index 8ab598102c..7884db86f3 100644 --- a/test/integration/epp/domain/domain_renew_test.rb +++ b/test/integration/epp/domain/domain_renew_test.rb @@ -3,23 +3,20 @@ class EppDomainRenewTest < EppTestCase self.use_transactional_fixtures = false - setup do - @domain = domains(:shop) - travel_to Time.zone.parse('2010-07-05') - end - def test_renews_domain travel_to Time.zone.parse('2010-07-05') - original_valid_to = @domain.valid_to + domain = domains(:shop) + original_valid_to = domain.valid_to default_renewal_period = 1.year + request_xml = <<-XML - #{@domain.name} - #{@domain.expire_time.to_date} + #{domain.name} + #{domain.expire_time.to_date} 1 @@ -28,21 +25,23 @@ def test_renews_domain XML post '/epp/command/renew', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' - @domain.reload + domain.reload assert_epp_response :completed_successfully - assert_equal original_valid_to + default_renewal_period, @domain.valid_to + assert_equal original_valid_to + default_renewal_period, domain.valid_to end def test_domain_cannot_be_renewed_when_invalid + domain = domains(:invalid) + request_xml = <<-XML - invalid.test - 2010-07-05 + #{domain.name} + #{domain.valid_to.to_date} 1 @@ -50,15 +49,16 @@ def test_domain_cannot_be_renewed_when_invalid XML - assert_no_changes -> { domains(:invalid).valid_to } do + assert_no_changes -> { domain.valid_to } do post '/epp/command/renew', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' + domain.reload end assert_epp_response :object_status_prohibits_operation end def test_domain_cannot_be_renewed_when_belongs_to_another_registrar - session = epp_sessions(:api_bestnames) domain = domains(:metro) + session = epp_sessions(:api_bestnames) assert_not_equal session.user.registrar, domain.registrar request_xml = <<-XML @@ -76,24 +76,27 @@ def test_domain_cannot_be_renewed_when_belongs_to_another_registrar XML - assert_no_changes -> { domains(:invalid).valid_to } do + assert_no_changes -> { domain.valid_to } do post '/epp/command/renew', { frame: request_xml }, 'HTTP_COOKIE' => "session=#{session.session_id}" + domain.reload end assert_epp_response :authorization_error end def test_insufficient_funds + domain = domains(:shop) session = epp_sessions(:api_bestnames) session.user.registrar.accounts.first.update!(balance: 0) + request_xml = <<-XML - #{@domain.name} - #{@domain.expire_time.to_date} + #{domain.name} + #{domain.expire_time.to_date} 1 @@ -101,14 +104,16 @@ def test_insufficient_funds XML - @domain.reload - assert_no_difference -> { @domain.valid_to } do - post '/epp/command/renew', { frame: request_xml }, 'HTTP_COOKIE' => "session=#{session.session_id}" + assert_no_difference -> { domain.valid_to } do + post '/epp/command/renew', { frame: request_xml }, 'HTTP_COOKIE' => + "session=#{session.session_id}" + domain.reload end assert_epp_response :billing_failure end def test_no_price + domain = domains(:shop) assert_nil Billing::Price.find_by(duration: '2 months') request_xml = <<-XML @@ -117,8 +122,8 @@ def test_no_price - #{@domain.name} - #{@domain.expire_time.to_date} + #{domain.name} + #{domain.expire_time.to_date} 2 @@ -126,15 +131,17 @@ def test_no_price XML - assert_no_changes -> { @domain.valid_to } do + assert_no_changes -> { domain.valid_to } do post '/epp/command/renew', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' + domain.reload end assert_epp_response :billing_failure end def test_fails_when_provided_expiration_date_is_wrong + domain = domains(:shop) provided_expiration_date = Date.parse('2010-07-06') - assert_not_equal provided_expiration_date, @domain.valid_to + assert_not_equal provided_expiration_date, domain.valid_to request_xml = <<-XML @@ -142,7 +149,7 @@ def test_fails_when_provided_expiration_date_is_wrong - #{@domain.name} + #{domain.name} #{provided_expiration_date} @@ -150,8 +157,9 @@ def test_fails_when_provided_expiration_date_is_wrong XML - assert_no_changes -> { @domain.valid_to } do + assert_no_changes -> { domain.valid_to } do post '/epp/command/renew', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' + domain.reload end assert_epp_response :parameter_value_policy_error end From 7254fd49742cf9ad3c17949f80a68f1f4039aa3a Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 17 Sep 2019 13:59:09 +0300 Subject: [PATCH 3/3] Move tests --- .../epp/domain/{domain_renew_test.rb => renew/base_test.rb} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename test/integration/epp/domain/{domain_renew_test.rb => renew/base_test.rb} (99%) diff --git a/test/integration/epp/domain/domain_renew_test.rb b/test/integration/epp/domain/renew/base_test.rb similarity index 99% rename from test/integration/epp/domain/domain_renew_test.rb rename to test/integration/epp/domain/renew/base_test.rb index 7884db86f3..537e697c9e 100644 --- a/test/integration/epp/domain/domain_renew_test.rb +++ b/test/integration/epp/domain/renew/base_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class EppDomainRenewTest < EppTestCase +class EppDomainRenewBaseTest < EppTestCase self.use_transactional_fixtures = false def test_renews_domain