Added custom contact id support

This commit is contained in:
Priit Tark 2015-03-03 16:30:31 +02:00
parent aa5cc83344
commit 767f7bb6df
13 changed files with 195 additions and 42 deletions

View file

@ -13,10 +13,8 @@ describe 'EPP Contact', epp: true do
login_as :registrar1
Contact.skip_callback(:create, :before, :generate_code)
Contact.skip_callback(:create, :before, :generate_auth_info)
@contact = Fabricate(:contact, registrar: @registrar1)
@legal_document = {
legalDocument: {
value: 'JVBERi0xLjQKJcOkw7zDtsOfCjIgMCBvYmoKPDwvTGVuZ3RoIDMgMCBSL0Zp==',
@ -25,11 +23,6 @@ describe 'EPP Contact', epp: true do
}
end
after :all do
Contact.set_callback(:create, :before, :generate_code)
Contact.set_callback(:create, :before, :generate_auth_info)
end
context 'with valid user' do
context 'create command' do
def create_request(overwrites = {})
@ -133,6 +126,17 @@ describe 'EPP Contact', epp: true do
# 5 seconds for what-ever weird lag reasons might happen
cr_date.text.to_time.should be_within(5).of(Time.now)
end
it 'successfully saves custom code' do
response = create_request(
{ id: { value: '12345' } }
)
response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000'
Contact.last.code.should == 'registrar1:12345'
end
end
context 'update command' do
@ -140,11 +144,9 @@ describe 'EPP Contact', epp: true do
@contact =
Fabricate(
:contact,
# created_by_id: 1,
registrar: @registrar1,
email: 'not_updated@test.test',
code: 'sh8013',
auth_info: 'password'
code: 'sh8013'
)
end
@ -226,6 +228,20 @@ describe 'EPP Contact', epp: true do
response[:results][1][:msg].should == 'Email is invalid'
response[:results][1][:result_code].should == '2005'
end
it 'should not update code with custom string' do
response = update_request(
id: { value: 'sh8013' },
chg: {
id: { value: 'notpossibletoupdate' }
}
)
response[:msg].should == 'Object does not exist'
response[:result_code].should == '2303'
@contact.reload.code.should == 'sh8013'
end
end
context 'delete command' do

View file

@ -11,8 +11,6 @@ describe 'EPP Domain', epp: true do
login_as :registrar1
Contact.skip_callback(:create, :before, :generate_code)
Fabricate(:contact, code: 'citizen_1234')
Fabricate(:contact, code: 'sh8013')
Fabricate(:contact, code: 'sh801333')
@ -254,8 +252,8 @@ describe 'EPP Domain', epp: true do
})
response = epp_plain_request(xml, :xml)
response[:result_code].should == '2005'
response[:msg].should == 'Hostname is invalid'
response[:result_code].should == '2005'
end
it 'checks hostAttr presence' do
@ -271,8 +269,8 @@ describe 'EPP Domain', epp: true do
})
response = epp_plain_request(xml, :xml)
response[:result_code].should == '2003'
response[:msg].should == 'Required parameter missing: create > create > ns > hostAttr'
response[:result_code].should == '2003'
end
it 'creates domain with nameservers with ips' do

View file

@ -1,13 +1,16 @@
Fabricator(:contact) do
code { "sh#{Faker::Number.number(8)}" }
auth_info 'password'
name { sequence(:name) { |i| "#{Faker::Name.name}#{i}" } }
phone '+372.12345678'
email Faker::Internet.email
ident '37605030299'
ident_type 'priv'
ident_country_code 'EE'
auth_info 'ccds4324pok'
address
registrar { Fabricate(:registrar, name: Faker::Company.name, reg_no: Faker::Company.duns_number) }
disclosure { Fabricate(:contact_disclosure) }
# rubocop: disable Style/SymbolProc
after_validation { |c| c.disable_generate_auth_info! }
# rubocop: enamble Style/SymbolProc
end

View file

@ -91,6 +91,12 @@ describe Contact do
it 'should not have any versions' do
@contact.versions.should == []
end
it 'should not accept long code' do
@contact.code = 'verylongcode' * 100
@contact.valid?
@contact.errors[:code].should == ['is too long (maximum is 100 characters)']
end
end
context 'with valid attributes' do
@ -130,6 +136,17 @@ describe Contact do
@contact.errors.full_messages.should match_array([])
end
it 'should not accept new custom code' do
old_code = @contact.code
@contact.code = 'CID:REG1:12345'
@contact.save.should == true
@contact.code.should == old_code
end
it 'should have static password' do
@contact.auth_info.should == 'password'
end
context 'as birthday' do
before :all do
@contact.ident_type = 'birthday'
@ -182,20 +199,56 @@ describe Contact do
end
context 'after create' do
it 'should generate a new code and password' do
it 'should not generate a new code when code is present' do
@contact = Fabricate.build(:contact, code: '123asd', auth_info: 'qwe321')
@contact.code.should == '123asd'
@contact.save.should == true
@contact.code.should == '123asd'
end
it 'should generate a new password' do
@contact = Fabricate.build(:contact, code: '123asd', auth_info: 'qwe321')
@contact.code.should == '123asd'
@contact.auth_info.should == 'qwe321'
@contact.save!
@contact.code.should_not == '123asd'
@contact.save.should == true
@contact.auth_info.should_not == 'qwe321'
end
it 'should not allow same code' do
@double_contact = Fabricate.build(:contact, code: @contact.code)
@double_contact.valid?
@double_contact.errors.full_messages.should == ["Code Contact id already exists"]
end
it 'should allow supported code format' do
@contact = Fabricate.build(:contact, code: 'CID:REG1:12345')
@contact.valid?
@contact.errors.full_messages.should == []
end
it 'should not allow unsupported characters in code' do
@contact = Fabricate.build(:contact, code: 'unsupported!ÄÖÜ~?')
@contact.valid?
@contact.errors.full_messages.should == ['Code is invalid']
end
it 'should generate code if empty code is given' do
@contact = Fabricate(:contact, code: '')
@contact.code.should_not == ''
end
it 'should not allow empty spaces as code' do
@contact = Fabricate.build(:contact, code: ' ')
@contact.valid?
@contact.errors.full_messages.should == ['Code is invalid']
end
end
context 'after update' do
before :all do
@contact.code = '123asd'
@contact.auth_info = 'qwe321'
@contact = Fabricate.build(:contact, code: '123asd', auth_info: 'qwe321')
@contact.save
@contact.code.should == '123asd'
@auth_info = @contact.auth_info
end
it 'should not generate new code' do
@ -205,7 +258,7 @@ describe Contact do
it 'should not generate new auth_info' do
@contact.update_attributes(name: 'fvrsgbqevciherot23')
@contact.auth_info.should == 'qwe321'
@contact.auth_info.should == @auth_info
end
end
end

View file

@ -28,6 +28,10 @@ describe Registrar do
@registrar.errors[:email].should == ['is invalid']
@registrar.errors[:billing_email].should == ['is invalid']
end
it 'should not have valid code' do
@registrar.code.should == nil
end
end
context 'with valid attributes' do
@ -59,5 +63,26 @@ describe Registrar do
it 'should return full address' do
@registrar.address.should == 'Street 999, Town, County, Postal'
end
it 'should have code' do
@registrar.code.should =~ /registrar/
end
it 'should not be able to change code' do
@registrar.code = 'not-updated'
@registrar.code.should =~ /registrar/
end
it 'should automatically add next code if original is taken' do
@registrar = Fabricate(:registrar, name: 'uniq')
@registrar.name = 'New name'
@registrar.code.should == 'uniq'
@registrar.save
@new_registrar = Fabricate.build(:registrar, name: 'uniq')
@new_registrar.valid?
@new_registrar.errors.full_messages.should == []
@new_registrar.code.should == 'uniq1'
end
end
end