Merge branch 'migrate-fabricators-to-factory-bot-factories' into registry-343

This commit is contained in:
Artur Beljajev 2017-11-15 15:46:54 +02:00
commit 411af16f9c
58 changed files with 2505 additions and 432 deletions

View file

@ -0,0 +1,12 @@
require 'rails_helper'
RSpec.feature 'Contact list', settings: false do
background do
sign_in_to_admin_area
end
it 'is visible' do
visit admin_contacts_path
expect(page).to have_css('.contacts')
end
end

View file

@ -0,0 +1,15 @@
require 'rails_helper'
RSpec.feature 'Contact list', settings: false do
given!(:registrar) { create(:registrar) }
given!(:contact) { create(:contact, registrar: registrar) }
background do
sign_in_to_registrar_area(user: create(:api_user_with_unlimited_balance, registrar: registrar))
end
it 'is visible' do
visit registrar_contacts_path
expect(page).to have_css('.contacts')
end
end

View file

@ -0,0 +1,29 @@
# https://en.wikipedia.org/wiki/E.164
RSpec.shared_examples 'e164' do
describe 'validation' do
it 'rejects invalid format' do
model.send("#{attribute}=", '+.1')
model.validate
expect(model.errors).to be_added(attribute, :invalid)
end
it 'rejects longer than max length' do
model.send("#{attribute}=", '1' * 18)
model.validate
expect(model.errors).to be_added(attribute, :too_long, count: 17)
end
it 'accepts valid format' do
model.send("#{attribute}=", '+123.4')
model.validate
expect(model.errors).to_not be_added(attribute, :invalid)
end
it 'accepts max length' do
model.send("#{attribute}=", '1' * 17)
model.validate
expect(model.errors).to_not be_added(attribute, :too_long, count: 17)
end
end
end

View file

@ -0,0 +1,17 @@
# https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
RSpec.shared_examples 'iso31661_alpha2' do
describe 'validation' do
it 'rejects invalid' do
model.send("#{attribute}=", 'invalid')
model.validate
expect(model.errors).to be_added(attribute, :invalid_iso31661_alpha2)
end
it 'accepts valid' do
model.send("#{attribute}=", 'US')
model.validate
expect(model.errors).to_not be_added(attribute, :invalid_iso31661_alpha2)
end
end
end

View file

@ -0,0 +1,17 @@
# https://en.wikipedia.org/wiki/ISO_8601
RSpec.shared_examples 'iso8601' do
describe 'validation' do
it 'rejects invalid' do
model.send("#{attribute}=", '2010-07-0')
model.validate
expect(model.errors).to be_added(attribute, :invalid_iso8601_date)
end
it 'accepts valid' do
model.send("#{attribute}=", '2010-07-05')
model.validate
expect(model.errors).to_not be_added(attribute, :invalid_iso8601_date)
end
end
end

View file

@ -0,0 +1,33 @@
require 'rails_helper'
require 'lib/validators/e164'
RSpec.describe Contact do
let(:contact) { described_class.new }
describe 'phone', db: false do
it_behaves_like 'e164' do
let(:model) { contact }
let(:attribute) { :phone }
end
end
describe 'phone validation', db: false do
it 'rejects absent' do
contact.phone = nil
contact.validate
expect(contact.errors).to be_added(:phone, :blank)
end
it 'rejects all zeros in country code' do
contact.phone = '+000.1'
contact.validate
expect(contact.errors).to be_added(:phone, :invalid)
end
it 'rejects all zeros in subscriber number' do
contact.phone = '+123.0'
contact.validate
expect(contact.errors).to be_added(:phone, :invalid)
end
end
end

View file

@ -0,0 +1,227 @@
require 'active_model'
require 'lib/validators/iso31661_alpha2'
require 'lib/validators/iso8601'
RSpec.describe Contact::Ident, db: false do
let(:ident) { described_class.new }
describe 'country code' do
it_behaves_like 'iso31661_alpha2' do
let(:model) { ident }
let(:attribute) { :country_code }
end
end
describe 'code validation' do
it 'rejects absent' do
ident.code = nil
ident.validate
expect(ident.errors).to be_added(:code, :blank)
end
context 'when type is :birthday' do
let(:ident) { described_class.new(type: 'birthday') }
it_behaves_like 'iso8601' do
let(:model) { ident }
let(:attribute) { :code }
end
end
context 'when type is not :birthday' do
let(:ident) { described_class.new(type: 'priv') }
it 'accepts any' do
ident.code = '%123456789%'
ident.validate
expect(ident.errors).to_not include(:code)
end
end
context 'when country code is EE' do
context 'when type is :priv' do
let(:ident) { described_class.new(country_code: 'EE', type: 'priv') }
it 'rejects invalid' do
ident.code = 'invalid'
ident.validate
expect(ident.errors).to be_added(:code, :invalid_national_id, country: 'Estonia')
end
it 'accepts valid' do
ident.code = '47101010033'
ident.validate
expect(ident.errors).to_not be_added(:code, :invalid_national_id, country: 'Estonia')
end
end
context 'when ident type is :org' do
let(:ident) { described_class.new(country_code: 'EE', type: 'org') }
it 'rejects invalid' do
ident.code = '1' * 7
ident.validate
expect(ident.errors).to be_added(:code, :invalid_reg_no, country: 'Estonia')
end
it 'accepts valid length' do
ident.code = '1' * 8
ident.validate
expect(ident.errors).to_not be_added(:code, :invalid_reg_no, country: 'Estonia')
end
end
end
context 'when ident country code is not EE' do
let(:ident) { described_class.new(country_code: 'US') }
it 'accepts any' do
ident.code = 'test-123456789'
ident.validate
expect(ident.errors).to_not include(:code)
end
end
it 'translates :invalid_national_id error message' do
expect(ident.errors.generate_message(:code, :invalid_national_id, country: 'Germany'))
.to eq('does not conform to national identification number format of Germany')
end
it 'translates :invalid_reg_no error message' do
expect(ident.errors.generate_message(:code, :invalid_reg_no, country: 'Germany'))
.to eq('does not conform to registration number format of Germany')
end
end
describe 'type validation' do
before do
allow(described_class).to receive(:types).and_return(%w(valid))
end
it 'rejects absent' do
ident.type = nil
ident.validate
expect(ident.errors).to be_added(:type, :blank)
end
it 'rejects invalid' do
ident.type = 'invalid'
ident.validate
expect(ident.errors).to be_added(:type, :inclusion)
end
it 'accepts valid' do
ident.type = 'valid'
ident.validate
expect(ident.errors).to_not be_added(:type, :inclusion)
end
end
describe 'country code validation' do
it 'rejects absent' do
ident.country_code = nil
ident.validate
expect(ident.errors).to be_added(:country_code, :blank)
end
end
describe 'mismatch validation' do
let(:ident) { described_class.new(type: 'test', country_code: 'DE') }
before do
mismatches = [Contact::Ident::MismatchValidator::Mismatch.new('test', Country.new('DE'))]
allow(Contact::Ident::MismatchValidator).to receive(:mismatches).and_return(mismatches)
end
it 'rejects mismatched' do
ident.validate
expect(ident.errors).to be_added(:base, :mismatch, type: 'test', country: 'Germany')
end
it 'accepts matched' do
ident.validate
expect(ident.errors).to_not be_added(:base, :mismatch, type: 'another-test', country: 'Germany')
end
it 'translates :mismatch error message' do
expect(ident.errors.generate_message(:base, :mismatch, type: 'test', country: 'Germany'))
.to eq('Ident type "test" is invalid for Germany')
end
end
describe '::types' do
it 'returns types' do
types = %w[
org
priv
birthday
]
expect(described_class.types).to eq(types)
end
end
describe '#birthday?' do
context 'when type is birthday' do
subject(:ident) { described_class.new(type: 'birthday') }
it { is_expected.to be_birthday }
end
context 'when type is not birthday' do
subject(:ident) { described_class.new(type: 'priv') }
it { is_expected.to_not be_birthday }
end
end
describe '#national_id?' do
context 'when type is priv' do
subject(:ident) { described_class.new(type: 'priv') }
it { is_expected.to be_national_id }
end
context 'when type is not' do
subject(:ident) { described_class.new(type: 'org') }
it { is_expected.to_not be_national_id }
end
end
describe '#reg_no?' do
context 'when type is birthday' do
subject(:ident) { described_class.new(type: 'org') }
it { is_expected.to be_reg_no }
end
context 'when type is not birthday' do
subject(:ident) { described_class.new(type: 'priv') }
it { is_expected.to_not be_reg_no }
end
end
describe '#country' do
let(:ident) { described_class.new(country_code: 'US') }
it 'returns country' do
expect(ident.country).to eq(Country.new('US'))
end
end
describe '#==' do
let(:ident) { described_class.new(code: 'test', type: 'test', country_code: 'US') }
context 'when code, type and country code are the same' do
let(:another_ident) { described_class.new(code: 'test', type: 'test', country_code: 'US') }
it 'returns true' do
expect(ident).to eq(another_ident)
end
end
context 'when code, type and country code are not the same' do
let(:another_ident) { described_class.new(code: 'another-test', type: 'test', country_code: 'US') }
it 'returns false' do
expect(ident).to_not eq(another_ident)
end
end
end
end

View file

@ -28,45 +28,6 @@ RSpec.describe Contact do
@contact.updator.should == nil
end
it 'should require country code when org' do
@contact.ident_type = 'org'
@contact.valid?
@contact.errors[:ident_country_code].should == ['is missing']
end
it 'should require country code when priv' do
@contact.ident_type = 'priv'
@contact.valid?
@contact.errors[:ident_country_code].should == ['is missing']
end
it 'should validate correct country code' do
@contact.ident = 1
@contact.ident_type = 'org'
@contact.ident_country_code = 'EE'
@contact.valid?
@contact.errors[:ident_country_code].should == []
end
it 'should require valid country code' do
@contact.ident = '123'
@contact.ident_type = 'org'
@contact.ident_country_code = 'INVALID'
@contact.valid?
expect(@contact.errors).to have_key(:ident)
end
it 'should convert to alpha2 country code' do
@contact.ident = 1
@contact.ident_type = 'org'
@contact.ident_country_code = 'ee'
@contact.validate
@contact.ident_country_code.should == 'EE'
end
it 'should not have any versions' do
@contact.versions.should == []
end
@ -119,14 +80,6 @@ RSpec.describe Contact do
@contact.domains_present?.should == false
end
it 'org should be valid' do
contact = build(:contact, ident_type: 'org', ident: '1' * 8)
contact.validate
contact.errors.full_messages.should match_array([])
end
it 'should not overwrite code' do
old_code = @contact.code
@contact.code = 'CID:REG1:should-not-overwrite-old-code-12345'
@ -217,31 +170,6 @@ RSpec.describe Contact do
end
end
context 'as birthday' do
before :example do
@contact.ident_type = 'birthday'
end
it 'birthday should be valid' do
valid = ['2012-12-11', '1990-02-16']
valid.each do |date|
@contact.ident = date
@contact.valid?
@contact.errors.full_messages.should match_array([])
end
end
it 'birthday should be invalid' do
invalid = ['123' '12/12/2012', 'aaaa', '12/12/12', '02-11-1999']
invalid.each do |date|
@contact.ident = date
@contact.valid?
@contact.errors.full_messages.should ==
["Ident Ident not in valid birthady format, should be YYYY-MM-DD"]
end
end
end
context 'with callbacks' do
before :example do
# Ensure callbacks are not taken out from other specs
@ -445,7 +373,7 @@ RSpec.describe Contact do
end
end
describe 'country code validation' do
describe 'country code validation', db: false do
let(:contact) { described_class.new(country_code: 'test') }
it 'rejects invalid' do
@ -455,37 +383,25 @@ RSpec.describe Contact do
end
end
describe 'phone validation', db: false do
describe 'identifier validation', db: false do
let(:contact) { described_class.new }
it 'rejects absent' do
contact.phone = nil
it 'rejects invalid' do
ident = Contact::Ident.new
ident.validate
contact.identifier = ident
contact.validate
expect(contact.errors).to have_key(:phone)
end
it 'rejects invalid format' do
contact.phone = '123'
contact.validate
expect(contact.errors).to have_key(:phone)
end
it 'rejects all zeros in country code' do
contact.phone = '+000.1'
contact.validate
expect(contact.errors).to have_key(:phone)
end
it 'rejects all zeros in phone number' do
contact.phone = '+123.0'
contact.validate
expect(contact.errors).to have_key(:phone)
expect(contact.errors).to be_added(:identifier, :invalid)
end
it 'accepts valid' do
contact.phone = '+123.4'
ident = Contact::Ident.new(code: 'test', type: 'priv', country_code: 'US')
ident.validate
contact.identifier = ident
contact.validate
expect(contact.errors).to_not have_key(:phone)
expect(contact.errors).to_not be_added(:identifier, :invalid)
end
end
@ -595,4 +511,13 @@ RSpec.describe Contact do
expect(domain_names).to eq({ 'test.com' => %i[admin_domain_contact].to_set })
end
end
it 'normalizes ident country code', db: false do
contact = described_class.new
contact.ident_country_code = 'ee'
contact.validate
expect(contact.ident_country_code).to eq('EE')
end
end

View file

@ -0,0 +1,21 @@
require 'rails_helper'
RSpec.describe EPP::Response::Result, db: false do
# https://tools.ietf.org/html/rfc5730#section-3
describe '::codes' do
it 'returns codes' do
codes = {
'1000' => :success,
'1001' => :success_pending,
'1300' => :success_empty_queue,
'1301' => :success_dequeue,
'2001' => :syntax_error,
'2003' => :required_param_missing,
'2005' => :param_syntax_error,
'2308' => :data_management_policy_violation
}
expect(described_class.codes).to eq(codes)
end
end
end

View file

@ -35,10 +35,6 @@ describe Registrar do
@registrar.reference_no.should_not be_blank
@registrar.reference_no.last(10).to_i.should_not == 0
end
it 'should not have priv contacts' do
@registrar.priv_contacts.size.should == 0
end
end
context 'with valid attributes' do
@ -118,9 +114,5 @@ describe Registrar do
registrar.valid?
registrar.errors.full_messages.should == ['Code is forbidden to use']
end
it 'should not have priv contacts' do
@registrar.priv_contacts.size.should == 0
end
end
end

View file

@ -10,6 +10,7 @@ require 'support/requests/epp_helpers'
require 'support/features/session_helpers'
require 'support/matchers/alias_attribute'
require 'support/matchers/epp/code'
require 'support/matchers/epp/have_result'
require 'support/capybara'
require 'support/devise'
@ -28,7 +29,8 @@ RSpec.configure do |config|
config.include AbstractController::Translation, type: :request
config.include AbstractController::Translation, type: :feature
config.include AbstractController::Translation, type: :mailer
config.include Requests::EPPHelpers, type: :request
config.include Requests::EPPHelpers, epp: true
config.include Matchers::EPP, epp: true
config.define_derived_metadata(file_path: %r[/spec/features/]) do |metadata|
metadata[:db] = true if metadata[:db].nil?

View file

@ -0,0 +1,289 @@
require 'rails_helper'
RSpec.describe 'EPP contact:create' do
let(:request) { post '/epp/command/create', frame: request_xml }
before do
Setting.address_processing = false
sign_in_to_epp_area
end
context 'when all ident params are valid' do
let(:ident) { Contact.first.identifier }
let(:request_xml) { <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<create>
<contact:create xmlns:contact="https://epp.tld.ee/schema/contact-ee-1.1.xsd">
<contact:postalInfo>
<contact:name>test</contact:name>
</contact:postalInfo>
<contact:voice>+1.2</contact:voice>
<contact:email>test@test.com</contact:email>
</contact:create>
</create>
<extension>
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
<eis:ident type="priv" cc="US">test</eis:ident>
</eis:extdata>
</extension>
</command>
</epp>
XML
}
it 'creates a contact' do
expect { request }.to change { Contact.count }.from(0).to(1)
end
it 'saves ident type' do
request
expect(ident.type).to eq('priv')
end
it 'saves ident country code' do
request
expect(ident.country_code).to eq('US')
end
specify do
request
expect(epp_response).to have_result(:success)
end
end
context 'when code is blank' do
let(:request_xml) { <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<create>
<contact:create xmlns:contact="https://epp.tld.ee/schema/contact-ee-1.1.xsd">
<contact:postalInfo>
<contact:name>test</contact:name>
</contact:postalInfo>
<contact:voice>+1.2</contact:voice>
<contact:email>test@test.com</contact:email>
</contact:create>
</create>
<extension>
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
<eis:ident type="priv" cc="US"></eis:ident>
</eis:extdata>
</extension>
</command>
</epp>
XML
}
it 'does not create a contact' do
expect { request }.to_not change { Contact.count }
end
specify do
request
expect(epp_response).to have_result(:required_param_missing,
'Required parameter missing: extension > extdata > ident [ident]')
end
end
context 'when code is not valid national id' do
let(:request_xml) { <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<create>
<contact:create xmlns:contact="https://epp.tld.ee/schema/contact-ee-1.1.xsd">
<contact:postalInfo>
<contact:name>test</contact:name>
</contact:postalInfo>
<contact:voice>+1.2</contact:voice>
<contact:email>test@test.com</contact:email>
</contact:create>
</create>
<extension>
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
<eis:ident type="priv" cc="DE">invalid</eis:ident>
</eis:extdata>
</extension>
</command>
</epp>
XML
}
before do
country_specific_validations = {
Country.new('DE') => proc { false },
}
allow(Contact::Ident::NationalIdValidator).to receive(:country_specific_validations)
.and_return(country_specific_validations)
end
it 'does not create a contact' do
expect { request }.to_not change { Contact.count }
end
specify do
request
message = 'Ident code does not conform to national identification number format of Germany'
expect(epp_response).to have_result(:param_syntax_error, message)
end
end
context 'when code is not valid registration number' do
let(:request_xml) { <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<create>
<contact:create xmlns:contact="https://epp.tld.ee/schema/contact-ee-1.1.xsd">
<contact:postalInfo>
<contact:name>test</contact:name>
</contact:postalInfo>
<contact:voice>+1.2</contact:voice>
<contact:email>test@test.com</contact:email>
</contact:create>
</create>
<extension>
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
<eis:ident type="org" cc="DE">invalid</eis:ident>
</eis:extdata>
</extension>
</command>
</epp>
XML
}
before do
country_specific_formats = {
Country.new('DE') => /\Avalid\z/,
}
allow(Contact::Ident::RegNoValidator).to receive(:country_specific_formats).and_return(country_specific_formats)
end
it 'does not create a contact' do
expect { request }.to_not change { Contact.count }
end
specify do
request
expect(epp_response).to have_result(:param_syntax_error,
'Ident code does not conform to registration number format of Germany')
end
end
context 'when country code is absent' do
let(:request_xml) { <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<create>
<contact:create xmlns:contact="https://epp.tld.ee/schema/contact-ee-1.1.xsd">
<contact:postalInfo>
<contact:name>test</contact:name>
</contact:postalInfo>
<contact:voice>+1.2</contact:voice>
<contact:email>test@test.com</contact:email>
</contact:create>
</create>
<extension>
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
<eis:ident type="priv">test</eis:ident>
</eis:extdata>
</extension>
</command>
</epp>
XML
}
it 'does not create a contact' do
expect { request }.to_not change { Contact.count }
end
specify do
request
expect(epp_response).to have_result(:required_param_missing,
'Required ident attribute missing: cc')
end
end
context 'when country code is blank' do
let(:request_xml) { <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<create>
<contact:create xmlns:contact="https://epp.tld.ee/schema/contact-ee-1.1.xsd">
<contact:postalInfo>
<contact:name>test</contact:name>
</contact:postalInfo>
<contact:voice>+1.2</contact:voice>
<contact:email>test@test.com</contact:email>
</contact:create>
</create>
<extension>
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
<eis:ident type="priv" cc="">test</eis:ident>
</eis:extdata>
</extension>
</command>
</epp>
XML
}
it 'does not create a contact' do
expect { request }.to_not change { Contact.count }
end
specify do
request
expect(epp_response).to have_result(:syntax_error)
end
end
context 'when mismatches' do
let(:request_xml) { <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<create>
<contact:create xmlns:contact="https://epp.tld.ee/schema/contact-ee-1.1.xsd">
<contact:postalInfo>
<contact:name>test</contact:name>
</contact:postalInfo>
<contact:voice>+1.2</contact:voice>
<contact:email>test@test.com</contact:email>
</contact:create>
</create>
<extension>
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
<eis:ident type="priv" cc="DE">test</eis:ident>
</eis:extdata>
</extension>
</command>
</epp>
XML
}
before do
mismatches = [
Contact::Ident::MismatchValidator::Mismatch.new('priv', Country.new('DE'))
]
allow(Contact::Ident::MismatchValidator).to receive(:mismatches).and_return(mismatches)
end
it 'does not create a contact' do
expect { request }.to_not change { Contact.count }
end
specify do
request
expect(epp_response).to have_result(:param_syntax_error,
'Ident type "priv" is invalid for Germany')
end
end
end

View file

@ -0,0 +1,196 @@
require 'rails_helper'
# https://github.com/internetee/registry/issues/576
RSpec.describe 'EPP contact:update' do
let(:ident) { contact.identifier }
let(:request) { post '/epp/command/update', frame: request_xml }
let(:request_xml) { <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<update>
<contact:update xmlns:contact="https://epp.tld.ee/schema/contact-ee-1.1.xsd">
<contact:id>TEST</contact:id>
<contact:chg>
<contact:postalInfo>
<contact:name>test</contact:name>
</contact:postalInfo>
</contact:chg>
</contact:update>
</update>
<extension>
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
<eis:ident cc="US" type="priv">test</eis:ident>
</eis:extdata>
</extension>
</command>
</epp>
XML
}
before do
sign_in_to_epp_area
end
context 'when contact ident is valid' do
context 'when submitted ident matches current one' do
let!(:contact) { create(:contact, code: 'TEST',
ident: 'test',
ident_type: 'priv',
ident_country_code: 'US') }
specify do
request
expect(epp_response).to have_result(:success)
end
end
context 'when submitted ident does not match current one' do
let!(:contact) { create(:contact, code: 'TEST',
ident: 'another-test',
ident_type: 'priv',
ident_country_code: 'US') }
it 'does not update code' do
expect do
request
contact.reload
end.to_not change { ident.code }
end
it 'does not update type' do
expect do
request
contact.reload
end.to_not change { ident.type }
end
it 'does not update country code' do
expect do
request
contact.reload
end.to_not change { ident.country_code }
end
specify do
request
expect(epp_response).to have_result(:data_management_policy_violation,
t('epp.contacts.errors.valid_ident'))
end
end
end
context 'when contact ident is invalid' do
let(:contact) { build(:contact, code: 'TEST', ident: 'test', ident_type: nil, ident_country_code: nil) }
before do
contact.save(validate: false)
end
context 'when submitted ident is the same as current one' do
let(:request_xml) { <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<update>
<contact:update xmlns:contact="https://epp.tld.ee/schema/contact-ee-1.1.xsd">
<contact:id>TEST</contact:id>
<contact:chg>
<contact:postalInfo>
<contact:name>test</contact:name>
</contact:postalInfo>
</contact:chg>
</contact:update>
</update>
<extension>
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
<eis:ident cc="US" type="priv">test</eis:ident>
</eis:extdata>
</extension>
</command>
</epp>
XML
}
it 'does not update code' do
expect do
request
contact.reload
end.to_not change { ident.code }
end
it 'updates type' do
request
contact.reload
expect(ident.type).to eq('priv')
end
it 'updates country code' do
request
contact.reload
expect(ident.country_code).to eq('US')
end
specify do
request
expect(epp_response).to have_result(:success)
end
end
context 'when submitted ident is different from current one' do
let(:request_xml) { <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<update>
<contact:update xmlns:contact="https://epp.tld.ee/schema/contact-ee-1.1.xsd">
<contact:id>TEST</contact:id>
<contact:chg>
<contact:postalInfo>
<contact:name>test</contact:name>
</contact:postalInfo>
</contact:chg>
</contact:update>
</update>
<extension>
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
<eis:ident cc="US" type="priv">another-test</eis:ident>
</eis:extdata>
</extension>
</command>
</epp>
XML
}
it 'does not update code' do
expect do
request
contact.reload
end.to_not change { ident.code }
end
it 'does not update type' do
expect do
request
contact.reload
end.to_not change { ident.type }
end
it 'does not update country code' do
expect do
request
contact.reload
end.to_not change { ident.country_code }
end
specify do
request
expect(epp_response).to have_result(:data_management_policy_violation,
t('epp.contacts.errors.ident_update'))
end
end
end
end

View file

@ -0,0 +1,37 @@
module Matchers
module EPP
class HaveResultMatcher
def initialize(expected)
@expected = expected
end
def matches?(target)
@target = target
if @expected.message.present?
@target.results.any? { |result| result.code == @expected.code && result.message == @expected.message }
else
@target.results.any? { |result| result.code == @expected.code }
end
end
def failure_message
"expected #{@target.results} to have result #{@expected.inspect}"
end
def failure_message_when_negated
"expected #{@target.results} not to have result #{@expected.inspect}"
end
def description
"should have EPP code of #{@expected}"
end
end
def have_result(type, message = nil)
code = ::EPP::Response::Result.codes.key(type)
result = ::EPP::Response::Result.new(code, message)
HaveResultMatcher.new(result)
end
end
end

View file

@ -7,5 +7,9 @@ module Requests
def valid_legal_document
Base64.encode64('a' * 5000)
end
def epp_response
EPP::Response.from_xml(response.body)
end
end
end

View file

@ -0,0 +1,13 @@
require 'rails_helper'
RSpec.describe Contact::Ident::MismatchValidator do
describe '::mismatches' do
it 'returns mismatches' do
mismatches = [
Contact::Ident::MismatchValidator::Mismatch.new('birthday', Country.new('EE'))
]
expect(described_class.mismatches).to eq(mismatches)
end
end
end