mirror of
https://github.com/internetee/registry.git
synced 2025-07-27 21:16:12 +02:00
- Add AgeValidation module for consistent age checks - Validate admin contacts must be at least 18 years old - Move age validation logic from Domain to shared module - Add tests for admin contact age validation - Fix JSON format for admin_contacts_allowed_ident_type setting This change ensures that administrative contacts must be adults (18+), using the same age validation logic as for registrants. The validation works with both birthday and Estonian ID formats. Settings are now properly stored as JSON strings for consistent parsing.
83 lines
No EOL
2.1 KiB
Ruby
83 lines
No EOL
2.1 KiB
Ruby
require 'test_helper'
|
|
|
|
class DomainContactTest < ActiveSupport::TestCase
|
|
setup do
|
|
@domain_contact = domain_contacts(:shop_jane)
|
|
end
|
|
|
|
def test_if_domain_contact_type_invalid
|
|
@domain_contact.update(type: "Some")
|
|
assert @domain_contact.name, ''
|
|
end
|
|
|
|
def test_value_typeahead
|
|
assert @domain_contact.value_typeahead, 'Jane'
|
|
end
|
|
|
|
def test_validates_admin_contact_age_with_birthday
|
|
admin_contact = contacts(:john)
|
|
admin_contact.update!(
|
|
ident_type: 'birthday',
|
|
ident: (Time.zone.now - 16.years).strftime('%Y-%m-%d')
|
|
)
|
|
|
|
domain_contact = AdminDomainContact.new(
|
|
domain: domains(:shop),
|
|
contact: admin_contact
|
|
)
|
|
|
|
assert_not domain_contact.valid?
|
|
assert_includes domain_contact.errors.full_messages,
|
|
'Contact Administrative contact must be at least 18 years old'
|
|
end
|
|
|
|
def test_validates_admin_contact_age_with_estonian_id
|
|
admin_contact = contacts(:john)
|
|
admin_contact.update!(
|
|
ident_type: 'priv',
|
|
ident: '61203150222',
|
|
ident_country_code: 'EE'
|
|
)
|
|
|
|
domain_contact = AdminDomainContact.new(
|
|
domain: domains(:shop),
|
|
contact: admin_contact
|
|
)
|
|
|
|
assert_not domain_contact.valid?
|
|
assert_includes domain_contact.errors.full_messages,
|
|
'Contact Administrative contact must be at least 18 years old'
|
|
end
|
|
|
|
def test_allows_adult_admin_contact_with_birthday
|
|
admin_contact = contacts(:john)
|
|
admin_contact.update!(
|
|
ident_type: 'birthday',
|
|
ident: (Time.zone.now - 20.years).strftime('%Y-%m-%d')
|
|
)
|
|
|
|
domain_contact = AdminDomainContact.new(
|
|
domain: domains(:shop),
|
|
contact: admin_contact
|
|
)
|
|
|
|
assert domain_contact.valid?
|
|
end
|
|
|
|
def test_allows_adult_admin_contact_with_estonian_id
|
|
admin_contact = contacts(:john)
|
|
admin_contact.update!(
|
|
ident_type: 'priv',
|
|
ident: '38903111310',
|
|
ident_country_code: 'EE'
|
|
)
|
|
|
|
domain_contact = AdminDomainContact.new(
|
|
domain: domains(:shop),
|
|
contact: admin_contact
|
|
)
|
|
|
|
assert domain_contact.valid?
|
|
end
|
|
|
|
end |