Merge branch 'master' into registry-791

This commit is contained in:
Artur Beljajev 2018-08-21 12:08:45 +03:00
commit ffd389790c
74 changed files with 1646 additions and 137 deletions

View file

@ -0,0 +1,37 @@
require 'test_helper'
class ContactTest < ActiveSupport::TestCase
setup do
@contact = contacts(:john)
end
def test_valid_fixture
assert @contact.valid?
end
def test_invalid_without_email
@contact.email = ''
assert @contact.invalid?
end
def test_email_format_validation
@contact.email = 'invalid'
assert @contact.invalid?
@contact.email = 'test@bestmail.test'
assert @contact.valid?
end
def test_invalid_without_phone
@contact.email = ''
assert @contact.invalid?
end
def test_phone_format_validation
@contact.phone = '+123.'
assert @contact.invalid?
@contact.phone = '+123.4'
assert @contact.valid?
end
end

View file

@ -0,0 +1,59 @@
require 'test_helper'
class DepositTest < ActiveSupport::TestCase
def setup
super
@deposit = Deposit.new(registrar: registrars(:bestnames))
@minimum_deposit = Setting.minimum_deposit
Setting.minimum_deposit = 1.00
end
def teardown
super
Setting.minimum_deposit = @minimum_deposit
end
def test_validate_amount_cannot_be_lower_than_0_01
Setting.minimum_deposit = 0.0
@deposit.amount = -10
refute(@deposit.valid?)
assert(@deposit.errors.full_messages.include?("Amount is too small. Minimum deposit is 0.01 EUR"))
end
def test_validate_amount_cannot_be_lower_than_minimum_deposit
@deposit.amount = 0.10
refute(@deposit.valid?)
assert(@deposit.errors.full_messages.include?("Amount is too small. Minimum deposit is 1.0 EUR"))
end
def test_registrar_must_be_set
deposit = Deposit.new(amount: 120)
refute(deposit.valid?)
assert(deposit.errors.full_messages.include?("Registrar is missing"))
end
def test_amount_is_converted_from_string
@deposit.amount = "12.00"
assert_equal(BigDecimal.new("12.00"), @deposit.amount)
@deposit.amount = "12,11"
assert_equal(BigDecimal.new("12.11"), @deposit.amount)
end
def test_amount_is_converted_from_float
@deposit.amount = 12.0044
assert_equal(BigDecimal.new("12.0044"), @deposit.amount)
@deposit.amount = 12.0144
assert_equal(BigDecimal.new("12.0144"), @deposit.amount)
end
def test_amount_is_converted_from_nil
@deposit.amount = nil
assert_equal(BigDecimal.new("0.00"), @deposit.amount)
end
end

View file

@ -0,0 +1,62 @@
class RegistrantUserTest < ActiveSupport::TestCase
def setup
super
end
def teardown
super
end
def test_find_or_create_by_api_data_creates_a_user
user_data = {
ident: '37710100070',
first_name: 'JOHN',
last_name: 'SMITH'
}
RegistrantUser.find_or_create_by_api_data(user_data)
user = User.find_by(registrant_ident: 'EE-37710100070')
assert_equal('JOHN SMITH', user.username)
end
def test_find_or_create_by_api_data_creates_a_user_after_upcasing_input
user_data = {
ident: '37710100070',
first_name: 'John',
last_name: 'Smith'
}
RegistrantUser.find_or_create_by_api_data(user_data)
user = User.find_by(registrant_ident: 'EE-37710100070')
assert_equal('JOHN SMITH', user.username)
end
def test_find_or_create_by_mid_data_creates_a_user
user_data = OpenStruct.new(user_country: 'EE', user_id_code: '37710100070',
user_givenname: 'JOHN', user_surname: 'SMITH')
RegistrantUser.find_or_create_by_mid_data(user_data)
user = User.find_by(registrant_ident: 'EE-37710100070')
assert_equal('JOHN SMITH', user.username)
end
def test_find_or_create_by_idc_with_legacy_header_creates_a_user
header = '/C=EE/O=ESTEID/OU=authentication/CN=SMITH,JOHN,37710100070/SN=SMITH/GN=JOHN/serialNumber=37710100070'
RegistrantUser.find_or_create_by_idc_data(header, RegistrantUser::ACCEPTED_ISSUER)
user = User.find_by(registrant_ident: 'EE-37710100070')
assert_equal('JOHN SMITH', user.username)
end
def test_find_or_create_by_idc_with_rfc2253_header_creates_a_user
header = 'serialNumber=37710100070,GN=JOHN,SN=SMITH,CN=SMITH\\,JOHN\\,37710100070,OU=authentication,O=ESTEID,C=EE'
RegistrantUser.find_or_create_by_idc_data(header, RegistrantUser::ACCEPTED_ISSUER)
user = User.find_by(registrant_ident: 'EE-37710100070')
assert_equal('JOHN SMITH', user.username)
end
end