mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 17:37:17 +02:00
130 lines
3.5 KiB
Ruby
130 lines
3.5 KiB
Ruby
require 'rails_helper'
|
|
|
|
describe Contact do
|
|
it { should have_one(:address) }
|
|
|
|
context 'with invalid attribute' do
|
|
before(:each) { @contact = Fabricate(:contact) }
|
|
|
|
it 'phone should return false' do
|
|
@contact.phone = '32341'
|
|
expect(@contact.valid?).to be false
|
|
end
|
|
|
|
it 'ident should return false' do
|
|
@contact.ident = '123abc'
|
|
expect(@contact.valid?).to be false
|
|
end
|
|
|
|
it 'should return missing parameter error messages' do
|
|
@contact = Contact.new
|
|
expect(@contact.valid?).to eq false
|
|
|
|
expect(@contact.errors.messages).to match_array({
|
|
code: ['Required parameter missing - code'],
|
|
phone: ['Required parameter missing - phone', 'Phone nr is invalid'],
|
|
email: ['Required parameter missing - email', 'Email is invalid'],
|
|
ident: ['Required parameter missing - ident'],
|
|
address: ['is missing'],
|
|
registrar: ['is missing']
|
|
})
|
|
end
|
|
end
|
|
|
|
context 'with valid attributes' do
|
|
before(:each) { @contact = Fabricate(:contact) }
|
|
|
|
it 'should return true' do
|
|
expect(@contact.valid?).to be true
|
|
end
|
|
end
|
|
end
|
|
|
|
describe Contact, '#relations_with_domain?' do
|
|
context 'with no relation' do
|
|
before(:each) { Fabricate(:contact) }
|
|
it 'should return false' do
|
|
expect(Contact.first.relations_with_domain?).to be false
|
|
end
|
|
end
|
|
|
|
context 'with relation' do
|
|
before(:each) do
|
|
Fabricate(:domain_validation_setting_group)
|
|
Fabricate(:domain)
|
|
end
|
|
|
|
it 'should return true' do
|
|
expect(Contact.first.relations_with_domain?).to be true
|
|
end
|
|
end
|
|
end
|
|
|
|
describe Contact, '#cr_id' do
|
|
before(:each) { Fabricate(:contact, code: 'asd12', created_by: Fabricate(:epp_user)) }
|
|
|
|
it 'should return username of creator' do
|
|
expect(Contact.first.cr_id).to eq('gitlab')
|
|
end
|
|
|
|
it 'should return nil when no creator' do
|
|
expect(Contact.new.cr_id).to be nil
|
|
end
|
|
end
|
|
|
|
describe Contact, '#up_id' do
|
|
before(:each) do
|
|
#Fabricate(:contact, code: 'asd12', created_by: Fabricate(:epp_user), updated_by: Fabricate(:epp_user), registrar: zone)
|
|
@epp_user = Fabricate(:epp_user)
|
|
@contact = Fabricate.build(:contact, code: 'asd12', created_by: @epp_user, updated_by: @epp_user)
|
|
end
|
|
|
|
it 'should return username of updater' do
|
|
expect(@contact.up_id).to eq('gitlab')
|
|
end
|
|
|
|
it 'should return nil when no updater' do
|
|
expect(Contact.new.up_id).to be nil
|
|
end
|
|
end
|
|
|
|
describe Contact, '.extract_params' do
|
|
it 'returns params hash'do
|
|
ph = { id: '123123', email: 'jdoe@example.com', authInfo: { pw: 'asde' },
|
|
postalInfo: { name: 'fred', addr: { cc: 'EE' } } }
|
|
expect(Contact.extract_attributes(ph)).to eq({
|
|
name: 'fred',
|
|
email: 'jdoe@example.com',
|
|
auth_info: 'asde'
|
|
})
|
|
end
|
|
end
|
|
|
|
describe Contact, '.check_availability' do
|
|
|
|
before(:each) do
|
|
Fabricate(:contact, code: 'asd12')
|
|
Fabricate(:contact, code: 'asd13')
|
|
end
|
|
|
|
it 'should return array if argument is string' do
|
|
response = Contact.check_availability('asd12')
|
|
expect(response.class).to be Array
|
|
expect(response.length).to eq(1)
|
|
end
|
|
|
|
it 'should return in_use and available codes' do
|
|
response = Contact.check_availability(%w(asd12 asd13 asd14))
|
|
expect(response.class).to be Array
|
|
expect(response.length).to eq(3)
|
|
|
|
expect(response[0][:avail]).to eq(0)
|
|
expect(response[0][:code]).to eq('asd12')
|
|
|
|
expect(response[1][:avail]).to eq(0)
|
|
expect(response[1][:code]).to eq('asd13')
|
|
|
|
expect(response[2][:avail]).to eq(1)
|
|
expect(response[2][:code]).to eq('asd14')
|
|
end
|
|
end
|