From 348e6e5d7a98ba60e196f0472751d67b72221441 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Tue, 3 Sep 2019 18:15:58 +0300 Subject: [PATCH] Introduce custom assertion --- app/models/epp/response.rb | 23 +++-- app/models/epp/response/result.rb | 23 +---- app/models/epp/response/result/code.rb | 81 ++++++++++++++++++ spec/models/epp/response/result_spec.rb | 21 ----- spec/rails_helper.rb | 3 - .../requests/epp/contact/create/ident_spec.rb | 20 ++--- spec/requests/epp/contact/shared/phone.rb | 6 +- .../requests/epp/contact/update/ident_spec.rb | 12 +-- .../epp/domain/create/account_balance_spec.rb | 4 +- .../epp/domain/create/default_period_spec.rb | 2 +- .../domain/create/optional_nameserver_spec.rb | 4 +- .../requests/epp/domain/create/period_spec.rb | 4 +- spec/requests/epp/domain/create/price_spec.rb | 4 +- .../domain/create/required_nameserver_spec.rb | 4 +- .../epp/domain/renew/account_balance_spec.rb | 4 +- .../epp/domain/renew/default_period_spec.rb | 2 +- .../epp/domain/renew/expire_time_spec.rb | 4 +- spec/requests/epp/domain/renew/period_spec.rb | 4 +- spec/requests/epp/domain/renew/price_spec.rb | 4 +- .../registrant_change/same_as_current_spec.rb | 8 +- .../update/registrant_change/verified_spec.rb | 8 +- spec/support/matchers/epp/code.rb | 39 --------- spec/support/matchers/epp/have_result.rb | 37 -------- spec/support/requests/epp_helpers.rb | 8 -- .../epp/contact/check/base_test.rb | 5 +- .../epp/contact/create/base_test.rb | 6 +- .../epp/contact/delete/base_test.rb | 9 +- .../integration/epp/contact/info/base_test.rb | 8 +- .../epp/contact/update/base_test.rb | 9 +- .../epp/domain/check/auction_test.rb | 17 ++-- .../integration/epp/domain/check/base_test.rb | 5 +- .../epp/domain/create/auction_idn_test.rb | 36 ++------ .../epp/domain/create/auction_test.rb | 35 ++------ .../epp/domain/create/base_test.rb | 7 +- .../epp/domain/create/nameservers_test.rb | 4 +- .../epp/domain/create/reserved_test.rb | 19 +---- .../epp/domain/create/transfer_code_test.rb | 8 +- .../epp/domain/delete/base_test.rb | 29 ++----- .../epp/domain/domain_renew_test.rb | 5 +- .../epp/domain/domain_update_test.rb | 7 +- test/integration/epp/domain/info/base_test.rb | 9 +- .../epp/domain/transfer/base_test.rb | 5 +- .../epp/domain/transfer/query_test.rb | 11 +-- .../epp/domain/transfer/request_test.rb | 16 ++-- .../integration/epp/login/credentials_test.rb | 10 +-- .../epp/login/password_change_test.rb | 5 +- .../epp/login/session_limit_test.rb | 9 +- test/integration/epp/logout_test.rb | 7 +- test/integration/epp/poll_test.rb | 20 ++--- test/models/epp/response/result/code_test.rb | 84 +++++++++++++++++++ test/models/epp/response/result_test.rb | 5 ++ test/models/epp/response_test.rb | 29 +++++++ test/support/assertions/epp_assertions.rb | 14 ++++ test/test_helper.rb | 5 ++ 54 files changed, 378 insertions(+), 389 deletions(-) create mode 100644 app/models/epp/response/result/code.rb delete mode 100644 spec/models/epp/response/result_spec.rb delete mode 100644 spec/support/matchers/epp/code.rb delete mode 100644 spec/support/matchers/epp/have_result.rb create mode 100644 test/models/epp/response/result/code_test.rb create mode 100644 test/models/epp/response/result_test.rb create mode 100644 test/models/epp/response_test.rb create mode 100644 test/support/assertions/epp_assertions.rb diff --git a/app/models/epp/response.rb b/app/models/epp/response.rb index c9a5d8bb4..eb61c02a4 100644 --- a/app/models/epp/response.rb +++ b/app/models/epp/response.rb @@ -1,22 +1,27 @@ -module EPP +module Epp class Response - attr_accessor :results + attr_reader :results - def self.from_xml(xml) + def self.xml(xml) xml_doc = Nokogiri::XML(xml) - response = new - result_elements = xml_doc.css('result') + results = [] result_elements.each do |result_element| - response.results << Result.new(result_element[:code].to_s, result_element.text.strip) + code_value = result_element[:code] + code = Result::Code.new(code_value) + results << Result.new(code: code) end - response + new(results: results) end - def initialize - @results = [] + def initialize(results:) + @results = results + end + + def code?(code) + results.any? { |result| result.code == code } end end end diff --git a/app/models/epp/response/result.rb b/app/models/epp/response/result.rb index 5c870c830..2bbf6cbf8 100644 --- a/app/models/epp/response/result.rb +++ b/app/models/epp/response/result.rb @@ -1,27 +1,10 @@ -module EPP +module Epp class Response class Result - CODE_TO_TYPE = { - '1000' => :success, - '1001' => :success_pending, - '1300' => :success_empty_queue, - '1301' => :success_dequeue, - '2001' => :syntax_error, - '2003' => :required_param_missing, - '2005' => :param_syntax_error, - '2308' => :data_management_policy_violation - } + attr_reader :code - attr_accessor :code - attr_accessor :message - - def initialize(code, message) + def initialize(code:) @code = code - @message = message - end - - def self.codes - CODE_TO_TYPE end end end diff --git a/app/models/epp/response/result/code.rb b/app/models/epp/response/result/code.rb new file mode 100644 index 000000000..2566279f5 --- /dev/null +++ b/app/models/epp/response/result/code.rb @@ -0,0 +1,81 @@ +module Epp + class Response + class Result + class Code + attr_reader :value + + KEY_TO_VALUE = { + completed_successfully: 1000, + completed_successfully_action_pending: 1001, + completed_successfully_no_messages: 1300, + completed_successfully_ack_to_dequeue: 1301, + completed_successfully_ending_session: 1500, + unknown_command: 2000, + syntax_error: 2001, + use_error: 2002, + required_parameter_missing: 2003, + parameter_value_range_error: 2004, + parameter_value_syntax_error: 2005, + billing_failure: 2104, + object_is_not_eligible_for_renewal: 2105, + authorization_error: 2201, + invalid_authorization_information: 2202, + object_does_not_exist: 2303, + object_status_prohibits_operation: 2304, + object_association_prohibits_operation: 2305, + parameter_value_policy_error: 2306, + data_management_policy_violation: 2308, + authentication_error_server_closing_connection: 2501, + }.freeze + private_constant :KEY_TO_VALUE + + DEFAULT_DESCRIPTIONS = { + 1000 => 'Command completed successfully', + 1001 => 'Command completed successfully; action pending', + 1300 => 'Command completed successfully; no messages', + 1301 => 'Command completed successfully; ack to dequeue', + 1500 => 'Command completed successfully; ending session', + 2000 => 'Unknown command', + 2001 => 'Command syntax error', + 2002 => 'Command use error', + 2003 => 'Required parameter missing', + 2004 => 'Parameter value range error', + 2005 => 'Parameter value syntax error', + 2104 => 'Billing failure', + 2105 => 'Object is not eligible for renewal', + 2201 => 'Authorization error', + 2202 => 'Invalid authorization information', + 2303 => 'Object does not exist', + 2304 => 'Object status prohibits operation', + 2305 => 'Object association prohibits operation', + 2306 => 'Parameter value policy error', + 2308 => 'Data management policy violation', + 2501 => 'Authentication error; server closing connection', + }.freeze + private_constant :DEFAULT_DESCRIPTIONS + + def self.codes + KEY_TO_VALUE + end + + def self.default_descriptions + DEFAULT_DESCRIPTIONS + end + + def self.key(key) + new(KEY_TO_VALUE[key]) + end + + def initialize(value) + value = value.to_i + raise ArgumentError, "Invalid value: #{value}" unless KEY_TO_VALUE.value?(value) + @value = value + end + + def ==(other) + value == other.value + end + end + end + end +end diff --git a/spec/models/epp/response/result_spec.rb b/spec/models/epp/response/result_spec.rb deleted file mode 100644 index 606a4c2de..000000000 --- a/spec/models/epp/response/result_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require 'rails_helper' - -RSpec.describe EPP::Response::Result, db: false do - # https://tools.ietf.org/html/rfc5730#section-3 - describe '::codes' do - it 'returns codes' do - codes = { - '1000' => :success, - '1001' => :success_pending, - '1300' => :success_empty_queue, - '1301' => :success_dequeue, - '2001' => :syntax_error, - '2003' => :required_param_missing, - '2005' => :param_syntax_error, - '2308' => :data_management_policy_violation - } - - expect(described_class.codes).to eq(codes) - end - end -end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index aead0dfa5..85a9832e9 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -8,8 +8,6 @@ require 'support/requests/session_helpers' require 'support/requests/epp_helpers' require 'support/features/session_helpers' require 'support/matchers/alias_attribute' -require 'support/matchers/epp/code' -require 'support/matchers/epp/have_result' require 'support/capybara' require 'support/devise' @@ -30,7 +28,6 @@ RSpec.configure do |config| config.include AbstractController::Translation, type: :feature config.include AbstractController::Translation, type: :mailer config.include Requests::EPPHelpers, epp: true - config.include Matchers::EPP, epp: true config.include Devise::Test::IntegrationHelpers, type: :feature config.include Devise::Test::IntegrationHelpers, type: :request diff --git a/spec/requests/epp/contact/create/ident_spec.rb b/spec/requests/epp/contact/create/ident_spec.rb index f4f785f4a..2de0e59a1 100644 --- a/spec/requests/epp/contact/create/ident_spec.rb +++ b/spec/requests/epp/contact/create/ident_spec.rb @@ -52,7 +52,7 @@ RSpec.describe 'EPP contact:create' do specify do request - expect(epp_response).to have_result(:success) + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy end end @@ -86,8 +86,7 @@ RSpec.describe 'EPP contact:create' do specify do request - expect(epp_response).to have_result(:required_param_missing, - 'Required parameter missing: extension > extdata > ident [ident]') + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:required_parameter_missing))).to be_truthy end end @@ -130,9 +129,7 @@ RSpec.describe 'EPP contact:create' do specify do request - - message = 'Ident code does not conform to national identification number format of Germany' - expect(epp_response).to have_result(:param_syntax_error, message) + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:parameter_value_syntax_error))).to be_truthy end end @@ -174,8 +171,7 @@ RSpec.describe 'EPP contact:create' do specify do request - expect(epp_response).to have_result(:param_syntax_error, - 'Ident code does not conform to registration number format of Germany') + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:parameter_value_syntax_error))).to be_truthy end end @@ -209,8 +205,7 @@ RSpec.describe 'EPP contact:create' do specify do request - expect(epp_response).to have_result(:required_param_missing, - 'Required ident attribute missing: cc') + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:required_parameter_missing))).to be_truthy end end @@ -244,7 +239,7 @@ RSpec.describe 'EPP contact:create' do specify do request - expect(epp_response).to have_result(:syntax_error) + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:syntax_error))).to be_truthy end end @@ -285,8 +280,7 @@ RSpec.describe 'EPP contact:create' do specify do request - expect(epp_response).to have_result(:param_syntax_error, - 'Ident type "priv" is invalid for Germany') + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:parameter_value_syntax_error))).to be_truthy end end end diff --git a/spec/requests/epp/contact/shared/phone.rb b/spec/requests/epp/contact/shared/phone.rb index 3ae9f22df..51a0a758c 100644 --- a/spec/requests/epp/contact/shared/phone.rb +++ b/spec/requests/epp/contact/shared/phone.rb @@ -4,7 +4,7 @@ RSpec.shared_examples 'EPP contact phone' do specify do request - expect(response).to have_code_of(1000) + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy end end @@ -13,7 +13,7 @@ RSpec.shared_examples 'EPP contact phone' do specify do request - expect(response).to have_code_of(2005) + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:parameter_value_syntax_error))).to be_truthy end end @@ -22,7 +22,7 @@ RSpec.shared_examples 'EPP contact phone' do specify do request - expect(response).to have_code_of(2005) + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:parameter_value_syntax_error))).to be_truthy end end end diff --git a/spec/requests/epp/contact/update/ident_spec.rb b/spec/requests/epp/contact/update/ident_spec.rb index 25f57389f..c8e1fe389 100644 --- a/spec/requests/epp/contact/update/ident_spec.rb +++ b/spec/requests/epp/contact/update/ident_spec.rb @@ -45,7 +45,7 @@ RSpec.describe 'EPP contact:update' do specify do request - expect(epp_response).to have_result(:success) + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy end end @@ -78,9 +78,7 @@ RSpec.describe 'EPP contact:update' do specify do request - - expect(epp_response).to have_result(:data_management_policy_violation, - t('epp.contacts.errors.valid_ident')) + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:data_management_policy_violation))).to be_truthy end end end @@ -138,7 +136,7 @@ RSpec.describe 'EPP contact:update' do specify do request - expect(epp_response).to have_result(:success) + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy end end @@ -190,9 +188,7 @@ RSpec.describe 'EPP contact:update' do specify do request - - expect(epp_response).to have_result(:data_management_policy_violation, - t('epp.contacts.errors.ident_update')) + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:data_management_policy_violation))).to be_truthy end end end diff --git a/spec/requests/epp/domain/create/account_balance_spec.rb b/spec/requests/epp/domain/create/account_balance_spec.rb index 1692a1797..d4acc7141 100644 --- a/spec/requests/epp/domain/create/account_balance_spec.rb +++ b/spec/requests/epp/domain/create/account_balance_spec.rb @@ -49,7 +49,7 @@ RSpec.describe 'EPP domain:create', settings: false do specify do request - expect(response).to have_code_of(1000) + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy end end @@ -62,7 +62,7 @@ RSpec.describe 'EPP domain:create', settings: false do specify do request - expect(response).to have_code_of(2104) + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:billing_failure))).to be_truthy end end end diff --git a/spec/requests/epp/domain/create/default_period_spec.rb b/spec/requests/epp/domain/create/default_period_spec.rb index bb83d5aba..a3a7c6f70 100644 --- a/spec/requests/epp/domain/create/default_period_spec.rb +++ b/spec/requests/epp/domain/create/default_period_spec.rb @@ -54,7 +54,7 @@ RSpec.describe 'EPP domain:create', settings: false do specify do request - expect(response).to have_code_of(1000) + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy end end end diff --git a/spec/requests/epp/domain/create/optional_nameserver_spec.rb b/spec/requests/epp/domain/create/optional_nameserver_spec.rb index da409d0b9..920deb14e 100644 --- a/spec/requests/epp/domain/create/optional_nameserver_spec.rb +++ b/spec/requests/epp/domain/create/optional_nameserver_spec.rb @@ -64,7 +64,7 @@ RSpec.describe 'EPP domain:create', settings: false do specify do request - expect(response).to have_code_of(2308) + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:data_management_policy_violation))).to be_truthy end end @@ -103,7 +103,7 @@ RSpec.describe 'EPP domain:create', settings: false do specify do request - expect(response).to have_code_of(1000) + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy end end end diff --git a/spec/requests/epp/domain/create/period_spec.rb b/spec/requests/epp/domain/create/period_spec.rb index c9c7e163a..7bd290852 100644 --- a/spec/requests/epp/domain/create/period_spec.rb +++ b/spec/requests/epp/domain/create/period_spec.rb @@ -57,7 +57,7 @@ RSpec.describe 'EPP domain:create', settings: false do specify do request - expect(response).to have_code_of(1000) + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy end end @@ -103,7 +103,7 @@ RSpec.describe 'EPP domain:create', settings: false do specify do request - expect(response).to have_code_of(1000) + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy end end end diff --git a/spec/requests/epp/domain/create/price_spec.rb b/spec/requests/epp/domain/create/price_spec.rb index b158bd7af..69f97633a 100644 --- a/spec/requests/epp/domain/create/price_spec.rb +++ b/spec/requests/epp/domain/create/price_spec.rb @@ -50,7 +50,7 @@ RSpec.describe 'EPP domain:create', settings: false do specify do request - expect(response).to have_code_of(1000) + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy end end @@ -61,7 +61,7 @@ RSpec.describe 'EPP domain:create', settings: false do specify do request - expect(response).to have_code_of(2104) + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:billing_failure))).to be_truthy end end end diff --git a/spec/requests/epp/domain/create/required_nameserver_spec.rb b/spec/requests/epp/domain/create/required_nameserver_spec.rb index cb21bc150..08b5208e1 100644 --- a/spec/requests/epp/domain/create/required_nameserver_spec.rb +++ b/spec/requests/epp/domain/create/required_nameserver_spec.rb @@ -61,7 +61,7 @@ RSpec.describe 'EPP domain:create', settings: false do specify do request - expect(response).to have_code_of(1000) + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy end end @@ -93,7 +93,7 @@ RSpec.describe 'EPP domain:create', settings: false do specify do request - expect(response).to have_code_of(2003) + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:required_parameter_missing))).to be_truthy end end end diff --git a/spec/requests/epp/domain/renew/account_balance_spec.rb b/spec/requests/epp/domain/renew/account_balance_spec.rb index 7670dcd75..465469100 100644 --- a/spec/requests/epp/domain/renew/account_balance_spec.rb +++ b/spec/requests/epp/domain/renew/account_balance_spec.rb @@ -51,7 +51,7 @@ RSpec.describe 'EPP domain:renew' do specify do request - expect(response).to have_code_of(1000) + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy end end @@ -86,7 +86,7 @@ RSpec.describe 'EPP domain:renew' do specify do request - expect(response).to have_code_of(2104) + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:billing_failure))).to be_truthy end end end diff --git a/spec/requests/epp/domain/renew/default_period_spec.rb b/spec/requests/epp/domain/renew/default_period_spec.rb index dd0806806..623199cf4 100644 --- a/spec/requests/epp/domain/renew/default_period_spec.rb +++ b/spec/requests/epp/domain/renew/default_period_spec.rb @@ -50,7 +50,7 @@ RSpec.describe 'EPP domain:renew', settings: false do specify do request - expect(response).to have_code_of(1000) + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy end end end diff --git a/spec/requests/epp/domain/renew/expire_time_spec.rb b/spec/requests/epp/domain/renew/expire_time_spec.rb index 385b2ba5e..e4321386a 100644 --- a/spec/requests/epp/domain/renew/expire_time_spec.rb +++ b/spec/requests/epp/domain/renew/expire_time_spec.rb @@ -51,7 +51,7 @@ RSpec.describe 'EPP domain:renew' do specify do request - expect(response).to have_code_of(1000) + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy end end @@ -83,7 +83,7 @@ RSpec.describe 'EPP domain:renew' do specify do request - expect(response).to have_code_of(2306) + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:parameter_value_policy_error))).to be_truthy end end end diff --git a/spec/requests/epp/domain/renew/period_spec.rb b/spec/requests/epp/domain/renew/period_spec.rb index 510e3cf06..0b2e6ed24 100644 --- a/spec/requests/epp/domain/renew/period_spec.rb +++ b/spec/requests/epp/domain/renew/period_spec.rb @@ -51,7 +51,7 @@ RSpec.describe 'EPP domain:renew', settings: false do specify do request - expect(response).to have_code_of(1000) + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy end end @@ -88,7 +88,7 @@ RSpec.describe 'EPP domain:renew', settings: false do specify do request - expect(response).to have_code_of(1000) + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy end end end diff --git a/spec/requests/epp/domain/renew/price_spec.rb b/spec/requests/epp/domain/renew/price_spec.rb index 68ee6b1a9..da2ad4022 100644 --- a/spec/requests/epp/domain/renew/price_spec.rb +++ b/spec/requests/epp/domain/renew/price_spec.rb @@ -51,7 +51,7 @@ RSpec.describe 'EPP domain:renew', settings: false do specify do request - expect(response).to have_code_of(1000) + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy end end @@ -62,7 +62,7 @@ RSpec.describe 'EPP domain:renew', settings: false do specify do request - expect(response).to have_code_of(2104) + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:billing_failure))).to be_truthy end end end diff --git a/spec/requests/epp/domain/update/registrant_change/same_as_current_spec.rb b/spec/requests/epp/domain/update/registrant_change/same_as_current_spec.rb index 46ea197da..bafe6fb0a 100644 --- a/spec/requests/epp/domain/update/registrant_change/same_as_current_spec.rb +++ b/spec/requests/epp/domain/update/registrant_change/same_as_current_spec.rb @@ -42,7 +42,7 @@ RSpec.describe 'EPP domain:update' do specify do request - expect(response).to have_code_of(1000) + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy end it 'keeps same registrant' do @@ -87,7 +87,7 @@ RSpec.describe 'EPP domain:update' do specify do request - expect(response).to have_code_of(1001) + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully_action_pending))).to be_truthy end it 'does not change registrant without confirmation' do @@ -143,7 +143,7 @@ RSpec.describe 'EPP domain:update' do specify do request - expect(response).to have_code_of(1000) + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy end it 'keeps same registrant' do @@ -188,7 +188,7 @@ RSpec.describe 'EPP domain:update' do specify do request - expect(response).to have_code_of(1000) + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy end it 'changes registrant without confirmation' do diff --git a/spec/requests/epp/domain/update/registrant_change/verified_spec.rb b/spec/requests/epp/domain/update/registrant_change/verified_spec.rb index 5e0cee39d..8bb66e61c 100644 --- a/spec/requests/epp/domain/update/registrant_change/verified_spec.rb +++ b/spec/requests/epp/domain/update/registrant_change/verified_spec.rb @@ -43,7 +43,7 @@ RSpec.describe 'EPP domain:update' do specify do request - expect(response).to have_code_of(1000) + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy end it 'changes registrant' do @@ -86,7 +86,7 @@ RSpec.describe 'EPP domain:update' do specify do request - expect(response).to have_code_of(1001) + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully_action_pending))).to be_truthy end it 'does not change registrant' do @@ -135,7 +135,7 @@ RSpec.describe 'EPP domain:update' do specify do request - expect(response).to have_code_of(1000) + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy end it 'changes registrant' do @@ -178,7 +178,7 @@ RSpec.describe 'EPP domain:update' do specify do request - expect(response).to have_code_of(1000) + expect(Epp::Response.xml(response.body).code?(Epp::Response::Result::Code.key(:completed_successfully))).to be_truthy end it 'changes registrant' do diff --git a/spec/support/matchers/epp/code.rb b/spec/support/matchers/epp/code.rb deleted file mode 100644 index 042598c50..000000000 --- a/spec/support/matchers/epp/code.rb +++ /dev/null @@ -1,39 +0,0 @@ -module Matchers - module EPP - class Code - def initialize(expected) - @expected = expected - end - - def matches?(response) - @xml = response.body - actual == expected - end - - def failure_message - "Expected EPP code of #{expected}, got #{actual} (#{code_description})" - end - - def description - "should have EPP code of #{expected}" - end - - private - - attr_reader :xml - attr_reader :expected - - def actual - xml_document.xpath('//xmlns:result').first['code'].to_i - end - - def code_description - xml_document.css('result msg').text - end - - def xml_document - @xml_document ||= Nokogiri::XML(xml) - end - end - end -end diff --git a/spec/support/matchers/epp/have_result.rb b/spec/support/matchers/epp/have_result.rb deleted file mode 100644 index 7850082dd..000000000 --- a/spec/support/matchers/epp/have_result.rb +++ /dev/null @@ -1,37 +0,0 @@ -module Matchers - module EPP - class HaveResultMatcher - def initialize(expected) - @expected = expected - end - - def matches?(target) - @target = target - - if @expected.message.present? - @target.results.any? { |result| result.code == @expected.code && result.message == @expected.message } - else - @target.results.any? { |result| result.code == @expected.code } - end - end - - def failure_message - "expected #{@target.results} to have result #{@expected.inspect}" - end - - def failure_message_when_negated - "expected #{@target.results} not to have result #{@expected.inspect}" - end - - def description - "should have EPP code of #{@expected}" - end - end - - def have_result(type, message = nil) - code = ::EPP::Response::Result.codes.key(type) - result = ::EPP::Response::Result.new(code, message) - HaveResultMatcher.new(result) - end - end -end diff --git a/spec/support/requests/epp_helpers.rb b/spec/support/requests/epp_helpers.rb index fb0175df1..1bdcd3075 100644 --- a/spec/support/requests/epp_helpers.rb +++ b/spec/support/requests/epp_helpers.rb @@ -1,15 +1,7 @@ module Requests module EPPHelpers - def have_code_of(*args) - Matchers::EPP::Code.new(*args) - end - def valid_legal_document Base64.encode64('a' * 5000) end - - def epp_response - EPP::Response.from_xml(response.body) - end end end diff --git a/test/integration/epp/contact/check/base_test.rb b/test/integration/epp/contact/check/base_test.rb index 0035f0db5..03fa7aba8 100644 --- a/test/integration/epp/contact/check/base_test.rb +++ b/test/integration/epp/contact/check/base_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class EppContactCheckBaseTest < ActionDispatch::IntegrationTest +class EppContactCheckBaseTest < EppTestCase setup do @contact = contacts(:john) end @@ -24,8 +24,7 @@ class EppContactCheckBaseTest < ActionDispatch::IntegrationTest post '/epp/command/check', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' response_xml = Nokogiri::XML(response.body) - assert_equal '1000', response_xml.at_css('result')[:code] - assert_equal 1, response_xml.css('result').size + assert_epp_response :completed_successfully assert_equal 'john-001', response_xml.at_xpath('//contact:id', contact: xml_schema).text end diff --git a/test/integration/epp/contact/create/base_test.rb b/test/integration/epp/contact/create/base_test.rb index ce8cad680..891dea93a 100644 --- a/test/integration/epp/contact/create/base_test.rb +++ b/test/integration/epp/contact/create/base_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class EppContactCreateBaseTest < ActionDispatch::IntegrationTest +class EppContactCreateBaseTest < EppTestCase def test_creates_new_contact_with_minimum_required_parameters request_xml = <<-XML @@ -28,9 +28,7 @@ class EppContactCreateBaseTest < ActionDispatch::IntegrationTest post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' end - response_xml = Nokogiri::XML(response.body) - assert_equal '1000', response_xml.at_css('result')[:code] - + assert_epp_response :completed_successfully contact = Contact.last assert_not_empty contact.code assert_equal 'New', contact.name diff --git a/test/integration/epp/contact/delete/base_test.rb b/test/integration/epp/contact/delete/base_test.rb index 05e96d248..442d16a63 100644 --- a/test/integration/epp/contact/delete/base_test.rb +++ b/test/integration/epp/contact/delete/base_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class EppContactDeleteBaseTest < ActionDispatch::IntegrationTest +class EppContactDeleteBaseTest < EppTestCase def test_deletes_contact contact = deletable_contact @@ -23,9 +23,7 @@ class EppContactDeleteBaseTest < ActionDispatch::IntegrationTest assert_difference 'Contact.count', -1 do post '/epp/command/delete', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' end - response_xml = Nokogiri::XML(response.body) - assert_equal '1000', response_xml.at_css('result')[:code] - assert_equal 1, response_xml.css('result').size + assert_epp_response :completed_successfully end def test_undeletable_cannot_be_deleted @@ -51,8 +49,7 @@ class EppContactDeleteBaseTest < ActionDispatch::IntegrationTest assert_no_difference 'Contact.count' do post '/epp/command/delete', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' end - response_xml = Nokogiri::XML(response.body) - assert_equal '2305', response_xml.at_css('result')[:code] + assert_epp_response :object_association_prohibits_operation end private diff --git a/test/integration/epp/contact/info/base_test.rb b/test/integration/epp/contact/info/base_test.rb index 414c1a1d6..c871eb636 100644 --- a/test/integration/epp/contact/info/base_test.rb +++ b/test/integration/epp/contact/info/base_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class EppContactInfoBaseTest < ActionDispatch::IntegrationTest +class EppContactInfoBaseTest < EppTestCase setup do @contact = contacts(:john) end @@ -32,8 +32,7 @@ class EppContactInfoBaseTest < ActionDispatch::IntegrationTest post '/epp/command/info', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' response_xml = Nokogiri::XML(response.body) - assert_equal '1000', response_xml.at_css('result')[:code] - assert_equal 1, response_xml.css('result').size + assert_epp_response :completed_successfully assert_equal 'JOHN-001', response_xml.at_xpath('//contact:id', contact: xml_schema).text assert_equal 'ok', response_xml.at_xpath('//contact:status', contact: xml_schema)['s'] assert_equal 'john@inbox.test', response_xml.at_xpath('//contact:email', contact: xml_schema) @@ -62,8 +61,7 @@ class EppContactInfoBaseTest < ActionDispatch::IntegrationTest post '/epp/command/info', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' - response_xml = Nokogiri::XML(response.body) - assert_equal '2303', response_xml.at_css('result')[:code] + assert_epp_response :object_does_not_exist end private diff --git a/test/integration/epp/contact/update/base_test.rb b/test/integration/epp/contact/update/base_test.rb index 2c0486a07..a8bb1d7a2 100644 --- a/test/integration/epp/contact/update/base_test.rb +++ b/test/integration/epp/contact/update/base_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class EppContactUpdateBaseTest < ActionDispatch::IntegrationTest +class EppContactUpdateBaseTest < EppTestCase include ActionMailer::TestHelper setup do @@ -40,9 +40,7 @@ class EppContactUpdateBaseTest < ActionDispatch::IntegrationTest post '/epp/command/update', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' @contact.reload - response_xml = Nokogiri::XML(response.body) - assert_equal '1000', response_xml.at_css('result')[:code] - assert_equal 1, response_xml.css('result').size + assert_epp_response :completed_successfully assert_equal 'new name', @contact.name assert_equal 'new-email@inbox.test', @contact.email assert_equal '+123.4', @contact.phone @@ -158,8 +156,7 @@ class EppContactUpdateBaseTest < ActionDispatch::IntegrationTest post '/epp/command/update', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' - response_xml = Nokogiri::XML(response.body) - assert_equal '2303', response_xml.at_css('result')[:code] + assert_epp_response :object_does_not_exist end private diff --git a/test/integration/epp/domain/check/auction_test.rb b/test/integration/epp/domain/check/auction_test.rb index 6a2722dc5..d52a65629 100644 --- a/test/integration/epp/domain/check/auction_test.rb +++ b/test/integration/epp/domain/check/auction_test.rb @@ -1,7 +1,7 @@ # encoding: UTF-8 require 'test_helper' -class EppDomainCheckAuctionTest < ApplicationIntegrationTest +class EppDomainCheckAuctionTest < EppTestCase setup do @auction = auctions(:one) @idn_auction = auctions(:idn) @@ -31,8 +31,7 @@ class EppDomainCheckAuctionTest < ApplicationIntegrationTest post '/epp/command/check', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' response_xml = Nokogiri::XML(response.body) - assert_equal '1000', response_xml.at_css('result')[:code] - assert_equal 1, response_xml.css('result').size + assert_epp_response :completed_successfully assert_equal '0', response_xml.at_xpath('//domain:name', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd')['avail'] assert_equal 'Domain is at auction', response_xml.at_xpath('//domain:reason', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text end @@ -56,8 +55,7 @@ class EppDomainCheckAuctionTest < ApplicationIntegrationTest post '/epp/command/check', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' response_xml = Nokogiri::XML(response.body) - assert_equal '1000', response_xml.at_css('result')[:code] - assert_equal 1, response_xml.css('result').size + assert_epp_response :completed_successfully assert_equal '0', response_xml.at_xpath('//domain:name', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd')['avail'] assert_equal 'Domain is at auction', response_xml.at_xpath('//domain:reason', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text end @@ -81,8 +79,7 @@ class EppDomainCheckAuctionTest < ApplicationIntegrationTest post '/epp/command/check', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' response_xml = Nokogiri::XML(response.body) - assert_equal '1000', response_xml.at_css('result')[:code] - assert_equal 1, response_xml.css('result').size + assert_epp_response :completed_successfully assert_equal '0', response_xml.at_xpath('//domain:name', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd')['avail'] assert_equal 'Domain is at auction', response_xml.at_xpath('//domain:reason', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text end @@ -106,8 +103,7 @@ class EppDomainCheckAuctionTest < ApplicationIntegrationTest post '/epp/command/check', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' response_xml = Nokogiri::XML(response.body) - assert_equal '1000', response_xml.at_css('result')[:code] - assert_equal 1, response_xml.css('result').size + assert_epp_response :completed_successfully assert_equal '0', response_xml.at_xpath('//domain:name', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd')['avail'] assert_equal 'Awaiting payment', response_xml.at_xpath('//domain:reason', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text end @@ -131,8 +127,7 @@ class EppDomainCheckAuctionTest < ApplicationIntegrationTest post '/epp/command/check', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' response_xml = Nokogiri::XML(response.body) - assert_equal '1000', response_xml.at_css('result')[:code] - assert_equal 1, response_xml.css('result').size + assert_epp_response :completed_successfully assert_equal '1', response_xml.at_xpath('//domain:name', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd')['avail'] assert_nil response_xml.at_xpath('//domain:reason', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd') end diff --git a/test/integration/epp/domain/check/base_test.rb b/test/integration/epp/domain/check/base_test.rb index 65e746947..fc8eaaca0 100644 --- a/test/integration/epp/domain/check/base_test.rb +++ b/test/integration/epp/domain/check/base_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class EppDomainCheckBaseTest < ApplicationIntegrationTest +class EppDomainCheckBaseTest < EppTestCase def test_returns_valid_response request_xml = <<-XML @@ -18,8 +18,7 @@ class EppDomainCheckBaseTest < ApplicationIntegrationTest post '/epp/command/check', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' response_xml = Nokogiri::XML(response.body) - assert_equal '1000', response_xml.at_css('result')[:code] - assert_equal 1, response_xml.css('result').size + assert_epp_response :completed_successfully assert_equal 'some.test', response_xml.at_xpath('//domain:name', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text end diff --git a/test/integration/epp/domain/create/auction_idn_test.rb b/test/integration/epp/domain/create/auction_idn_test.rb index 52bc49a98..8830d93f2 100644 --- a/test/integration/epp/domain/create/auction_idn_test.rb +++ b/test/integration/epp/domain/create/auction_idn_test.rb @@ -1,7 +1,7 @@ # encoding: UTF-8 require 'test_helper' -class EppDomainCreateAuctionIdnTest < ApplicationIntegrationTest +class EppDomainCreateAuctionIdnTest < EppTestCase def setup super @@ -46,11 +46,7 @@ class EppDomainCreateAuctionIdnTest < ApplicationIntegrationTest @idn_auction.reload refute @idn_auction.domain_registered? - - response_xml = Nokogiri::XML(response.body) - assert_equal '2003', response_xml.at_css('result')[:code] - assert_equal 'Required parameter missing; reserved>pw element is required', - response_xml.at_css('result msg').text + assert_epp_response :required_parameter_missing end def test_domain_with_unicode_idn_cannot_be_registered_without_registration_code @@ -84,11 +80,7 @@ class EppDomainCreateAuctionIdnTest < ApplicationIntegrationTest @idn_auction.reload refute @idn_auction.domain_registered? - - response_xml = Nokogiri::XML(response.body) - assert_equal '2003', response_xml.at_css('result')[:code] - assert_equal 'Required parameter missing; reserved>pw element is required', - response_xml.at_css('result msg').text + assert_epp_response :required_parameter_missing end def test_domain_with_ascii_idn_cannot_be_registered_without_winning_the_auction @@ -121,11 +113,7 @@ class EppDomainCreateAuctionIdnTest < ApplicationIntegrationTest @idn_auction.reload refute @idn_auction.domain_registered? - - response_xml = Nokogiri::XML(response.body) - assert_equal '2306', response_xml.at_css('result')[:code] - assert_equal 'Parameter value policy error: domain is at auction', - response_xml.at_css('result msg').text + assert_epp_response :parameter_value_policy_error end def test_domain_with_unicode_idn_cannot_be_registered_without_winning_the_auction @@ -195,11 +183,7 @@ class EppDomainCreateAuctionIdnTest < ApplicationIntegrationTest @idn_auction.reload refute @idn_auction.domain_registered? - - response_xml = Nokogiri::XML(response.body) - assert_equal '2306', response_xml.at_css('result')[:code] - assert_equal 'Parameter value policy error: domain is at auction', - response_xml.at_css('result msg').text + assert_epp_response :parameter_value_policy_error end def test_registers_unicode_domain_with_correct_registration_code_when_payment_is_received @@ -235,10 +219,7 @@ class EppDomainCreateAuctionIdnTest < ApplicationIntegrationTest @idn_auction.reload assert @idn_auction.domain_registered? assert Domain.where(name: @idn_auction.domain).exists? - - response_xml = Nokogiri::XML(response.body) - assert_equal '1000', response_xml.at_css('result')[:code] - assert_equal 1, Nokogiri::XML(response.body).css('result').size + assert_epp_response :completed_successfully end def test_registers_ascii_domain_with_correct_registration_code_when_payment_is_received @@ -274,9 +255,6 @@ class EppDomainCreateAuctionIdnTest < ApplicationIntegrationTest @idn_auction.reload assert @idn_auction.domain_registered? assert Domain.where(name: @idn_auction.domain).exists? - - response_xml = Nokogiri::XML(response.body) - assert_equal '1000', response_xml.at_css('result')[:code] - assert_equal 1, Nokogiri::XML(response.body).css('result').size + assert_epp_response :completed_successfully end end diff --git a/test/integration/epp/domain/create/auction_test.rb b/test/integration/epp/domain/create/auction_test.rb index cb3a4f3c3..73104c0bb 100644 --- a/test/integration/epp/domain/create/auction_test.rb +++ b/test/integration/epp/domain/create/auction_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class EppDomainCreateAuctionTest < ApplicationIntegrationTest +class EppDomainCreateAuctionTest < EppTestCase setup do @auction = auctions(:one) Domain.release_to_auction = true @@ -33,9 +33,7 @@ class EppDomainCreateAuctionTest < ApplicationIntegrationTest assert_difference 'Domain.count' do post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' end - response_xml = Nokogiri::XML(response.body) - assert_equal '1000', response_xml.at_css('result')[:code] - assert_equal 1, Nokogiri::XML(response.body).css('result').size + assert_epp_response :completed_successfully end def test_registers_domain_with_correct_registration_code_after_another_auction_when_payment_is_received @@ -72,9 +70,7 @@ class EppDomainCreateAuctionTest < ApplicationIntegrationTest assert_difference 'Domain.count' do post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' end - response_xml = Nokogiri::XML(response.body) - assert_equal '1000', response_xml.at_css('result')[:code] - assert_equal 1, Nokogiri::XML(response.body).css('result').size + assert_epp_response :completed_successfully end def test_registers_domain_with_correct_registration_code_when_payment_is_received @@ -109,10 +105,7 @@ class EppDomainCreateAuctionTest < ApplicationIntegrationTest @auction.reload assert @auction.domain_registered? - - response_xml = Nokogiri::XML(response.body) - assert_equal '1000', response_xml.at_css('result')[:code] - assert_equal 1, Nokogiri::XML(response.body).css('result').size + assert_epp_response :completed_successfully end def test_domain_cannot_be_registered_without_registration_code @@ -141,10 +134,7 @@ class EppDomainCreateAuctionTest < ApplicationIntegrationTest assert_no_difference 'Domain.count' do post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' end - response_xml = Nokogiri::XML(response.body) - assert_equal '2003', response_xml.at_css('result')[:code] - assert_equal 'Required parameter missing; reserved>pw element is required', - response_xml.at_css('result msg').text + assert_epp_response :required_parameter_missing end def test_domain_cannot_be_registered_with_wrong_registration_code @@ -176,10 +166,7 @@ class EppDomainCreateAuctionTest < ApplicationIntegrationTest assert_no_difference 'Domain.count' do post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' end - response_xml = Nokogiri::XML(response.body) - assert_equal '2202', response_xml.at_css('result')[:code] - assert_equal 'Invalid authorization information; invalid reserved>pw value', - response_xml.at_css('result msg').text + assert_epp_response :invalid_authorization_information end def test_domain_cannot_be_registered_when_payment_is_not_received @@ -210,10 +197,7 @@ class EppDomainCreateAuctionTest < ApplicationIntegrationTest assert_no_difference 'Domain.count' do post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' end - response_xml = Nokogiri::XML(response.body) - assert_equal '2003', response_xml.at_css('result')[:code] - assert_equal 'Required parameter missing; reserved>pw element required for reserved domains', - response_xml.at_css('result msg').text + assert_epp_response :required_parameter_missing end def test_domain_cannot_be_registered_when_at_auction @@ -240,9 +224,6 @@ class EppDomainCreateAuctionTest < ApplicationIntegrationTest assert_no_difference 'Domain.count' do post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' end - response_xml = Nokogiri::XML(response.body) - assert_equal '2306', response_xml.at_css('result')[:code] - assert_equal 'Parameter value policy error: domain is at auction', - response_xml.at_css('result msg').text + assert_epp_response :parameter_value_policy_error end end diff --git a/test/integration/epp/domain/create/base_test.rb b/test/integration/epp/domain/create/base_test.rb index ff3a856df..e8787645f 100644 --- a/test/integration/epp/domain/create/base_test.rb +++ b/test/integration/epp/domain/create/base_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class EppDomainCreateBaseTest < ApplicationIntegrationTest +class EppDomainCreateBaseTest < EppTestCase def test_domain_can_be_registered_with_required_attributes_only request_xml = <<-XML @@ -28,9 +28,6 @@ class EppDomainCreateBaseTest < ApplicationIntegrationTest domain = Domain.last assert_equal 'new.test', domain.name assert_equal contacts(:john).becomes(Registrant), domain.registrant - - response_xml = Nokogiri::XML(response.body) - assert_equal '1000', response_xml.at_css('result')[:code] - assert_equal 1, Nokogiri::XML(response.body).css('result').size + assert_epp_response :completed_successfully end end diff --git a/test/integration/epp/domain/create/nameservers_test.rb b/test/integration/epp/domain/create/nameservers_test.rb index 954d1f300..205bc7a86 100644 --- a/test/integration/epp/domain/create/nameservers_test.rb +++ b/test/integration/epp/domain/create/nameservers_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class EppDomainCreateNameserversTest < ApplicationIntegrationTest +class EppDomainCreateNameserversTest < EppTestCase # Glue record requirement def test_nameserver_ip_address_is_required_if_hostname_is_under_the_same_domain request_xml = <<-XML @@ -30,6 +30,6 @@ class EppDomainCreateNameserversTest < ApplicationIntegrationTest assert_no_difference 'Domain.count' do post '/epp/command/create', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_bestnames' } end - assert_equal '2003', Nokogiri::XML(response.body).at_css('result')[:code] + assert_epp_response :required_parameter_missing end end diff --git a/test/integration/epp/domain/create/reserved_test.rb b/test/integration/epp/domain/create/reserved_test.rb index 1a57cd220..40e5be59d 100644 --- a/test/integration/epp/domain/create/reserved_test.rb +++ b/test/integration/epp/domain/create/reserved_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class EppDomainCreateReservedTest < ApplicationIntegrationTest +class EppDomainCreateReservedTest < EppTestCase setup do @reserved_domain = reserved_domains(:one) end @@ -34,10 +34,7 @@ class EppDomainCreateReservedTest < ApplicationIntegrationTest assert_difference 'Domain.count' do post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' end - - response_xml = Nokogiri::XML(response.body) - assert_equal '1000', response_xml.at_css('result')[:code] - assert_equal 1, Nokogiri::XML(response.body).css('result').size + assert_epp_response :completed_successfully end def test_registering_reserved_domain_regenerates_registration_code @@ -101,11 +98,7 @@ class EppDomainCreateReservedTest < ApplicationIntegrationTest assert_no_difference 'Domain.count' do post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' end - - response_xml = Nokogiri::XML(response.body) - assert_equal '2202', response_xml.at_css('result')[:code] - assert_equal 'Invalid authorization information; invalid reserved>pw value', - response_xml.at_css('result msg').text + assert_epp_response :invalid_authorization_information end def test_domain_cannot_be_registered_without_registration_code @@ -133,10 +126,6 @@ class EppDomainCreateReservedTest < ApplicationIntegrationTest assert_no_difference 'Domain.count' do post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' end - - response_xml = Nokogiri::XML(response.body) - assert_equal '2003', response_xml.at_css('result')[:code] - assert_equal 'Required parameter missing; reserved>pw element required for reserved domains', - response_xml.at_css('result msg').text + assert_epp_response :required_parameter_missing end end diff --git a/test/integration/epp/domain/create/transfer_code_test.rb b/test/integration/epp/domain/create/transfer_code_test.rb index 131baf67a..05c7d0bec 100644 --- a/test/integration/epp/domain/create/transfer_code_test.rb +++ b/test/integration/epp/domain/create/transfer_code_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class EppDomainCreateTransferCodeTest < ApplicationIntegrationTest +class EppDomainCreateTransferCodeTest < EppTestCase setup do travel_to Time.zone.parse('2010-07-05') end @@ -28,8 +28,7 @@ class EppDomainCreateTransferCodeTest < ApplicationIntegrationTest post '/epp/command/create', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_bestnames' } refute_empty Domain.find_by(name: 'brandnew.test').transfer_code - assert_equal '1000', Nokogiri::XML(response.body).at_css('result')[:code] - assert_equal 1, Nokogiri::XML(response.body).css('result').size + assert_epp_response :completed_successfully end def test_honors_custom @@ -58,7 +57,6 @@ class EppDomainCreateTransferCodeTest < ApplicationIntegrationTest post '/epp/command/create', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_bestnames' } assert_equal '1058ad73', Domain.find_by(name: 'brandnew.test').transfer_code - assert_equal '1000', Nokogiri::XML(response.body).at_css('result')[:code] - assert_equal 1, Nokogiri::XML(response.body).css('result').size + assert_epp_response :completed_successfully end end diff --git a/test/integration/epp/domain/delete/base_test.rb b/test/integration/epp/domain/delete/base_test.rb index 0a2a4308a..c1f52166d 100644 --- a/test/integration/epp/domain/delete/base_test.rb +++ b/test/integration/epp/domain/delete/base_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class EppDomainDeleteBaseTest < ActionDispatch::IntegrationTest +class EppDomainDeleteBaseTest < EppTestCase include ActionMailer::TestHelper setup do @@ -36,8 +36,7 @@ class EppDomainDeleteBaseTest < ActionDispatch::IntegrationTest post '/epp/command/delete', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' assert_includes Domain.find_by(name: 'invalid.test').statuses, DomainStatus::PENDING_DELETE_CONFIRMATION - assert_equal '1001', Nokogiri::XML(response.body).at_css('result')[:code] - assert_equal 1, Nokogiri::XML(response.body).css('result').size + assert_epp_response :completed_successfully_action_pending end def test_discarded_domain_cannot_be_deleted @@ -65,7 +64,7 @@ class EppDomainDeleteBaseTest < ActionDispatch::IntegrationTest assert_no_difference 'Domain.count' do post '/epp/command/delete', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' end - assert_equal '2105', Nokogiri::XML(response.body).at_css('result')[:code] + assert_epp_response :object_is_not_eligible_for_renewal end def test_requests_registrant_confirmation_when_required @@ -96,8 +95,7 @@ class EppDomainDeleteBaseTest < ActionDispatch::IntegrationTest 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] + assert_epp_response :completed_successfully_action_pending end def test_skips_registrant_confirmation_when_not_required @@ -128,8 +126,7 @@ class EppDomainDeleteBaseTest < ActionDispatch::IntegrationTest 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] + assert_epp_response :completed_successfully end def test_skips_registrant_confirmation_when_required_but_already_verified_by_registrar @@ -160,8 +157,7 @@ class EppDomainDeleteBaseTest < ActionDispatch::IntegrationTest 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] + assert_epp_response :completed_successfully end def test_legal_document_is_required @@ -182,10 +178,7 @@ class EppDomainDeleteBaseTest < ActionDispatch::IntegrationTest 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 + assert_epp_response :required_parameter_missing end def test_domain_cannot_be_deleted_when_explicitly_prohibited_by_registrar @@ -212,9 +205,7 @@ class EppDomainDeleteBaseTest < ActionDispatch::IntegrationTest 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 + assert_epp_response :object_status_prohibits_operation end def test_domain_not_found @@ -240,8 +231,6 @@ class EppDomainDeleteBaseTest < ActionDispatch::IntegrationTest 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 + assert_epp_response :object_does_not_exist end end \ No newline at end of file diff --git a/test/integration/epp/domain/domain_renew_test.rb b/test/integration/epp/domain/domain_renew_test.rb index ac48269ad..e1dfbdae1 100644 --- a/test/integration/epp/domain/domain_renew_test.rb +++ b/test/integration/epp/domain/domain_renew_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class EppDomainRenewTest < ApplicationIntegrationTest +class EppDomainRenewTest < EppTestCase self.use_transactional_fixtures = false setup do @@ -26,7 +26,6 @@ class EppDomainRenewTest < ApplicationIntegrationTest assert_no_changes -> { domains(:invalid).valid_to } do post '/epp/command/renew', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' end - assert_equal '2304', Nokogiri::XML(response.body).at_css('result')[:code], - Nokogiri::XML(response.body).css('result').text + assert_epp_response :object_status_prohibits_operation end end diff --git a/test/integration/epp/domain/domain_update_test.rb b/test/integration/epp/domain/domain_update_test.rb index e97fe453a..fcd0da0c6 100644 --- a/test/integration/epp/domain/domain_update_test.rb +++ b/test/integration/epp/domain/domain_update_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class EppDomainUpdateTest < ApplicationIntegrationTest +class EppDomainUpdateTest < EppTestCase def setup @domain = domains(:shop) end @@ -27,8 +27,7 @@ class EppDomainUpdateTest < ApplicationIntegrationTest post '/epp/command/update', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' @domain.reload assert_equal 'f0ff7d17b0', @domain.transfer_code - assert_equal '1000', Nokogiri::XML(response.body).at_css('result')[:code] - assert_equal 1, Nokogiri::XML(response.body).css('result').size + assert_epp_response :completed_successfully end def test_discarded_domain_cannot_be_updated @@ -48,6 +47,6 @@ class EppDomainUpdateTest < ApplicationIntegrationTest XML post '/epp/command/update', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' - assert_equal '2105', Nokogiri::XML(response.body).at_css('result')[:code] + assert_epp_response :object_is_not_eligible_for_renewal end end diff --git a/test/integration/epp/domain/info/base_test.rb b/test/integration/epp/domain/info/base_test.rb index 2ba273951..0aebc4de5 100644 --- a/test/integration/epp/domain/info/base_test.rb +++ b/test/integration/epp/domain/info/base_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class EppDomainInfoBaseTest < ApplicationIntegrationTest +class EppDomainInfoBaseTest < EppTestCase def test_returns_valid_response assert_equal 'john-001', contacts(:john).code domains(:shop).update_columns(statuses: [DomainStatus::OK], @@ -24,8 +24,7 @@ class EppDomainInfoBaseTest < ApplicationIntegrationTest post '/epp/command/info', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' response_xml = Nokogiri::XML(response.body) - assert_equal '1000', response_xml.at_css('result')[:code] - assert_equal 1, response_xml.css('result').size + assert_epp_response :completed_successfully assert_equal 'shop.test', response_xml.at_xpath('//domain:name', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text assert_equal 'ok', response_xml.at_xpath('//domain:status', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd')['s'] assert_equal 'john-001', response_xml.at_xpath('//domain:registrant', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text @@ -125,8 +124,6 @@ class EppDomainInfoBaseTest < ApplicationIntegrationTest post '/epp/command/info', { 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 + assert_epp_response :object_does_not_exist end end \ No newline at end of file diff --git a/test/integration/epp/domain/transfer/base_test.rb b/test/integration/epp/domain/transfer/base_test.rb index e220f8ebd..5c15ae881 100644 --- a/test/integration/epp/domain/transfer/base_test.rb +++ b/test/integration/epp/domain/transfer/base_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class EppDomainTransferBaseTest < ApplicationIntegrationTest +class EppDomainTransferBaseTest < EppTestCase def test_non_existent_domain request_xml = <<-XML @@ -19,6 +19,7 @@ class EppDomainTransferBaseTest < ApplicationIntegrationTest XML post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_goodnames' } - assert_equal '2303', Nokogiri::XML(response.body).at_css('result')[:code] + + assert_epp_response :object_does_not_exist end end diff --git a/test/integration/epp/domain/transfer/query_test.rb b/test/integration/epp/domain/transfer/query_test.rb index 8a9c589c8..e3bf7bdae 100644 --- a/test/integration/epp/domain/transfer/query_test.rb +++ b/test/integration/epp/domain/transfer/query_test.rb @@ -1,11 +1,10 @@ require 'test_helper' -class EppDomainTransferQueryTest < ApplicationIntegrationTest +class EppDomainTransferQueryTest < EppTestCase def test_returns_domain_transfer_details 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_epp_response :completed_successfully 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 @@ -30,13 +29,15 @@ class EppDomainTransferQueryTest < ApplicationIntegrationTest XML post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_bestnames' } - assert_equal '2201', Nokogiri::XML(response.body).at_css('result')[:code] + + # https://github.com/internetee/registry/issues/686 + assert_epp_response :authorization_error end def test_no_domain_transfer domains(:shop).transfers.delete_all post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_bestnames' } - assert_equal '2303', Nokogiri::XML(response.body).at_css('result')[:code] + assert_epp_response :object_does_not_exist end private diff --git a/test/integration/epp/domain/transfer/request_test.rb b/test/integration/epp/domain/transfer/request_test.rb index f9cfda911..babb7642a 100644 --- a/test/integration/epp/domain/transfer/request_test.rb +++ b/test/integration/epp/domain/transfer/request_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class EppDomainTransferRequestTest < ApplicationIntegrationTest +class EppDomainTransferRequestTest < EppTestCase def setup @domain = domains(:shop) @new_registrar = registrars(:goodnames) @@ -14,8 +14,7 @@ class EppDomainTransferRequestTest < ApplicationIntegrationTest 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 + assert_epp_response :completed_successfully end def test_creates_new_domain_transfer @@ -77,7 +76,7 @@ class EppDomainTransferRequestTest < ApplicationIntegrationTest domains(:shop).reload assert_equal registrars(:bestnames), domains(:shop).registrar - assert_equal '2304', Nokogiri::XML(response.body).at_css('result')[:code] + assert_epp_response :object_status_prohibits_operation end def test_discarded_domain_cannot_be_transferred @@ -87,15 +86,14 @@ class EppDomainTransferRequestTest < ApplicationIntegrationTest @domain.reload assert_equal registrars(:bestnames), @domain.registrar - assert_equal '2105', Nokogiri::XML(response.body).at_css('result')[:code] + assert_epp_response :object_is_not_eligible_for_renewal end def test_same_registrar assert_no_difference -> { @domain.transfers.size } do post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_bestnames' } end - - assert_equal '2002', Nokogiri::XML(response.body).at_css('result')[:code] + assert_epp_response :use_error end def test_wrong_transfer_code @@ -118,7 +116,9 @@ class EppDomainTransferRequestTest < ApplicationIntegrationTest post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_goodnames' } @domain.reload refute_equal @new_registrar, @domain.registrar - assert_equal '2201', Nokogiri::XML(response.body).at_css('result')[:code] + + # https://github.com/internetee/registry/issues/686 + assert_epp_response :authorization_error end private diff --git a/test/integration/epp/login/credentials_test.rb b/test/integration/epp/login/credentials_test.rb index 3eac10da5..a9275e8e8 100644 --- a/test/integration/epp/login/credentials_test.rb +++ b/test/integration/epp/login/credentials_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class EppLoginCredentialsTest < ApplicationIntegrationTest +class EppLoginCredentialsTest < EppTestCase def test_correct_credentials request_xml = <<-XML @@ -27,8 +27,7 @@ class EppLoginCredentialsTest < ApplicationIntegrationTest post '/epp/session/login', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=new_session_id' } assert EppSession.find_by(session_id: 'new_session_id') assert_equal users(:api_bestnames), EppSession.find_by(session_id: 'new_session_id').user - assert Nokogiri::XML(response.body).at_css('result[code="1000"]') - assert_equal 1, Nokogiri::XML(response.body).css('result').size + assert_epp_response :completed_successfully end def test_already_logged_in @@ -58,7 +57,8 @@ class EppLoginCredentialsTest < ApplicationIntegrationTest XML - post '/epp/session/login', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=any_random_string' } - assert Nokogiri::XML(response.body).at_css('result[code="2501"]') + post '/epp/session/login', { frame: request_xml }, 'HTTP_COOKIE' => 'session=any_random_string' + + assert_epp_response :authentication_error_server_closing_connection end end diff --git a/test/integration/epp/login/password_change_test.rb b/test/integration/epp/login/password_change_test.rb index 69c3140b6..69cda0d6a 100644 --- a/test/integration/epp/login/password_change_test.rb +++ b/test/integration/epp/login/password_change_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class EppLoginPasswordChangeTest < ActionDispatch::IntegrationTest +class EppLoginPasswordChangeTest < EppTestCase def test_password_change request_xml = <<-XML @@ -27,7 +27,6 @@ class EppLoginPasswordChangeTest < ActionDispatch::IntegrationTest post '/epp/session/login', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=new_session_id' } assert_equal 'new-password', users(:api_bestnames).plain_text_password - assert_equal '1000', Nokogiri::XML(response.body).at_css('result')[:code] - assert_equal 1, Nokogiri::XML(response.body).css('result').size + assert_epp_response :completed_successfully end end \ No newline at end of file diff --git a/test/integration/epp/login/session_limit_test.rb b/test/integration/epp/login/session_limit_test.rb index de7f85a06..a3db4f145 100644 --- a/test/integration/epp/login/session_limit_test.rb +++ b/test/integration/epp/login/session_limit_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class EppLoginSessionLimitTest < ApplicationIntegrationTest +class EppLoginSessionLimitTest < EppTestCase setup do travel_to Time.zone.parse('2010-07-05') EppSession.delete_all @@ -16,9 +16,7 @@ class EppLoginSessionLimitTest < ApplicationIntegrationTest assert_difference 'EppSession.count' do post '/epp/session/login', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=new_session_id' } end - - assert Nokogiri::XML(response.body).at_css('result[code="1000"]') - assert_equal 1, Nokogiri::XML(response.body).css('result').size + assert_epp_response :completed_successfully end def test_reached @@ -31,8 +29,7 @@ class EppLoginSessionLimitTest < ApplicationIntegrationTest assert_no_difference 'EppSession.count' do post '/epp/session/login', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=new_session_id' } end - - assert Nokogiri::XML(response.body).at_css('result[code="2501"]') + assert_epp_response :authentication_error_server_closing_connection end private diff --git a/test/integration/epp/logout_test.rb b/test/integration/epp/logout_test.rb index dc8276e7e..bb6340c13 100644 --- a/test/integration/epp/logout_test.rb +++ b/test/integration/epp/logout_test.rb @@ -1,10 +1,9 @@ require 'test_helper' -class EppLogoutTest < ApplicationIntegrationTest +class EppLogoutTest < EppTestCase def test_success_response post '/epp/session/logout', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_bestnames' } - assert Nokogiri::XML(response.body).at_css('result[code="1500"]') - assert_equal 1, Nokogiri::XML(response.body).css('result').size + assert_epp_response :completed_successfully_ending_session end def test_ends_current_session @@ -19,7 +18,7 @@ class EppLogoutTest < ApplicationIntegrationTest def test_anonymous_user post '/epp/session/logout', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=non-existent' } - assert Nokogiri::XML(response.body).at_css('result[code="2201"]') + assert_epp_response :authorization_error end private diff --git a/test/integration/epp/poll_test.rb b/test/integration/epp/poll_test.rb index bc3a559cd..ae31398f1 100644 --- a/test/integration/epp/poll_test.rb +++ b/test/integration/epp/poll_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class EppPollTest < ApplicationIntegrationTest +class EppPollTest < EppTestCase setup do @notification = notifications(:complete) end @@ -18,8 +18,7 @@ class EppPollTest < ApplicationIntegrationTest post '/epp/command/poll', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' xml_doc = Nokogiri::XML(response.body) - assert_equal 1301.to_s, xml_doc.at_css('result')[:code] - assert_equal 1, xml_doc.css('result').size + assert_epp_response :completed_successfully_ack_to_dequeue assert_equal 2.to_s, xml_doc.at_css('msgQ')[:count] assert_equal @notification.id.to_s, xml_doc.at_css('msgQ')[:id] assert_equal Time.zone.parse('2010-07-05').utc.xmlschema, xml_doc.at_css('msgQ qDate').text @@ -63,9 +62,7 @@ class EppPollTest < ApplicationIntegrationTest XML post '/epp/command/poll', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' - xml_doc = Nokogiri::XML(response.body) - assert_equal 1300.to_s, xml_doc.at_css('result')[:code] - assert_equal 1, xml_doc.css('result').size + assert_epp_response :completed_successfully_no_messages end def test_mark_as_read @@ -85,8 +82,7 @@ class EppPollTest < ApplicationIntegrationTest xml_doc = Nokogiri::XML(response.body) assert notification.read? - assert_equal 1000.to_s, xml_doc.at_css('result')[:code] - assert_equal 1, xml_doc.css('result').size + assert_epp_response :completed_successfully assert_equal 1.to_s, xml_doc.at_css('msgQ')[:count] assert_equal notification.id.to_s, xml_doc.at_css('msgQ')[:id] end @@ -105,9 +101,8 @@ class EppPollTest < ApplicationIntegrationTest post '/epp/command/poll', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' notification.reload - xml_doc = Nokogiri::XML(response.body) assert notification.unread? - assert_equal 2303.to_s, xml_doc.at_css('result')[:code] + assert_epp_response :object_does_not_exist end def test_notification_not_found @@ -121,7 +116,6 @@ class EppPollTest < ApplicationIntegrationTest XML post '/epp/command/poll', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames' - xml_doc = Nokogiri::XML(response.body) - assert_equal 2303.to_s, xml_doc.at_css('result')[:code] + assert_epp_response :object_does_not_exist end -end \ No newline at end of file +end diff --git a/test/models/epp/response/result/code_test.rb b/test/models/epp/response/result/code_test.rb new file mode 100644 index 000000000..0a5f507d3 --- /dev/null +++ b/test/models/epp/response/result/code_test.rb @@ -0,0 +1,84 @@ +require 'test_helper' + +class EppResponseResultCodeTest < ActiveSupport::TestCase + def test_creates_code_by_key + key = :completed_successfully + assert_includes Epp::Response::Result::Code.codes.keys, key + + assert_kind_of Epp::Response::Result::Code, Epp::Response::Result::Code.key(key) + end + + def test_creates_new_code_by_string_value + code_value = Epp::Response::Result::Code.codes.values.first + code = Epp::Response::Result::Code.new(code_value.to_s) + assert_equal code_value, code.value + end + + def test_invalid_code_value + invalid_code_value = 0000 + refute_includes Epp::Response::Result::Code.codes.values, invalid_code_value + + e = assert_raises ArgumentError do + Epp::Response::Result::Code.new(invalid_code_value) + end + assert_equal "Invalid value: #{invalid_code_value}", e.message + end + + def test_returns_code_values + codes = { + completed_successfully: 1000, + completed_successfully_action_pending: 1001, + completed_successfully_no_messages: 1300, + completed_successfully_ack_to_dequeue: 1301, + completed_successfully_ending_session: 1500, + unknown_command: 2000, + syntax_error: 2001, + use_error: 2002, + required_parameter_missing: 2003, + parameter_value_range_error: 2004, + parameter_value_syntax_error: 2005, + billing_failure: 2104, + object_is_not_eligible_for_renewal: 2105, + authorization_error: 2201, + invalid_authorization_information: 2202, + object_does_not_exist: 2303, + object_status_prohibits_operation: 2304, + object_association_prohibits_operation: 2305, + parameter_value_policy_error: 2306, + data_management_policy_violation: 2308, + authentication_error_server_closing_connection: 2501, + } + assert_equal codes, Epp::Response::Result::Code.codes + end + + def test_returns_default_descriptions + descriptions = { + 1000 => 'Command completed successfully', + 1001 => 'Command completed successfully; action pending', + 1300 => 'Command completed successfully; no messages', + 1301 => 'Command completed successfully; ack to dequeue', + 1500 => 'Command completed successfully; ending session', + 2000 => 'Unknown command', + 2001 => 'Command syntax error', + 2002 => 'Command use error', + 2003 => 'Required parameter missing', + 2004 => 'Parameter value range error', + 2005 => 'Parameter value syntax error', + 2104 => 'Billing failure', + 2105 => 'Object is not eligible for renewal', + 2201 => 'Authorization error', + 2202 => 'Invalid authorization information', + 2303 => 'Object does not exist', + 2304 => 'Object status prohibits operation', + 2305 => 'Object association prohibits operation', + 2306 => 'Parameter value policy error', + 2308 => 'Data management policy violation', + 2501 => 'Authentication error; server closing connection', + } + assert_equal descriptions, Epp::Response::Result::Code.default_descriptions + end + + def test_equality + assert_equal Epp::Response::Result::Code.new(1000), Epp::Response::Result::Code.new(1000) + end +end diff --git a/test/models/epp/response/result_test.rb b/test/models/epp/response/result_test.rb new file mode 100644 index 000000000..18947aa9a --- /dev/null +++ b/test/models/epp/response/result_test.rb @@ -0,0 +1,5 @@ +require 'test_helper' + +class EppResponseResultTest < ActiveSupport::TestCase + +end diff --git a/test/models/epp/response_test.rb b/test/models/epp/response_test.rb new file mode 100644 index 000000000..9f82bd205 --- /dev/null +++ b/test/models/epp/response_test.rb @@ -0,0 +1,29 @@ +require 'test_helper' + +class EppResponseTest < ActiveSupport::TestCase + def test_creates_new_response_from_xml_doc + xml = <<-XML + + + + + any + + + + XML + + assert_kind_of Epp::Response, Epp::Response.xml(xml) + end + + def test_code_predicate + present_code = Epp::Response::Result::Code.key(:completed_successfully) + absent_code = Epp::Response::Result::Code.key(:required_parameter_missing) + + result = Epp::Response::Result.new(code: present_code) + response = Epp::Response.new(results: [result]) + + assert response.code?(present_code) + assert_not response.code?(absent_code) + end +end diff --git a/test/support/assertions/epp_assertions.rb b/test/support/assertions/epp_assertions.rb new file mode 100644 index 000000000..3f955a7e0 --- /dev/null +++ b/test/support/assertions/epp_assertions.rb @@ -0,0 +1,14 @@ +module Assertions + module EppAssertions + def assert_epp_response(code_key, message = nil) + assert epp_response.code?(Epp::Response::Result::Code.key(code_key)), message + end + + private + + def epp_response + @epp_response = Epp::Response.xml(response.body) unless @epp_response + @epp_response + end + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index f36bd61f3..c250837c1 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -11,6 +11,7 @@ require 'capybara/rails' require 'capybara/minitest' require 'webmock/minitest' require 'support/rails5_assertions' # Remove once upgraded to Rails 5 +require 'support/assertions/epp_assertions' Setting.address_processing = false Setting.registry_country_code = 'US' @@ -57,3 +58,7 @@ class ApplicationIntegrationTest < ActionDispatch::IntegrationTest Capybara.use_default_driver end end + +class EppTestCase < ActionDispatch::IntegrationTest + include Assertions::EppAssertions +end