From 8ef0692ca938b138e891d7b9655862feb77feaf1 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Fri, 25 Jun 2021 14:57:03 +0300 Subject: [PATCH] added tests --- lib/xsd/schema.rb | 50 +++++++------------ test/integration/epp/domain/info/base_test.rb | 40 +++++++++++++++ 2 files changed, 59 insertions(+), 31 deletions(-) diff --git a/lib/xsd/schema.rb b/lib/xsd/schema.rb index d4b6b23f6..1d73e50cc 100644 --- a/lib/xsd/schema.rb +++ b/lib/xsd/schema.rb @@ -3,6 +3,9 @@ module Xsd SCHEMA_PATH = 'lib/schemas/'.freeze BASE_URL = 'https://epp.tld.ee/schema/'.freeze + REGEX_PREFIX_WITH_DASH = /(?\w+-\w+)-(?\w.\w).xsd/ + REGEX_PREFIX_WITHOUT_DASH = /(?\w+)-(?\w.\w).xsd/ + PREFIXES = %w[ domain-ee domain-eis @@ -24,7 +27,7 @@ module Xsd def initialize(params) schema_path = params.fetch(:schema_path, SCHEMA_PATH) @for_prefix = params.fetch(:for_prefix) - @for_version = params.fetch(:for_version, '1.1') + @for_version = params.fetch(:for_version, '1.1') @xsd_schemas = Dir.entries(schema_path).select { |f| File.file? File.join(schema_path, f) } end @@ -33,47 +36,32 @@ module Xsd end def call - filename = latest(for_prefix) + filename = get_schema(for_prefix) BASE_URL + filename end private - # xml = response.gsub!(/(?<=>)(.*?)(?=<)/, &:strip) - # xml.to_s.match(/xmlns:domain=\"https:\/\/epp.tld.ee\/schema\/(?\w+-\w+)-(?\w.\w).xsd/) - # The prefix and version of the response are returned are these variants - res[:prefix] res[:version] - - def latest(prefix) + def get_schema(prefix) + actual_schema = '' schemas = schemas_by_name[prefix] - actual_schema = '' + schemas.each do |schema| + result = return_some(schema) + actual_schema = schema if result[:version] == @for_version - schemas.each do |schema| - result = return_some(schema) + actual_schema = 'epp-ee-1.0.xsd' if result[:prefix] == 'epp-ee' + actual_schema = 'eis-1.0.xsd' if result[:prefix] == 'eis' + end - if result[:version] == @for_version - actual_schema = schema - end - - if result[:prefix] == 'epp-ee' - actual_schema = 'epp-ee-1.0.xsd' - end - - if result[:prefix] == 'eis' - actual_schema = 'eis-1.0.xsd' - end - end - - actual_schema + actual_schema end - def return_some(data) - res = data.to_s.match(/(?\w+-\w+)-(?\w.\w).xsd/) - - res = data.to_s.match(/(?\w+)-(?\w.\w).xsd/) if res.nil? - - res - end + def return_some(data) + res = data.to_s.match(REGEX_PREFIX_WITH_DASH) + res = data.to_s.match(REGEX_PREFIX_WITHOUT_DASH) if res.nil? + res + end def basename(filename) File.basename(filename, '.xsd') diff --git a/test/integration/epp/domain/info/base_test.rb b/test/integration/epp/domain/info/base_test.rb index 355d1ed4b..ffacc20c8 100644 --- a/test/integration/epp/domain/info/base_test.rb +++ b/test/integration/epp/domain/info/base_test.rb @@ -48,6 +48,46 @@ class EppDomainInfoBaseTest < EppTestCase 'domain' => Xsd::Schema.filename(for_prefix: 'domain-ee').to_s).text end + def test_return_wrong_schema_with_invalid_version + request_xml = <<-XML + + + + + + shop.test + + + + + XML + + post epp_info_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + + assert_epp_response :wrong_schema + end + + def test_return_valid_response_if_specify_the_version + request_xml = <<-XML + + + + + + shop.test + + + + + XML + + post epp_info_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + + assert_epp_response :completed_successfully + end + def test_returns_valid_response_if_schema_version_is_previous dispute = disputes(:expired) dispute.update!(starts_at: Time.zone.now, expires_at: Time.zone.now + 5.days, closed: nil)