mirror of
https://github.com/internetee/registry.git
synced 2025-07-29 14:06:21 +02:00
feat: add age validation for admin contacts
- 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.
This commit is contained in:
parent
66619f12fe
commit
7799727867
10 changed files with 181 additions and 51 deletions
|
@ -14,4 +14,70 @@ class DomainContactTest < ActiveSupport::TestCase
|
|||
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
|
Loading…
Add table
Add a link
Reference in a new issue