Add a test to domain renew

This commit is contained in:
Martin Lensment 2014-08-11 11:48:03 +03:00
parent 8baa2e12c9
commit a3abfa73e5
5 changed files with 29 additions and 6 deletions

View file

@ -32,6 +32,7 @@ module Epp::DomainsHelper
end end
def renew_domain def renew_domain
# TODO support period unit
@domain = find_domain @domain = find_domain
handle_errors(@domain) and return unless @domain handle_errors(@domain) and return unless @domain
@ -49,11 +50,11 @@ module Epp::DomainsHelper
end end
def find_domain def find_domain
@domain = Domain.find_by(name: @ph[:name]) domain = Domain.find_by(name: @ph[:name])
unless @domain unless domain
epp_errors << {code: '2303', msg: I18n.t('errors.messages.epp_domain_not_found'), value: {obj: 'name', val: @ph[:name]}} epp_errors << {code: '2303', msg: I18n.t('errors.messages.epp_domain_not_found'), value: {obj: 'name', val: @ph[:name]}}
end end
@domain domain
end end
def domain_create_params(ph) def domain_create_params(ph)

View file

@ -7,7 +7,7 @@ class Domain < ActiveRecord::Base
EPP_CODE_MAP = { EPP_CODE_MAP = {
'2302' => ['Domain name already exists', 'Domain name is reserved or restricted'], # Object exists '2302' => ['Domain name already exists', 'Domain name is reserved or restricted'], # Object exists
'2306' => ['Registrant is missing', 'Admin contact is missing', 'Given and current expire dates do not match'], # Parameter policy error '2306' => ['Registrant is missing', 'Admin contact is missing', 'Given and current expire dates do not match'], # Parameter policy error
'2004' => ['Nameservers count must be between 1-13'], # Parameter value range error '2004' => ['Nameservers count must be between 1-13', 'Period must add up to 1, 2 or 3 years'], # Parameter value range error
'2303' => ['Contact was not found'] # Object does not exist '2303' => ['Contact was not found'] # Object does not exist
} }
@ -136,7 +136,6 @@ class Domain < ActiveRecord::Base
def validate_period def validate_period
return unless period.present? return unless period.present?
if period_unit == 'd' if period_unit == 'd'
valid_values = ['365', '366', '710', '712', '1065', '1068'] valid_values = ['365', '366', '710', '712', '1065', '1068']
elsif period_unit == 'm' elsif period_unit == 'm'
@ -145,7 +144,7 @@ class Domain < ActiveRecord::Base
valid_values = ['1', '2', '3'] valid_values = ['1', '2', '3']
end end
errors.add(:period, :step_error) unless valid_values.include?(period.to_s) errors.add(:period, :out_of_range) unless valid_values.include?(period.to_s)
end end
def validate_exp_dates(cur_exp_date) def validate_exp_dates(cur_exp_date)

View file

@ -52,6 +52,8 @@ en:
out_of_range: 'Nameservers count must be between %{min}-%{max}' out_of_range: 'Nameservers count must be between %{min}-%{max}'
hostname_invalid: 'Hostname is invalid' hostname_invalid: 'Hostname is invalid'
ip_invalid: 'IP is invalid' ip_invalid: 'IP is invalid'
period:
out_of_range: 'Period must add up to 1, 2 or 3 years'
nameserver: nameserver:
attributes: attributes:
hostname: hostname:

View file

@ -150,6 +150,13 @@ describe 'EPP Domain', epp: true do
expect(response[:results][0][:result_code]).to eq('2306') expect(response[:results][0][:result_code]).to eq('2306')
expect(response[:results][0][:msg]).to eq('Given and current expire dates do not match') expect(response[:results][0][:msg]).to eq('Given and current expire dates do not match')
end end
it 'returns an error when given and current exp dates do not match' do
response = epp_request('domains/renew_w_invalid_period.xml')
expect(response[:results][0][:result_code]).to eq('2004')
expect(response[:results][0][:msg]).to eq('Period must add up to 1, 2 or 3 years')
expect(response[:results][0][:value]).to eq('4')
end
end end
it 'checks a domain' do it 'checks a domain' do

View file

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<renew>
<domain:renew
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example.ee</domain:name>
<domain:curExpDate>2014-08-07</domain:curExpDate>
<domain:period unit="y">4</domain:period>
</domain:renew>
</renew>
<clTRID>ABC-12345</clTRID>
</command>
</epp>