Refactor renew tests

This commit is contained in:
Martin Lensment 2014-08-13 15:53:55 +03:00
parent e317667ffe
commit 838782fd62
4 changed files with 26 additions and 32 deletions

View file

@ -179,13 +179,17 @@ describe 'EPP Domain', epp: true do
end end
it 'returns an error when given and current exp dates do not match' do it 'returns an error when given and current exp dates do not match' do
response = epp_request('domains/renew_w_not_matching_exp_dates.xml') xml = domain_renew_xml(curExpDate: '2016-08-07')
response = epp_request(xml, :xml)
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 it 'returns an error when period is invalid' do
response = epp_request('domains/renew_w_invalid_period.xml') xml = domain_renew_xml(period_value: 4)
response = epp_request(xml, :xml)
expect(response[:results][0][:result_code]).to eq('2004') 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][:msg]).to eq('Period must add up to 1, 2 or 3 years')
expect(response[:results][0][:value]).to eq('4') expect(response[:results][0][:value]).to eq('4')

View file

@ -1,14 +0,0 @@
<?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>

View file

@ -1,14 +0,0 @@
<?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>2016-08-07</domain:curExpDate>
<domain:period unit="y">1</domain:period>
</domain:renew>
</renew>
<clTRID>ABC-12345</clTRID>
</command>
</epp>

View file

@ -63,7 +63,7 @@ module Epp
xml.create do xml.create do
xml.tag!('domain:create', 'xmlns:domain' => 'urn:ietf:params:xml:ns:domain-1.0') do xml.tag!('domain:create', 'xmlns:domain' => 'urn:ietf:params:xml:ns:domain-1.0') do
xml.tag!('domain:name', (xml_params[:name] || 'expample.ee')) if xml_params[:name] != false xml.tag!('domain:name', (xml_params[:name] || 'example.ee')) if xml_params[:name] != false
xml.tag!('domain:period', (xml_params[:period_value] || 1), 'unit' => (xml_params[:period_unit] || 'y')) if xml_params[:period] != false xml.tag!('domain:period', (xml_params[:period_value] || 1), 'unit' => (xml_params[:period_unit] || 'y')) if xml_params[:period] != false
@ -89,6 +89,24 @@ module Epp
end end
end end
def domain_renew_xml(xml_params={})
xml = Builder::XmlMarkup.new
xml.instruct!(:xml, :standalone => 'no')
xml.epp('xmlns' => 'urn:ietf:params:xml:ns:epp-1.0') do
xml.command do
xml.renew do
xml.tag!('domain:renew', 'xmlns:domain' => 'urn:ietf:params:xml:ns:domain-1.0') do
xml.tag!('domain:name', (xml_params[:name] || 'example.ee')) if xml_params[:name] != false
xml.tag!('domain:curExpDate', (xml_params[:curExpDate] || '2014-08-07')) if xml_params[:curExpDate] != false
xml.tag!('domain:period', (xml_params[:period_value] || 1), 'unit' => (xml_params[:period_unit] || 'y')) if xml_params[:period] != false
end
end
xml.clTRID 'ABC-12345'
end
end
end
end end
RSpec.configure do |c| RSpec.configure do |c|