mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 09:57:23 +02:00
parent
b265944cdb
commit
f9d4e3433b
1 changed files with 43 additions and 105 deletions
|
@ -1,7 +1,7 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe Contact do
|
describe Contact do
|
||||||
before :all do
|
before :example do
|
||||||
Fabricate(:zonefile_setting, origin: 'ee')
|
Fabricate(:zonefile_setting, origin: 'ee')
|
||||||
@api_user = Fabricate(:api_user)
|
@api_user = Fabricate(:api_user)
|
||||||
end
|
end
|
||||||
|
@ -17,28 +17,10 @@ describe Contact do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with invalid attribute' do
|
context 'with invalid attribute' do
|
||||||
before :all do
|
before :example do
|
||||||
@contact = Contact.new
|
@contact = Contact.new
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not be valid' do
|
|
||||||
@contact.valid?
|
|
||||||
@contact.errors.full_messages.should match_array([
|
|
||||||
"Name Required parameter missing - name",
|
|
||||||
"Phone Required parameter missing - phone",
|
|
||||||
"Phone Phone nr is invalid",
|
|
||||||
"Email Required parameter missing - email",
|
|
||||||
"Email Email is invalid",
|
|
||||||
"Ident Required parameter missing - ident",
|
|
||||||
"Registrar is missing",
|
|
||||||
"Ident type is missing",
|
|
||||||
"City is missing",
|
|
||||||
"Country code is missing",
|
|
||||||
"Street is missing",
|
|
||||||
"Zip is missing"
|
|
||||||
])
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should not have creator' do
|
it 'should not have creator' do
|
||||||
@contact.creator.should == nil
|
@contact.creator.should == nil
|
||||||
end
|
end
|
||||||
|
@ -66,6 +48,7 @@ describe Contact do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should validate correct country code' do
|
it 'should validate correct country code' do
|
||||||
|
@contact.ident = 1
|
||||||
@contact.ident_type = 'org'
|
@contact.ident_type = 'org'
|
||||||
@contact.ident_country_code = 'EE'
|
@contact.ident_country_code = 'EE'
|
||||||
@contact.valid?
|
@contact.valid?
|
||||||
|
@ -79,14 +62,14 @@ describe Contact do
|
||||||
@contact.ident_country_code = 'INVALID'
|
@contact.ident_country_code = 'INVALID'
|
||||||
@contact.valid?
|
@contact.valid?
|
||||||
|
|
||||||
@contact.errors[:ident].should ==
|
expect(@contact.errors).to have_key(:ident)
|
||||||
['Ident country code is not valid, should be in ISO_3166-1 alpha 2 format']
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should convert to alpha2 country code' do
|
it 'should convert to alpha2 country code' do
|
||||||
|
@contact.ident = 1
|
||||||
@contact.ident_type = 'org'
|
@contact.ident_type = 'org'
|
||||||
@contact.ident_country_code = 'ee'
|
@contact.ident_country_code = 'ee'
|
||||||
@contact.valid?
|
@contact.validate
|
||||||
|
|
||||||
@contact.ident_country_code.should == 'EE'
|
@contact.ident_country_code.should == 'EE'
|
||||||
end
|
end
|
||||||
|
@ -102,9 +85,11 @@ describe Contact do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not allow double status' do
|
it 'should not allow double status' do
|
||||||
@contact.statuses = ['ok', 'ok']
|
contact = described_class.new(statuses: %w(ok ok))
|
||||||
@contact.valid?
|
|
||||||
@contact.errors[:statuses].should == ['not uniq']
|
contact.validate
|
||||||
|
|
||||||
|
expect(contact.statuses).to eq(%w(ok))
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should have no related domain descriptions' do
|
it 'should have no related domain descriptions' do
|
||||||
|
@ -123,21 +108,10 @@ describe Contact do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with valid attributes' do
|
context 'with valid attributes' do
|
||||||
before :all do
|
before :example do
|
||||||
@contact = Fabricate(:contact)
|
@contact = Fabricate(:contact)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should be valid' do
|
|
||||||
@contact.valid?
|
|
||||||
@contact.errors.full_messages.should match_array([])
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should be valid twice' do
|
|
||||||
@contact = Fabricate(:contact)
|
|
||||||
@contact.valid?
|
|
||||||
@contact.errors.full_messages.should match_array([])
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should have one version' do
|
it 'should have one version' do
|
||||||
with_versioning do
|
with_versioning do
|
||||||
@contact.versions.reload.should == []
|
@contact.versions.reload.should == []
|
||||||
|
@ -153,10 +127,11 @@ describe Contact do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'org should be valid' do
|
it 'org should be valid' do
|
||||||
@contact.ident_type = 'org'
|
contact = Fabricate.build(:contact, ident_type: 'org', ident: '1' * 8)
|
||||||
@contact.ident = '1234'
|
|
||||||
@contact.valid?
|
contact.validate
|
||||||
@contact.errors.full_messages.should match_array([])
|
|
||||||
|
contact.errors.full_messages.should match_array([])
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not overwrite code' do
|
it 'should not overwrite code' do
|
||||||
|
@ -188,45 +163,11 @@ describe Contact do
|
||||||
contact.statuses.should == [Contact::SERVER_UPDATE_PROHIBITED]
|
contact.statuses.should == [Contact::SERVER_UPDATE_PROHIBITED]
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should have linked status when domain' do
|
|
||||||
contact = Fabricate(:contact)
|
|
||||||
tech_domain_contact = Fabricate(:tech_domain_contact, contact_id: contact.id)
|
|
||||||
contact.statuses.should == %w(ok)
|
|
||||||
domain = Fabricate(:domain, tech_domain_contacts: [tech_domain_contact])
|
|
||||||
|
|
||||||
contact = domain.contacts.first
|
|
||||||
contact.save
|
|
||||||
contact.statuses.sort.should == %w(linked ok)
|
|
||||||
|
|
||||||
contact = domain.contacts.second
|
|
||||||
contact.save
|
|
||||||
contact.statuses.sort.should == %w(linked ok)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should not have linked status when no domain' do
|
|
||||||
@admin_domain_contact = Fabricate(:admin_domain_contact, contact_id: @contact.id)
|
|
||||||
@domain = Fabricate(:domain, admin_domain_contacts: [@admin_domain_contact])
|
|
||||||
contact = @domain.contacts.first
|
|
||||||
contact.save
|
|
||||||
|
|
||||||
contact.statuses.sort.should == %w(linked ok)
|
|
||||||
|
|
||||||
contact.domains.first.destroy
|
|
||||||
contact.reload
|
|
||||||
contact.statuses.should == %w(ok)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should have code' do
|
it 'should have code' do
|
||||||
@contact.code.should =~ /FIXED:..../
|
registrar = Fabricate.create(:registrar, code: 'registrarcode')
|
||||||
end
|
contact = Fabricate.create(:contact, registrar: registrar, code: 'contactcode')
|
||||||
|
|
||||||
it 'should have linked status when domain is created' do
|
expect(contact.code).to eq('REGISTRARCODE:CONTACTCODE')
|
||||||
# @admin_domain_contact = Fabricate(:admin_domain_contact)
|
|
||||||
# @domain = Fabricate(:domain, admin_domain_contacts: [@admin_domain_contact])
|
|
||||||
# puts @domain.contacts.size
|
|
||||||
# contact = @domain.contacts.first
|
|
||||||
|
|
||||||
# contact.statuses.map(&:value).should == %w(ok linked)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should save status notes' do
|
it 'should save status notes' do
|
||||||
|
@ -281,7 +222,7 @@ describe Contact do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'as birthday' do
|
context 'as birthday' do
|
||||||
before :all do
|
before :example do
|
||||||
@contact.ident_type = 'birthday'
|
@contact.ident_type = 'birthday'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -306,7 +247,7 @@ describe Contact do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with callbacks' do
|
context 'with callbacks' do
|
||||||
before :all do
|
before :example do
|
||||||
# Ensure callbacks are not taken out from other specs
|
# Ensure callbacks are not taken out from other specs
|
||||||
Contact.set_callback(:create, :before, :generate_auth_info)
|
Contact.set_callback(:create, :before, :generate_auth_info)
|
||||||
end
|
end
|
||||||
|
@ -314,6 +255,7 @@ describe Contact do
|
||||||
context 'after create' do
|
context 'after create' do
|
||||||
it 'should not generate a new code when code is present' do
|
it 'should not generate a new code when code is present' do
|
||||||
@contact = Fabricate.build(:contact,
|
@contact = Fabricate.build(:contact,
|
||||||
|
registrar: Fabricate(:registrar, code: 'FIXED'),
|
||||||
code: 'FIXED:new-code',
|
code: 'FIXED:new-code',
|
||||||
auth_info: 'qwe321')
|
auth_info: 'qwe321')
|
||||||
@contact.code.should == 'FIXED:new-code' # still new record
|
@contact.code.should == 'FIXED:new-code' # still new record
|
||||||
|
@ -321,20 +263,21 @@ describe Contact do
|
||||||
@contact.code.should == 'FIXED:NEW-CODE'
|
@contact.code.should == 'FIXED:NEW-CODE'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not allaw to use same code' do
|
it 'should not allow to use same code' do
|
||||||
@contact = Fabricate.build(:contact,
|
registrar = Fabricate.create(:registrar, code: 'FIXED')
|
||||||
code: 'FIXED:new-code',
|
|
||||||
auth_info: 'qwe321')
|
|
||||||
@contact.code.should == 'FIXED:new-code' # still new record
|
|
||||||
@contact.save.should == true
|
|
||||||
@contact.code.should == 'FIXED:NEW-CODE'
|
|
||||||
|
|
||||||
@contact = Fabricate.build(:contact,
|
Fabricate.create(:contact,
|
||||||
|
registrar: registrar,
|
||||||
code: 'FIXED:new-code',
|
code: 'FIXED:new-code',
|
||||||
auth_info: 'qwe321')
|
auth_info: 'qwe321')
|
||||||
@contact.code.should == 'FIXED:new-code' # still new record
|
@contact = Fabricate.build(:contact,
|
||||||
@contact.valid?
|
registrar: registrar,
|
||||||
@contact.errors.full_messages.should == ["Code Contact id already exists"]
|
code: 'FIXED:new-code',
|
||||||
|
auth_info: 'qwe321')
|
||||||
|
|
||||||
|
@contact.validate
|
||||||
|
|
||||||
|
expect(@contact.errors).to have_key(:code)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should generate a new password' do
|
it 'should generate a new password' do
|
||||||
|
@ -344,20 +287,14 @@ describe Contact do
|
||||||
@contact.auth_info.should_not be_nil
|
@contact.auth_info.should_not be_nil
|
||||||
end
|
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
|
it 'should allow supported code format' do
|
||||||
@contact = Fabricate.build(:contact, code: 'CID:REG1:12345')
|
@contact = Fabricate.build(:contact, code: 'CID:REG1:12345', registrar: Fabricate(:registrar, code: 'FIXED'))
|
||||||
@contact.valid?
|
@contact.valid?
|
||||||
@contact.errors.full_messages.should == []
|
@contact.errors.full_messages.should == []
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not allow unsupported characters in code' do
|
it 'should not allow unsupported characters in code' do
|
||||||
@contact = Fabricate.build(:contact, code: 'unsupported!ÄÖÜ~?')
|
@contact = Fabricate.build(:contact, code: 'unsupported!ÄÖÜ~?', registrar: Fabricate(:registrar, code: 'FIXED'))
|
||||||
@contact.valid?
|
@contact.valid?
|
||||||
@contact.errors.full_messages.should == ['Code is invalid']
|
@contact.errors.full_messages.should == ['Code is invalid']
|
||||||
end
|
end
|
||||||
|
@ -368,15 +305,16 @@ describe Contact do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not ignore empty spaces as code and generate new one' do
|
it 'should not ignore empty spaces as code and generate new one' do
|
||||||
@contact = Fabricate.build(:contact, code: ' ')
|
@contact = Fabricate.build(:contact, code: ' ', registrar: Fabricate(:registrar, code: 'FIXED'))
|
||||||
@contact.valid?.should == true
|
@contact.valid?.should == true
|
||||||
@contact.code.should =~ /FIXED:..../
|
@contact.code.should =~ /FIXED:..../
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'after update' do
|
context 'after update' do
|
||||||
before :all do
|
before :example do
|
||||||
@contact = Fabricate.build(:contact,
|
@contact = Fabricate.build(:contact,
|
||||||
|
registrar: Fabricate(:registrar, code: 'FIXED'),
|
||||||
code: '123asd',
|
code: '123asd',
|
||||||
auth_info: 'qwe321')
|
auth_info: 'qwe321')
|
||||||
@contact.save
|
@contact.save
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue