Refactor prices

#475
This commit is contained in:
Artur Beljajev 2017-04-26 00:51:06 +03:00
parent 5fdc1938af
commit 5a533e09bf
44 changed files with 1027 additions and 375 deletions

View file

@ -1,28 +1,22 @@
require 'rails_helper'
RSpec.describe 'EPP domain:create' do
subject(:response_xml) { Nokogiri::XML(response.body) }
subject(:response_code) { response_xml.xpath('//xmlns:result').first['code'] }
subject(:response_description) { response_xml.css('result msg').text }
RSpec.describe 'EPP domain:create', settings: false do
let(:request) { post '/epp/command/create', frame: request_xml }
let!(:registrar) { create(:registrar_with_unlimited_balance) }
let!(:user) { create(:api_user_epp, registrar: registrar) }
let!(:contact) { create(:contact, code: 'test') }
let!(:zone) { create(:zone, origin: 'test') }
let!(:price) { create(:price,
duration: '1 year',
price: Money.from_amount(1),
operation_category: 'create',
valid_from: Time.zone.parse('05.07.2010'),
valid_to: Time.zone.parse('05.07.2010'),
zone: zone)
}
before :example do
travel_to Time.zone.parse('05.07.2010')
registrar = create(:registrar)
user = create(:api_user_epp, registrar: registrar)
create(:account, registrar: registrar, balance: 1.0)
create(:contact, code: 'test')
create(:pricelist,
category: 'com',
duration: '1year',
price: 1.to_money,
operation_category: 'create',
valid_from: Time.zone.parse('05.07.2010'),
valid_to: Time.zone.parse('05.07.2010')
)
sign_in_to_epp_area(user: user)
end
@ -38,7 +32,7 @@ RSpec.describe 'EPP domain:create' do
<command>
<create>
<domain:create xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>test.com</domain:name>
<domain:name>test.test</domain:name>
<domain:period unit="y">1</domain:period>
<domain:ns>
<domain:hostAttr>
@ -47,13 +41,11 @@ RSpec.describe 'EPP domain:create' do
</domain:hostAttr>
</domain:ns>
<domain:registrant>test</domain:registrant>
<domain:contact type="admin">test</domain:contact>
<domain:contact type="tech">test</domain:contact>
</domain:create>
</create>
<extension>
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
<eis:legalDocument type="pdf">#{Base64.encode64('a' * 5000)}</eis:legalDocument>
<eis:legalDocument type="pdf">#{valid_legal_document}</eis:legalDocument>
</eis:extdata>
</extension>
</command>
@ -65,18 +57,13 @@ RSpec.describe 'EPP domain:create' do
Setting.ns_min_count = 2
end
it 'returns epp code of 2308' do
post '/epp/command/create', frame: request_xml
expect(response_code).to eq('2308')
it 'does not create domain' do
expect { request }.to_not change { Domain.count }
end
it 'returns epp description' do
post '/epp/command/create', frame: request_xml
description = 'Data management policy violation;' \
" Nameserver count must be between #{Setting.ns_min_count}-#{Setting.ns_max_count}" \
' for active domains [nameservers]'
expect(response_description).to eq(description)
specify do
request
expect(response).to have_code_of(2308)
end
end
@ -87,16 +74,14 @@ RSpec.describe 'EPP domain:create' do
<command>
<create>
<domain:create xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>test.com</domain:name>
<domain:name>test.test</domain:name>
<domain:period unit="y">1</domain:period>
<domain:registrant>test</domain:registrant>
<domain:contact type="admin">test</domain:contact>
<domain:contact type="tech">test</domain:contact>
</domain:create>
</create>
<extension>
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
<eis:legalDocument type="pdf">#{Base64.encode64('a' * 5000)}</eis:legalDocument>
<eis:legalDocument type="pdf">#{valid_legal_document}</eis:legalDocument>
</eis:extdata>
</extension>
</command>
@ -104,22 +89,21 @@ RSpec.describe 'EPP domain:create' do
XML
}
it 'returns epp code of 1000' do
post '/epp/command/create', frame: request_xml
expect(response_code).to eq('1000'), "Expected EPP code of 1000, got #{response_code} (#{response_description})"
end
it 'creates new domain' do
expect { post '/epp/command/create', frame: request_xml }.to change { Domain.count }.from(0).to(1)
expect { request }.to change { Domain.count }.from(0).to(1)
end
describe 'new domain' do
it 'has status of inactive' do
post '/epp/command/create', frame: request_xml
domain = Domain.find_by(name: 'test.com')
expect(domain.statuses).to include(DomainStatus::INACTIVE)
request
expect(Domain.first.statuses).to include(DomainStatus::INACTIVE)
end
end
specify do
request
expect(response).to have_code_of(1000)
end
end
end
end