Refactor keyrelay specs

This commit is contained in:
Martin Lensment 2015-01-26 16:08:25 +02:00
parent 418695ccc7
commit bfb8670233
3 changed files with 154 additions and 140 deletions

View file

@ -90,12 +90,6 @@ describe 'EPP Domain', epp: true do
end
context 'with citizen as an owner' do
# before(:each) do
# Fabricate(:contact, code: 'citizen_1234')
# Fabricate(:contact, code: 'sh8013')
# Fabricate(:contact, code: 'sh801333')
# end
it 'creates a domain' do
dn = next_domain_name
response = epp_request(domain_create_xml({

View file

@ -3,22 +3,25 @@ require 'rails_helper'
describe 'EPP Keyrelay', epp: true do
let(:server_zone) { Epp::Server.new({ server: 'localhost', tag: 'zone', password: 'ghyt9e4fu', port: 701 }) }
let(:server_elkdata) { Epp::Server.new({ server: 'localhost', tag: 'elkdata', password: 'ghyt9e4fu', port: 701 }) }
let(:elkdata) { Fabricate(:registrar, { name: 'Elkdata', reg_no: '123' }) }
let(:zone) { Fabricate(:registrar) }
let(:domain) { Fabricate(:domain, name: 'example.ee', registrar: zone, dnskeys: [Fabricate.build(:dnskey)]) }
let(:epp_xml) { EppXml::Keyrelay.new }
before(:each) { create_settings }
context 'with valid user' do
before(:each) do
Fabricate(:epp_user, username: 'zone', registrar: zone)
Fabricate(:epp_user, username: 'elkdata', registrar: elkdata)
before(:all) do
@elkdata = Fabricate(:registrar, { name: 'Elkdata', reg_no: '123' })
@zone = Fabricate(:registrar)
Fabricate(:epp_user, username: 'zone', registrar: @zone)
Fabricate(:epp_user, username: 'elkdata', registrar: @elkdata)
@uniq_no = proc { @i ||= 0; @i += 1 }
end
before(:each) { Fabricate(:domain, name: next_domain_name, registrar: @zone, dnskeys: [Fabricate.build(:dnskey)]) }
let(:domain) { Domain.last }
it 'makes a keyrelay request' do
xml = epp_xml.keyrelay({
name: { value: 'example.ee' },
name: { value: domain.name },
keyData: {
flags: { value: '256' },
protocol: { value: '3' },
@ -38,7 +41,7 @@ describe 'EPP Keyrelay', epp: true do
expect(response[:msg]).to eq('Command completed successfully')
expect(response[:result_code]).to eq('1000')
expect(zone.messages.queued.count).to eq(1)
expect(@zone.messages.queued.count).to eq(1)
log = ApiLog::EppLog.all
@ -66,8 +69,9 @@ describe 'EPP Keyrelay', epp: true do
end
it 'returns an error when parameters are missing' do
msg_count = @zone.messages.queued.count
xml = epp_xml.keyrelay({
name: { value: 'example.ee' },
name: { value: domain.name },
keyData: {
flags: { value: '' },
protocol: { value: '3' },
@ -85,12 +89,13 @@ describe 'EPP Keyrelay', epp: true do
response = epp_request(xml, :xml, :elkdata)
expect(response[:msg]).to eq('Required parameter missing: flags')
expect(zone.messages.queued.count).to eq(0)
expect(@zone.messages.queued.count).to eq(msg_count)
end
it 'returns an error on invalid relative expiry' do
msg_count = @zone.messages.queued.count
xml = epp_xml.keyrelay({
name: { value: 'example.ee' },
name: { value: domain.name },
keyData: {
flags: { value: '256' },
protocol: { value: '3' },
@ -109,12 +114,13 @@ describe 'EPP Keyrelay', epp: true do
expect(response[:msg]).to eq('Expiry relative must be compatible to ISO 8601')
expect(response[:results][0][:value]).to eq('Invalid Expiry')
expect(zone.messages.queued.count).to eq(0)
expect(@zone.messages.queued.count).to eq(msg_count)
end
it 'returns an error on invalid absolute expiry' do
msg_count = @zone.messages.queued.count
xml = epp_xml.keyrelay({
name: { value: 'example.ee' },
name: { value: domain.name },
keyData: {
flags: { value: '256' },
protocol: { value: '3' },
@ -133,12 +139,13 @@ describe 'EPP Keyrelay', epp: true do
expect(response[:msg]).to eq('Expiry absolute must be compatible to ISO 8601')
expect(response[:results][0][:value]).to eq('Invalid Absolute')
expect(zone.messages.queued.count).to eq(0)
expect(@zone.messages.queued.count).to eq(msg_count)
end
it 'does not allow both relative and absolute' do
msg_count = @zone.messages.queued.count
xml = epp_xml.keyrelay({
name: { value: 'example.ee' },
name: { value: domain.name },
keyData: {
flags: { value: '256' },
protocol: { value: '3' },
@ -157,7 +164,6 @@ describe 'EPP Keyrelay', epp: true do
response = epp_request(xml, :xml, :elkdata)
expect(response[:msg]).to eq('Exactly one parameter required: expiry > relative or expiry > absolute')
expect(zone.messages.queued.count).to eq(0)
end
expect(@zone.messages.queued.count).to eq(msg_count)
end
end

View file

@ -31,13 +31,11 @@ RSpec.configure do |config|
# instead of true.
config.use_transactional_fixtures = false
config.before(:suite) do
config.before(:all) do
ActiveRecord::Base.establish_connection :api_log_test
DatabaseCleaner.strategy = :deletion
DatabaseCleaner.clean
ActiveRecord::Base.establish_connection :test
DatabaseCleaner.strategy = :truncation
DatabaseCleaner.clean
end
config.before(:each) do
@ -48,6 +46,22 @@ RSpec.configure do |config|
DatabaseCleaner.strategy = :truncation
end
config.before(:all, epp: true) do
ActiveRecord::Base.establish_connection :api_log_test
DatabaseCleaner.clean
ActiveRecord::Base.establish_connection :test
DatabaseCleaner.clean
end
config.after(:all, epp: true) do
ActiveRecord::Base.establish_connection :api_log_test
DatabaseCleaner.clean
ActiveRecord::Base.establish_connection :test
DatabaseCleaner.clean
end
config.before(:each, js: true) do
DatabaseCleaner.strategy = :truncation
end