Add Registrant API contact update action

Closes #849
This commit is contained in:
Artur Beljajev 2018-08-20 17:19:54 +03:00
parent 90ed23f64d
commit b6ecae6a35
41 changed files with 1239 additions and 61 deletions

View file

@ -0,0 +1,20 @@
require 'test_helper'
class ActionTest < ActiveSupport::TestCase
setup do
@action = actions(:contact_update)
end
def test_fixture_is_valid
assert @action.valid?
end
def test_invalid_with_unsupported_operation
@action.operation = 'invalid'
assert @action.invalid?
end
def test_notification_key_for_contact
assert_equal :contact_update, @action.notification_key
end
end

View file

@ -0,0 +1,16 @@
require 'test_helper'
class ContactAddressTest < ActiveSupport::TestCase
setup do
@address = Contact::Address.new('Main Street', '1234', 'NY City', 'NY State', 'US')
end
def test_equal_when_all_parts_are_the_same
assert_equal @address, Contact::Address.new('Main Street', '1234', 'NY City', 'NY State', 'US')
end
def test_not_equal_when_some_part_is_different
assert_not_equal @address, Contact::Address.new('Main Street', '1234', 'NY City', 'NY State',
'DE')
end
end

View file

@ -26,4 +26,16 @@ class ContactTest < ActiveSupport::TestCase
def test_not_in_use_if_acts_as_neither_registrant_nor_domain_contact
refute contacts(:not_in_use).in_use?
end
def test_managed_when_identity_codes_match
contact = Contact.new(ident: '1234')
user = RegistrantUser.new(registrant_ident: 'US-1234')
assert contact.managed_by?(user)
end
def test_unmanaged_when_identity_codes_do_not_match
contact = Contact.new(ident: '1234')
user = RegistrantUser.new(registrant_ident: 'US-12345')
assert_not contact.managed_by?(user)
end
end

View file

@ -21,4 +21,13 @@ class ContactPostalAddressTest < ActiveSupport::TestCase
@contact.country_code = 'invalid'
assert @contact.valid?
end
def test_state_is_optional_when_address_is_enabled
Setting.address_processing = true
contact = contacts(:william)
assert contact.valid?
contact.state = ''
assert contact.valid?
end
end

View file

@ -34,4 +34,18 @@ class ContactTest < ActiveSupport::TestCase
@contact.phone = '+123.4'
assert @contact.valid?
end
def test_address
address = Contact::Address.new('new street', '83746', 'new city', 'new state', 'EE')
@contact.address = address
@contact.save!
@contact.reload
assert_equal 'new street', @contact.street
assert_equal '83746', @contact.zip
assert_equal 'new city', @contact.city
assert_equal 'new state', @contact.state
assert_equal 'EE', @contact.country_code
assert_equal address, @contact.address
end
end

View file

@ -35,4 +35,14 @@ class RegistrantUserTest < ActiveSupport::TestCase
assert_equal('1234', @user.ident)
assert_equal('US', @user.country_code)
end
def test_first_name_from_username
user = RegistrantUser.new(username: 'John Doe')
assert_equal 'John', user.first_name
end
def test_last_name_from_username
user = RegistrantUser.new(username: 'John Doe')
assert_equal 'Doe', user.last_name
end
end