Resolve merge errors

This commit is contained in:
Karl Erik Õunapuu 2020-09-02 16:25:34 +03:00
commit 73e9dd6870
817 changed files with 16875 additions and 17443 deletions

View file

@ -0,0 +1,142 @@
require 'test_helper'
class AdminUserTest < ActiveSupport::TestCase
def test_valid_user_fixture_is_valid
assert valid_user.valid?, proc { valid_user.errors.full_messages }
end
def test_invalid_without_username
user = valid_user
user.username = ''
assert user.invalid?
end
def test_invalid_without_password_and_password_confirmation_when_creating
user = valid_non_persisted_user
user.password = ''
user.password_confirmation = ''
assert user.invalid?
user.password = valid_password
user.password_confirmation = user.password
assert user.valid?
end
def test_validates_password_format
user = valid_non_persisted_user
user.password = 'a' * (Devise.password_length.min.pred)
user.password_confirmation = user.password
assert user.invalid?
user.password = 'a' * (Devise.password_length.max.next)
user.password_confirmation = user.password
assert user.invalid?
user.password = 'a' * Devise.password_length.min
user.password_confirmation = user.password
assert user.valid?
user.password = 'a' * Devise.password_length.max
user.password_confirmation = user.password
assert user.valid?
end
def test_requires_password_confirmation
user = valid_non_persisted_user
user.password = valid_password
user.password_confirmation = ''
assert user.invalid?
user.password_confirmation = 'another'
assert user.invalid?
user.password_confirmation = user.password
assert user.valid?, proc { user.errors.full_messages }
end
def test_invalid_without_email
user = valid_user
user.email = ''
assert user.invalid?
end
def test_validates_email_format
user = valid_user
user.email = 'invalid'
assert user.invalid?
user.email = 'valid@registry.test'
assert user.valid?
end
def test_invalid_when_email_is_already_taken
another_user = valid_user
user = valid_non_persisted_user
user.email = another_user.email
assert user.invalid?
user.email = 'new-user@registry.test'
assert user.valid?, proc { user.errors.full_messages }
end
def test_invalid_without_country_code
user = valid_user
user.country_code = ''
assert user.invalid?
end
def test_invalid_without_roles
user = valid_user
user.roles = []
assert user.invalid?
end
def test_valid_without_identity_code
user = valid_user
user.identity_code = ''
assert user.valid?
end
def test_invalid_without_identity_code_when_country_code_is_estonia
user = valid_user
user.country_code = 'EE'
user.identity_code = ''
assert user.invalid?
end
# https://en.wikipedia.org/wiki/National_identification_number#Estonia
def test_validates_identity_code_format_when_country_code_is_estonia
user = valid_user
user.country_code = 'EE'
user.identity_code = '47101010030'
assert user.invalid?
user.identity_code = '47101010033'
assert user.valid?
end
private
def valid_user
users(:admin)
end
def valid_non_persisted_user
user = valid_user.dup
user.password = user.password_confirmation = valid_password
user.email = 'another@registry.test'
user
end
def valid_password
'a' * Devise.password_length.min
end
end

View file

@ -5,6 +5,53 @@ class ApiUserTest < ActiveSupport::TestCase
@user = users(:api_bestnames)
end
def test_valid_user_fixture_is_valid
assert valid_user.valid?, proc { valid_user.errors.full_messages }
end
def test_invalid_without_username
user = valid_user
user.username = ''
assert user.invalid?
end
def test_invalid_when_username_is_already_taken
user = valid_user
another_user = user.dup
assert another_user.invalid?
another_user.username = 'another'
assert another_user.valid?
end
def test_invalid_without_password
user = valid_user
user.plain_text_password = ''
assert user.invalid?
end
def test_validates_password_format
user = valid_user
min_length = ApiUser.min_password_length
user.plain_text_password = 'a' * (min_length.pred)
assert user.invalid?
user.plain_text_password = 'a' * min_length
assert user.valid?
end
def test_invalid_without_roles
user = valid_user
user.roles = []
assert user.invalid?
end
def test_active_by_default
assert ApiUser.new.active?
end
def test_finds_user_by_id_card
id_card = IdCard.new
id_card.personal_code = 'one'
@ -15,4 +62,29 @@ class ApiUserTest < ActiveSupport::TestCase
@user.update!(identity_code: 'another')
assert_nil ApiUser.find_by_id_card(id_card)
end
end
def test_verifies_pki_status
certificate = certificates(:api)
assert @user.pki_ok?(certificate.crt, certificate.common_name, api: true)
assert_not @user.pki_ok?(certificate.crt, 'invalid-cn', api: true)
certificate = certificates(:registrar)
assert @user.pki_ok?(certificate.crt, certificate.common_name, api: false)
assert_not @user.pki_ok?(certificate.crt, 'invalid-cn', api: false)
certificate.update(revoked: true)
assert_not @user.pki_ok?(certificate.crt, certificate.common_name, api: false)
certificate = certificates(:api)
certificate.update(revoked: true)
assert_not @user.pki_ok?(certificate.crt, certificate.common_name, api: true)
end
private
def valid_user
users(:api_bestnames)
end
end

View file

@ -6,9 +6,93 @@ class BankTransactionTest < ActiveSupport::TestCase
@invoice = invoices(:one)
end
def test_matches_against_invoice_number_and_reference_number
create_payable_invoice(number: '2222', total: 10, reference_no: '1111')
transaction = BankTransaction.new(description: 'invoice #2222', sum: 10, reference_no: '1111')
def test_matches_against_invoice_nubmber_and_reference_number
create_payable_invoice(number: '2222', total: 10, reference_no: '1234567')
transaction = BankTransaction.new(description: 'invoice #2222', sum: 10, reference_no: '1234567')
assert_difference 'AccountActivity.count' do
transaction.autobind_invoice
end
end
def test_binds_if_this_sum_invoice_already_present
create_payable_invoice(number: '2222', total: 10, reference_no: '1234567')
another_invoice = @invoice.dup
another_invoice.save(validate: false)
another_invoice.update(reference_no: '7654321', number: '2221')
another_item = @invoice.items.first.dup
another_item.invoice = another_invoice
another_item.save
another_invoice.reload
first_transaction = BankTransaction.new(description: 'invoice #2221',
sum: 10,
description: 'Order nr 1 from registrar 1234567 second number 2345678')
first_transaction.create_activity(another_invoice.buyer, another_invoice)
transaction = BankTransaction.new(description: 'invoice #2222',
sum: 10,
description: 'Order nr 1 from registrar 1234567 second number 2345678')
assert_difference 'AccountActivity.count' do
transaction.autobind_invoice
end
end
def test_binds_if_this_sum_cancelled_invoice_already_present
create_payable_invoice(number: '2222', total: 10, reference_no: '1234567')
another_invoice = @invoice.dup
another_invoice.save(validate: false)
another_item = @invoice.items.first.dup
another_item.invoice = another_invoice
another_item.save
another_invoice.reload
another_invoice.update(reference_no: '1234567', number: '2221', cancelled_at: Time.zone.now)
transaction = BankTransaction.new(description: 'invoice #2222',
sum: 10,
description: 'Order nr 1 from registrar 1234567 second number 2345678')
assert_difference 'AccountActivity.count' do
transaction.autobind_invoice
end
end
def test_marks_the_first_one_as_paid_if_same_sum
create_payable_invoice(number: '2222', total: 10, reference_no: '1234567')
another_invoice = @invoice.dup
another_invoice.save(validate: false)
another_invoice.update(reference_no: '7654321', number: '2221')
another_item = @invoice.items.first.dup
another_item.invoice = another_invoice
another_item.save
another_invoice.reload
transaction = BankTransaction.new(description: 'invoice #2222',
sum: 10,
description: 'Order nr 1 from registrar 1234567 second number 2345678')
assert_difference 'AccountActivity.count' do
transaction.autobind_invoice
end
@invoice.reload
another_invoice.reload
assert(@invoice.paid?)
assert_not(another_invoice.paid?)
end
def test_matches_against_invoice_nubmber_and_reference_number_in_description
create_payable_invoice(number: '2222', total: 10, reference_no: '1234567')
transaction = BankTransaction.new(description: 'invoice #2222',
sum: 10,
description: 'Order nr 1 from registrar 1234567 second number 2345678')
assert_difference 'AccountActivity.count' do
transaction.autobind_invoice

View file

@ -0,0 +1,106 @@
require 'test_helper'
class Billing::PriceTest < ActiveSupport::TestCase
setup do
@user = users(:api_bestnames)
end
def test_valid_price_fixture_is_valid
assert valid_price.valid?, proc { valid_price.errors.full_messages }
end
def test_invalid_without_price
price = valid_price
price.price = ''
assert price.invalid?
end
def test_validates_price_format
price = valid_price
price.price = -1
assert price.invalid?
price.price = 0
assert price.valid?, proc { price.errors.full_messages }
price.price = "1#{I18n.t('number.currency.format.separator')}1"
assert price.valid?
price.price = 1
assert price.valid?
end
def test_invalid_without_effective_date
price = valid_price
price.valid_from = ''
assert price.invalid?
end
def test_invalid_without_operation_category
price = valid_price
price.operation_category = ''
assert price.invalid?
end
def test_validates_operation_category_format
price = valid_price
price.operation_category = 'invalid'
assert price.invalid?
price.operation_category = Billing::Price.operation_categories.first
assert price.valid?
end
def test_invalid_without_duration
price = valid_price
price.duration = ''
assert price.invalid?
end
def test_validates_duration_format
price = valid_price
price.duration = 'invalid'
assert price.invalid?
price.duration = Billing::Price.durations.first
assert price.valid?
end
def test_returns_operation_categories
operation_categories = %w[create renew]
assert_equal operation_categories, Billing::Price.operation_categories
end
def test_returns_durations
durations = [
'3 mons',
'6 mons',
'9 mons',
'1 year',
'2 years',
'3 years',
'4 years',
'5 years',
'6 years',
'7 years',
'8 years',
'9 years',
'10 years',
]
assert_equal durations, Billing::Price.durations
end
def test_returns_statuses
statuses = %w[upcoming effective expired]
assert_equal statuses, Billing::Price.statuses
end
private
def valid_price
billing_prices(:create_one_month)
end
end

View file

@ -0,0 +1,28 @@
require 'test_helper'
class VersionsTest < ActiveSupport::TestCase
def test_if_gets_all_versions_without_error_if_ignored_column_present
@nameserver = nameservers(:shop_ns1)
@nameserver.update(hostname: 'ns99.bestnames.test')
@ignored_column_title = Nameserver.ignored_columns.first
version = NameserverVersion.last
hash = version.object
hash[@ignored_column_title] = 123456
version.update(object: hash)
assert_nothing_raised do
Nameserver.all_versions_for([@nameserver.id], Time.zone.now)
end
end
def test_if_gets_all_versions_without_error_if_no_ignored_column
@account = accounts(:cash)
@account.update(currency: 'USD')
assert_nothing_raised do
Account.all_versions_for([@account.id], Time.zone.now)
end
end
end

View file

@ -28,7 +28,7 @@ class ContactDisclosableTest < ActiveSupport::TestCase
@contact.disclosed_attributes = %w[some undisclosable]
assert @contact.invalid?
assert_includes @contact.errors.get(:disclosed_attributes), 'contain unsupported attribute(s)'
assert_includes @contact.errors[:disclosed_attributes], 'contain unsupported attribute(s)'
end
def test_valid_when_attribute_is_disclosable

View file

@ -0,0 +1,128 @@
require 'test_helper'
class ContactIdentTest < ActiveSupport::TestCase
def test_valid_ident_is_valid
assert valid_ident.valid?, proc { valid_ident.errors.full_messages }
end
def test_invalid_without_code
ident = valid_ident
ident.code = ''
assert ident.invalid?
end
def test_validates_date_of_birth
ident = valid_ident
ident.type = 'birthday'
ident.code = '2010-07-05'
assert ident.valid?
ident.code = '2010-07-0'
assert ident.invalid?
end
# https://en.wikipedia.org/wiki/National_identification_number#Estonia
def test_country_specific_national_id_format_validation
country = Country.new('EE')
ident = valid_ident
ident.type = 'priv'
ident.country_code = country.alpha2
ident.code = 'invalid'
assert ident.invalid?
assert_includes ident.errors.full_messages, "Code does not conform to national identification number format of #{country}"
ident.code = '47101010033'
assert ident.valid?
ident.country_code = 'US'
ident.code = 'any'
assert ident.valid?
end
def test_country_specific_company_registration_number_format_validation
country = Country.new('EE')
ident = valid_ident
ident.type = 'org'
ident.country_code = country.alpha2
allowed_length = 8
ident.code = '1' * allowed_length.pred
assert ident.invalid?
assert_includes ident.errors.full_messages, "Code does not conform to registration number format of #{country}"
ident.code = '1' * allowed_length.next
assert ident.invalid?
ident.code = '1' * allowed_length
assert ident.valid?
ident.country_code = 'US'
ident.code = 'any'
assert ident.valid?
end
def test_invalid_without_type
ident = valid_ident
ident.type = ''
assert ident.invalid?
end
def test_validates_type
assert_not_includes Contact::Ident.types, 'invalid'
ident = valid_ident
ident.type = 'invalid'
assert ident.invalid?
end
def test_invalid_without_country_code
ident = valid_ident
ident.country_code = ''
assert ident.invalid?
end
def test_validates_country_code_format
ident = valid_ident
ident.country_code = 'invalid'
assert ident.invalid?
ident.country_code = 'US'
assert ident.valid?
end
def test_validates_for_mismatches
ident = valid_ident
mismatch = Contact::Ident::MismatchValidator.mismatches.first
ident.type = mismatch.type
ident.country_code = mismatch.country.alpha2
assert ident.invalid?
assert_includes ident.errors.full_messages, %(Ident type "#{ident.type}" is invalid for #{ident.country})
end
def test_returns_types
assert_equal %w[org priv birthday], Contact::Ident.types
end
def test_returns_country
country_code = 'US'
ident = Contact::Ident.new(country_code: country_code)
assert_equal Country.new(country_code), ident.country
end
def test_equality
assert_equal Contact::Ident.new(code: 'code', type: 'type', country_code: 'US'),
Contact::Ident.new(code: 'code', type: 'type', country_code: 'US')
assert_not_equal Contact::Ident.new(code: 'code', type: 'type', country_code: 'US'),
Contact::Ident.new(code: 'code', type: 'type', country_code: 'GB')
end
private
def valid_ident
Contact::Ident.new(code: '1234', type: 'priv', country_code: 'US')
end
end

View file

@ -3,10 +3,15 @@ require 'test_helper'
class ContactTest < ActiveSupport::TestCase
setup do
@contact = contacts(:john)
@old_validation_type = Truemail.configure.default_validation_type
end
def test_valid_fixture_is_valid
assert @contact.valid?, proc { @contact.errors.full_messages }
teardown do
Truemail.configure.default_validation_type = @old_validation_type
end
def test_valid_contact_fixture_is_valid
assert valid_contact.valid?, proc { valid_contact.errors.full_messages }
end
def test_invalid_fixture_is_invalid
@ -21,33 +26,134 @@ class ContactTest < ActiveSupport::TestCase
assert_equal 'org', Contact::ORG
end
def test_invalid_without_email
@contact.email = ''
assert @contact.invalid?
def test_invalid_without_name
contact = valid_contact
contact.name = ''
assert contact.invalid?
end
def test_email_format_validation
@contact.email = 'invalid'
assert @contact.invalid?
def test_validates_code_format
contact = valid_contact.dup
max_length = 100
@contact.email = 'test@bestmail.test'
assert @contact.valid?
contact.code = '!invalid'
assert contact.invalid?
contact.code = 'a' * max_length.next
assert contact.invalid?
contact.code = 'foo:bar'
assert contact.valid?
contact.code = 'a' * max_length
assert contact.valid?
end
def test_invalid_when_code_is_already_taken
another_contact = valid_contact
contact = another_contact.dup
contact.code = another_contact.code
assert contact.invalid?
contact.regenerate_code
assert contact.valid?
end
def test_invalid_without_email
contact = valid_contact
contact.email = ''
assert contact.invalid?
end
def test_email_verification_valid
contact = valid_contact
contact.email = 'info@internet.ee'
assert contact.valid?
end
def test_email_verification_smtp_error
Truemail.configure.default_validation_type = :smtp
contact = valid_contact
contact.email = 'somecrude1337joke@internet.ee'
assert contact.invalid?
assert_equal I18n.t('activerecord.errors.models.contact.attributes.email.email_smtp_check_error'), contact.errors.messages[:email].first
end
def test_email_verification_mx_error
Truemail.configure.default_validation_type = :mx
contact = valid_contact
contact.email = 'somecrude31337joke@somestrange31337domain.ee'
assert contact.invalid?
assert_equal I18n.t('activerecord.errors.models.contact.attributes.email.email_mx_check_error'), contact.errors.messages[:email].first
end
def test_email_verification_regex_error
Truemail.configure.default_validation_type = :regex
contact = valid_contact
contact.email = 'some@strangesentence@internet.ee'
assert contact.invalid?
assert_equal I18n.t('activerecord.errors.models.contact.attributes.email.email_regex_check_error'), contact.errors.messages[:email].first
end
def test_invalid_without_phone
@contact.email = ''
assert @contact.invalid?
contact = valid_contact
contact.phone = ''
assert contact.invalid?
end
def test_phone_format_validation
@contact.phone = '+123.'
assert @contact.invalid?
# https://en.wikipedia.org/wiki/E.164
def test_validates_phone_format
contact = valid_contact
@contact.phone = '+123.4'
assert @contact.valid?
contact.phone = '+.1'
assert contact.invalid?
contact.phone = '+123.'
assert contact.invalid?
contact.phone = '+1.123456789123456'
assert contact.invalid?
contact.phone = '+134.1234567891234'
assert contact.invalid?
contact.phone = '+000.1'
assert contact.invalid?
contact.phone = '+123.0'
assert contact.invalid?
contact.phone = '+1.2'
assert contact.valid?
contact.phone = '+123.4'
assert contact.valid?
contact.phone = '+1.12345678912345'
assert contact.valid?
contact.phone = '+134.123456789123'
assert contact.valid?
end
def test_valid_without_address_when_address_processing_id_disabled
contact = valid_contact
contact.street = ''
contact.city = ''
contact.zip = ''
contact.country_code = ''
assert contact.valid?
end
def test_address
Setting.address_processing = true
address = Contact::Address.new('new street', '83746', 'new city', 'new state', 'EE')
@contact.address = address
@contact.save!
@ -74,13 +180,12 @@ class ContactTest < ActiveSupport::TestCase
end
def test_returns_registrant_user_indirect_contacts
@contact.update!(ident_type: Contact::ORG)
assert_equal '1234', @contact.ident
@contact.update!(ident_type: Contact::ORG, ident: '1234321')
assert_equal 'US', @contact.ident_country_code
registrant_user = RegistrantUser.new(registrant_ident: 'US-1234')
registrant_user = RegistrantUser.new(registrant_ident: 'US-1234321')
registrant_user.stub(:companies, [OpenStruct.new(registration_number: '1234')]) do
assert_equal [@contact], Contact.registrant_user_contacts(registrant_user)
registrant_user.stub(:companies, [OpenStruct.new(registration_number: '1234321')]) do
assert_equal registrant_user.contacts, Contact.registrant_user_contacts(registrant_user)
end
end
@ -93,15 +198,15 @@ class ContactTest < ActiveSupport::TestCase
end
def test_linked_when_in_use_as_registrant
Domain.update_all(registrant_id: @contact)
Domain.update_all(registrant_id: @contact.id)
DomainContact.delete_all
assert @contact.linked?
end
def test_linked_when_in_use_as_domain_contact
Domain.update_all(registrant_id: contacts(:william))
DomainContact.update_all(contact_id: @contact)
Domain.update_all(registrant_id: contacts(:william).id)
DomainContact.first.update(contact_id: @contact.id)
assert @contact.linked?
end
@ -179,21 +284,83 @@ class ContactTest < ActiveSupport::TestCase
assert Contact.unlinked.exclude?(contact), 'Contact should be excluded'
end
def test_normalizes_country_code
Setting.address_processing = true
contact = Contact.new(country_code: 'us')
contact.validate
assert_equal 'US', contact.country_code
end
def test_normalizes_ident_country_code
contact = Contact.new(ident_country_code: 'us')
contact.validate
assert_equal 'US', contact.ident_country_code
end
def test_generates_code
contact = Contact.new(registrar: registrars(:bestnames))
assert_nil contact.code
contact.generate_code
assert_not_empty contact.code
end
def test_prohibits_code_change
assert_no_changes -> { @contact.code } do
@contact.code = 'new'
@contact.save!
@contact.reload
end
end
def test_removes_duplicate_statuses
contact = Contact.new(statuses: %w[ok ok])
assert_equal %w[ok], contact.statuses
end
def test_default_status
contact = Contact.new
assert_equal %w[ok], contact.statuses
end
def test_whois_gets_updated_after_contact_save
@contact.name = 'SomeReallyWeirdRandomTestName'
domain = @contact.registrant_domains.first
@contact.save!
assert_equal domain.whois_record.try(:json).try(:[], 'registrant'), @contact.name
end
def test_creates_email_verification_in_unicode
unicode_email = 'suur@äri.ee'
punycode_email = Contact.unicode_to_punycode(unicode_email)
@contact.email = punycode_email
@contact.save
assert_equal @contact.email_verification.email, unicode_email
end
private
def make_contact_free_of_domains_where_it_acts_as_a_registrant(contact)
other_contact = contacts(:william)
assert_not_equal other_contact, contact
Domain.update_all(registrant_id: other_contact)
Domain.update_all(registrant_id: other_contact.id)
end
def unlinked_contact
other_contact = contacts(:william)
assert_not_equal @contact, other_contact
Domain.update_all(registrant_id: other_contact)
Domain.update_all(registrant_id: other_contact.id)
DomainContact.delete_all
@contact
end
end
def valid_contact
contacts(:john)
end
end

View file

@ -5,14 +5,12 @@ class DepositTest < ActiveSupport::TestCase
super
@deposit = Deposit.new(registrar: registrars(:bestnames))
@minimum_deposit = Setting.minimum_deposit
@original_minimum_deposit = Setting.minimum_deposit
Setting.minimum_deposit = 1.00
end
def teardown
super
Setting.minimum_deposit = @minimum_deposit
teardown do
Setting.minimum_deposit = @original_minimum_deposit
end
def test_validate_amount_cannot_be_lower_than_0_01
@ -38,22 +36,22 @@ class DepositTest < ActiveSupport::TestCase
def test_amount_is_converted_from_string
@deposit.amount = "12.00"
assert_equal(BigDecimal.new("12.00"), @deposit.amount)
assert_equal(BigDecimal("12.00"), @deposit.amount)
@deposit.amount = "12,11"
assert_equal(BigDecimal.new("12.11"), @deposit.amount)
assert_equal(BigDecimal("12.11"), @deposit.amount)
end
def test_amount_is_converted_from_float
@deposit.amount = 12.0044
assert_equal(BigDecimal.new("12.0044"), @deposit.amount)
assert_equal(BigDecimal("12.0044"), @deposit.amount)
@deposit.amount = 12.0144
assert_equal(BigDecimal.new("12.0144"), @deposit.amount)
assert_equal(BigDecimal("12.0144"), @deposit.amount)
end
def test_amount_is_converted_from_nil
@deposit.amount = nil
assert_equal(BigDecimal.new("0.00"), @deposit.amount)
assert_equal(BigDecimal("0.00"), @deposit.amount)
end
end

View file

@ -0,0 +1,4 @@
require 'test_helper'
class DirectoTest < ActiveSupport::TestCase
end

View file

@ -0,0 +1,52 @@
require 'test_helper'
class DisputedDomainTest < ActiveSupport::TestCase
setup do
@dispute = disputes(:active)
end
def test_fixture_is_valid
assert @dispute.valid?
end
def test_can_be_closed_by_domain_name
travel_to Time.zone.parse('2010-10-05')
Dispute.close_by_domain(@dispute.domain_name)
@dispute.reload
assert @dispute.closed
end
def test_syncs_password_to_reserved
dispute = Dispute.new(domain_name: 'reserved.test', starts_at: Time.zone.today, password: 'disputepw')
dispute.save
dispute.reload
assert_equal dispute.password, ReservedDomain.find_by(name: dispute.domain_name).password
end
def test_domain_name_zone_is_validated
dispute = Dispute.new(domain_name: 'correct.test', starts_at: Time.zone.today)
assert dispute.valid?
dispute.domain_name = 'zone.is.unrecognized.test'
assert_not dispute.valid?
end
def test_dispute_can_not_be_created_if_another_active_is_present
dispute = Dispute.new(domain_name: @dispute.domain_name,
starts_at: @dispute.starts_at + 1.day)
assert_not dispute.valid?
end
def test_expires_at_date_is_appended_automatically
dispute = Dispute.new(domain_name: 'random.test', starts_at: Time.zone.today)
assert dispute.valid?
assert_equal dispute.expires_at, dispute.starts_at + 3.years
end
def test_starts_at_must_be_present
dispute = Dispute.new(domain_name: 'random.test')
assert_not dispute.valid?
end
end

View file

@ -13,6 +13,8 @@ class AuctionDoubleTest < ActiveSupport::TestCase
end
class DNS::DomainNameTest < ActiveSupport::TestCase
fixtures 'whois/records'
def test_available_when_not_at_auction
domain_name = DNS::DomainName.new('auction.test')
auctions(:one).update!(domain: 'auction.test', status: Auction.statuses[:domain_registered])
@ -131,7 +133,10 @@ class DNS::DomainNameTest < ActiveSupport::TestCase
def test_blocked
assert_equal 'blocked.test', blocked_domains(:one).name
assert_equal 'blockedäöüõ.test', blocked_domains(:idn).name
assert DNS::DomainName.new('blocked.test').blocked?
assert DNS::DomainName.new('blockedäöüõ.test').blocked?
assert DNS::DomainName.new(SimpleIDN.to_ascii('blockedäöüõ.test')).blocked?
assert_not DNS::DomainName.new('nonblocked .test').blocked?
end

View file

@ -0,0 +1,186 @@
require 'test_helper'
class DNS::ZoneTest < ActiveSupport::TestCase
def test_valid_zone_fixture_is_valid
assert valid_zone.valid?, proc { valid_zone.errors.full_messages }
end
def test_invalid_without_origin
zone = valid_zone
zone.origin = ''
assert zone.invalid?
end
def test_invalid_when_origin_is_already_taken
zone = valid_zone
another_zone = zone.dup
assert another_zone.invalid?
end
def test_invalid_without_ttl
zone = valid_zone
zone.ttl = ''
assert zone.invalid?
end
def test_validates_ttl_format
zone = valid_zone
zone.ttl = 'text'
assert zone.invalid?
zone.ttl = '1.1'
assert zone.invalid?
zone.ttl = '1'
assert zone.valid?
end
def test_invalid_without_refresh
zone = valid_zone
zone.refresh = ''
assert zone.invalid?
end
def test_validates_refresh_format
zone = valid_zone
zone.refresh = 'text'
assert zone.invalid?
zone.refresh = '1.1'
assert zone.invalid?
zone.refresh = '1'
assert zone.valid?
end
def test_invalid_without_retry
zone = valid_zone
zone.retry = ''
assert zone.invalid?
end
def test_validates_retry_format
zone = valid_zone
zone.retry = 'text'
assert zone.invalid?
zone.retry = '1.1'
assert zone.invalid?
zone.retry = '1'
assert zone.valid?
end
def test_invalid_without_expire
zone = valid_zone
zone.expire = ''
assert zone.invalid?
end
def test_validates_expire_format
zone = valid_zone
zone.expire = 'text'
assert zone.invalid?
zone.expire = '1.1'
assert zone.invalid?
zone.expire = '1'
assert zone.valid?
end
def test_invalid_without_minimum_ttl
zone = valid_zone
zone.minimum_ttl = ''
assert zone.invalid?
end
def test_validates_minimum_ttl_format
zone = valid_zone
zone.minimum_ttl = 'text'
assert zone.invalid?
zone.minimum_ttl = '1.1'
assert zone.invalid?
zone.minimum_ttl = '1'
assert zone.valid?
end
def test_invalid_without_email
zone = valid_zone
zone.email = ''
assert zone.invalid?
end
def test_invalid_without_master_nameserver
zone = valid_zone
zone.master_nameserver = ''
assert zone.invalid?
end
def test_determines_if_subzone
zone = valid_zone
zone.update(origin: 'pri.ee')
assert zone.subzone?
end
def test_updates_whois_after_update
subzone = dns_zones(:one).dup
subzone.origin = 'sub.zone'
subzone.save
whois_record = Whois::Record.find_by(name: subzone.origin)
assert whois_record.present?
end
def test_has_setting_info_as_contacts_for_subzones
subzone = dns_zones(:one).dup
subzone.origin = 'sub.zone'
subzone.save
whois_record = Whois::Record.find_by(name: subzone.origin)
assert whois_record.present?
assert_equal Setting.registry_whois_disclaimer, whois_record.json['disclaimer']
assert_equal Setting.registry_email, whois_record.json['email']
assert_equal Setting.registry_juridical_name, whois_record.json['registrar']
assert_equal Setting.registry_url, whois_record.json['registrar_website']
assert_equal Setting.registry_phone, whois_record.json['registrar_phone']
assert_equal Setting.registry_juridical_name, whois_record.json['registrant']
assert_equal Setting.registry_reg_no, whois_record.json['registrant_reg_no']
assert_equal Setting.registry_country_code, whois_record.json['registrant_ident_country_code']
contact = { name: Setting.registry_invoice_contact, email: Setting.registry_email,
disclosed_attributes: %w[name email] }.with_indifferent_access
assert_equal contact, whois_record.json['admin_contacts'][0]
assert_equal contact, whois_record.json['tech_contacts'][0]
end
def test_deletes_whois_record_after_destroy
subzone = dns_zones(:one).dup
subzone.origin = 'sub.zone'
subzone.save
assert Whois::Record.find_by(name: subzone.origin).present?
subzone.destroy
assert_nil Whois::Record.find_by(name: subzone.origin)
end
private
def valid_zone
dns_zones(:one)
end
end

View file

@ -16,7 +16,7 @@ class DomainVersionTest < ActiveSupport::TestCase
def test_assigns_creator_to_paper_trail_whodunnit
duplicate_domain = prepare_duplicate_domain
PaperTrail.whodunnit = @user.id_role_username
PaperTrail.request.whodunnit = @user.id_role_username
assert_difference 'duplicate_domain.versions.count', 1 do
duplicate_domain.save!
end
@ -28,7 +28,7 @@ class DomainVersionTest < ActiveSupport::TestCase
end
def test_assigns_updator_to_paper_trail_whodunnit
PaperTrail.whodunnit = @user.id_role_username
PaperTrail.request.whodunnit = @user.id_role_username
assert_difference '@domain.versions.count', 1 do
@domain.apply_registry_lock

View file

@ -1,37 +1,70 @@
require 'test_helper'
class DomainForceDeleteTest < ActiveSupport::TestCase
class NewDomainForceDeleteTest < ActiveSupport::TestCase
setup do
@domain = domains(:shop)
@original_redemption_grace_period = Setting.redemption_grace_period
end
teardown do
Setting.redemption_grace_period = @original_redemption_grace_period
end
def test_schedules_force_delete
assert_not @domain.force_delete_scheduled?
Setting.redemption_grace_period = 30
end
def test_schedules_force_delete_fast_track
assert_not @domain.force_delete_scheduled?
travel_to Time.zone.parse('2010-07-05')
@domain.schedule_force_delete
@domain.schedule_force_delete(type: :fast_track)
@domain.reload
assert @domain.force_delete_scheduled?
assert_equal Date.parse('2010-08-05'), @domain.force_delete_date
assert_equal Date.parse('2010-08-20'), @domain.force_delete_date.to_date
assert_equal Date.parse('2010-07-06'), @domain.force_delete_start.to_date
end
def test_scheduling_force_delete_adds_corresponding_statuses
def test_schedules_force_delete_soft_year_ahead
@domain.update(valid_to: Time.zone.parse('2012-08-05'))
assert_not @domain.force_delete_scheduled?
travel_to Time.zone.parse('2010-07-05')
@domain.schedule_force_delete(type: :soft)
@domain.reload
assert @domain.force_delete_scheduled?
assert_equal Date.parse('2010-09-20'), @domain.force_delete_date.to_date
assert_equal Date.parse('2010-08-06'), @domain.force_delete_start.to_date
end
def test_schedules_force_delete_soft_less_than_year_ahead
@domain.update_columns(valid_to: Time.zone.parse('2010-08-05'),
force_delete_date: nil)
assert_not @domain.force_delete_scheduled?
travel_to Time.zone.parse('2010-07-05')
@domain.schedule_force_delete(type: :soft)
@domain.reload
assert @domain.force_delete_scheduled?
assert_nil @domain.force_delete_date
assert_nil @domain.force_delete_start
end
def test_scheduling_soft_force_delete_adds_corresponding_statuses
statuses_to_be_added = [
DomainStatus::FORCE_DELETE,
DomainStatus::SERVER_RENEW_PROHIBITED,
DomainStatus::SERVER_TRANSFER_PROHIBITED,
DomainStatus::SERVER_UPDATE_PROHIBITED,
DomainStatus::PENDING_DELETE,
]
@domain.schedule_force_delete
@domain.schedule_force_delete(type: :soft)
@domain.reload
assert (@domain.statuses & statuses_to_be_added) == statuses_to_be_added
end
def test_scheduling_fast_track_force_delete_adds_corresponding_statuses
statuses_to_be_added = [
DomainStatus::FORCE_DELETE,
DomainStatus::SERVER_RENEW_PROHIBITED,
DomainStatus::SERVER_TRANSFER_PROHIBITED,
]
@domain.schedule_force_delete(type: :fast_track)
@domain.reload
assert (@domain.statuses & statuses_to_be_added) == statuses_to_be_added
end
@ -43,12 +76,13 @@ class DomainForceDeleteTest < ActiveSupport::TestCase
]
@domain.statuses = statuses_to_be_removed + %w[other-status]
@domain.schedule_force_delete
@domain.schedule_force_delete(type: :fast_track)
@domain.reload
assert_empty @domain.statuses & statuses_to_be_removed
end
def test_scheduling_force_delete_stops_pending_actions
Setting.redemption_grace_period = 45
statuses_to_be_removed = [
DomainStatus::PENDING_UPDATE,
DomainStatus::PENDING_TRANSFER,
@ -57,33 +91,35 @@ class DomainForceDeleteTest < ActiveSupport::TestCase
]
@domain.statuses = statuses_to_be_removed + %w[other-status]
@domain.schedule_force_delete
@domain.schedule_force_delete(type: :fast_track)
@domain.reload
assert_empty @domain.statuses & statuses_to_be_removed, 'Pending actions should be stopped'
end
def test_scheduling_force_delete_preserves_current_statuses
@domain.statuses = %w[test1 test2]
@domain.schedule_force_delete
@domain.schedule_force_delete(type: :fast_track)
@domain.reload
assert_equal %w[test1 test2], @domain.statuses_before_force_delete
end
def test_scheduling_force_delete_bypasses_validation
@domain = domains(:invalid)
@domain.schedule_force_delete
@domain.schedule_force_delete(type: :fast_track)
assert @domain.force_delete_scheduled?
end
def test_force_delete_cannot_be_scheduled_when_a_domain_is_discarded
@domain.update!(statuses: [DomainStatus::DELETE_CANDIDATE])
assert_raises StandardError do
@domain.schedule_force_delete
@domain.schedule_force_delete(type: :fast_track)
end
end
def test_cancels_force_delete
@domain.update_columns(statuses: [DomainStatus::FORCE_DELETE], force_delete_date: '2010-07-05')
@domain.update_columns(statuses: [DomainStatus::FORCE_DELETE],
force_delete_date: Time.zone.parse('2010-07-05'),
force_delete_start: Time.zone.parse('2010-07-05') - 45.days)
assert @domain.force_delete_scheduled?
@domain.cancel_force_delete
@ -91,11 +127,12 @@ class DomainForceDeleteTest < ActiveSupport::TestCase
assert_not @domain.force_delete_scheduled?
assert_nil @domain.force_delete_date
assert_nil @domain.force_delete_start
end
def test_cancelling_force_delete_bypasses_validation
@domain = domains(:invalid)
@domain.schedule_force_delete
@domain.schedule_force_delete(type: :fast_track)
@domain.cancel_force_delete
assert_not @domain.force_delete_scheduled?
end
@ -105,12 +142,9 @@ class DomainForceDeleteTest < ActiveSupport::TestCase
DomainStatus::FORCE_DELETE,
DomainStatus::SERVER_RENEW_PROHIBITED,
DomainStatus::SERVER_TRANSFER_PROHIBITED,
DomainStatus::SERVER_UPDATE_PROHIBITED,
DomainStatus::PENDING_DELETE,
DomainStatus::SERVER_MANUAL_INZONE
]
@domain.statuses = @domain.statuses + statuses
@domain.schedule_force_delete
@domain.schedule_force_delete(type: :fast_track)
@domain.cancel_force_delete
@domain.reload
@ -118,13 +152,94 @@ class DomainForceDeleteTest < ActiveSupport::TestCase
assert_empty @domain.statuses & statuses
end
def test_cancelling_force_delete_restores_statuses_that_a_domain_had_before_force_delete
@domain.statuses_before_force_delete = ['test1', DomainStatus::DELETE_CANDIDATE]
@domain.cancel_force_delete
def test_hard_force_delete_should_have_outzone_and_purge_date_with_time
@domain.schedule_force_delete(type: :fast_track)
@domain.reload
assert_equal ['test1', DomainStatus::DELETE_CANDIDATE], @domain.statuses
assert_nil @domain.statuses_before_force_delete
assert_equal(@domain.purge_date.to_date, @domain.force_delete_date)
assert_equal(@domain.outzone_date.to_date, @domain.force_delete_start.to_date +
Setting.expire_warning_period.days)
assert(@domain.purge_date.is_a?(ActiveSupport::TimeWithZone))
assert(@domain.outzone_date.is_a?(ActiveSupport::TimeWithZone))
end
def test_soft_force_delete_year_ahead_should_have_outzone_and_purge_date_with_time
@domain.update(valid_to: Time.zone.parse('2012-08-05'))
@domain.update(template_name: 'legal_person')
travel_to Time.zone.parse('2010-07-05')
@domain.schedule_force_delete(type: :soft)
travel_to Time.zone.parse('2010-08-21')
DomainCron.start_client_hold
@domain.reload
assert_equal(@domain.purge_date.to_date, @domain.force_delete_date.to_date)
assert_equal(@domain.outzone_date.to_date, @domain.force_delete_start.to_date +
Setting.expire_warning_period.days)
assert(@domain.purge_date.is_a?(ActiveSupport::TimeWithZone))
assert(@domain.outzone_date.is_a?(ActiveSupport::TimeWithZone))
end
def test_force_delete_soft_year_ahead_sets_client_hold
asserted_status = DomainStatus::CLIENT_HOLD
@domain.update(valid_to: Time.zone.parse('2012-08-05'))
@domain.update(template_name: 'legal_person')
assert_not @domain.force_delete_scheduled?
travel_to Time.zone.parse('2010-07-05')
@domain.schedule_force_delete(type: :soft)
travel_to Time.zone.parse('2010-08-21')
DomainCron.start_client_hold
@domain.reload
assert_includes(@domain.statuses, asserted_status)
end
def test_force_delete_soft_year_ahead_not_sets_client_hold_before_threshold
asserted_status = DomainStatus::CLIENT_HOLD
@domain.update_columns(valid_to: Time.zone.parse('2010-08-05'),
force_delete_date: nil)
assert_not @domain.force_delete_scheduled?
travel_to Time.zone.parse('2010-07-05')
@domain.schedule_force_delete(type: :soft)
travel_to Time.zone.parse('2010-07-06')
DomainCron.start_client_hold
@domain.reload
assert_not_includes(@domain.statuses, asserted_status)
end
def test_force_delete_fast_track_sets_client_hold
asserted_status = DomainStatus::CLIENT_HOLD
@domain.update_columns(valid_to: Time.zone.parse('2010-10-05'),
force_delete_date: nil)
travel_to Time.zone.parse('2010-07-05')
@domain.schedule_force_delete(type: :fast_track)
travel_to Time.zone.parse('2010-07-25')
DomainCron.start_client_hold
@domain.reload
assert_includes(@domain.statuses, asserted_status)
end
def test_not_sets_hold_before_treshold
asserted_status = DomainStatus::CLIENT_HOLD
@domain.update_columns(valid_to: Time.zone.parse('2010-10-05'),
force_delete_date: nil)
@domain.update(template_name: 'legal_person')
travel_to Time.zone.parse('2010-07-05')
@domain.schedule_force_delete(type: :fast_track)
travel_to Time.zone.parse('2010-07-06')
DomainCron.start_client_hold
@domain.reload
assert_not_includes(@domain.statuses, asserted_status)
end
end

View file

@ -2,7 +2,7 @@ require 'test_helper'
class DomainReleasableAuctionableTest < ActiveSupport::TestCase
# Needed for `test_updates_whois` test because of `after_commit :update_whois_record` in Domain
self.use_transactional_fixtures = false
self.use_transactional_tests = false
setup do
@domain = domains(:shop)

View file

@ -5,9 +5,14 @@ class DomainCronTest < ActiveSupport::TestCase
setup do
@domain = domains(:shop)
@original_expire_pending_confirmation = Setting.expire_pending_confirmation
ActionMailer::Base.deliveries.clear
end
teardown do
Setting.expire_pending_confirmation = @original_expire_pending_confirmation
end
def test_clean_expired_pendings_notifies_registrant_by_email
Setting.expire_pending_confirmation = 0
@domain.update!(registrant_verification_asked_at: Time.zone.now,
@ -18,4 +23,33 @@ class DomainCronTest < ActiveSupport::TestCase
assert_emails 1
end
end
def test_client_hold
Setting.redemption_grace_period = 30
@domain.update(valid_to: Time.zone.parse('2012-08-05'))
assert_not @domain.force_delete_scheduled?
travel_to Time.zone.parse('2010-07-05')
@domain.schedule_force_delete(type: :soft)
@domain.reload
@domain.update(template_name: 'legal_person')
travel_to Time.zone.parse('2010-08-06')
DomainCron.start_client_hold
assert_emails 1
end
def test_does_not_sets_hold_if_already_set
Setting.redemption_grace_period = 30
@domain.update(valid_to: Time.zone.parse('2012-08-05'))
travel_to Time.zone.parse('2010-07-05')
@domain.schedule_force_delete(type: :soft)
@domain.reload
@domain.update(template_name: 'legal_person', statuses: [DomainStatus::CLIENT_HOLD])
travel_to Time.zone.parse('2010-08-06')
DomainCron.start_client_hold
assert_emails 0
end
end

View file

@ -3,25 +3,284 @@ require 'test_helper'
class DomainTest < ActiveSupport::TestCase
setup do
@domain = domains(:shop)
@original_nameserver_required = Setting.nameserver_required
@original_min_admin_contact_count = Setting.admin_contacts_min_count
@original_max_admin_contact_count = Setting.admin_contacts_max_count
@original_min_tech_contact_count = Setting.tech_contacts_min_count
@original_max_tech_contact_count = Setting.tech_contacts_max_count
end
def test_valid_fixture_is_valid
assert @domain.valid?
teardown do
Setting.nameserver_required = @original_nameserver_required
Setting.admin_contacts_min_count = @original_min_admin_contact_count
Setting.admin_contacts_max_count = @original_max_admin_contact_count
Setting.tech_contacts_min_count = @original_min_tech_contact_count
Setting.tech_contacts_max_count = @original_max_tech_contact_count
end
def test_valid_domain_is_valid
assert valid_domain.valid?, proc { valid_domain.errors.full_messages }
end
def test_invalid_fixture_is_invalid
assert domains(:invalid).invalid?
end
# https://www.internet.ee/domeenid/ee-domeenireeglid#domeeninimede-registreerimine
def test_validates_name_format
assert_equal dns_zones(:one).origin, 'test'
domain = valid_domain
subdomain_min_length = 1
subdomain_max_length = 63
domain.name = '!invalid'
assert domain.invalid?
domain.name = 'aa--a.test'
assert domain.invalid?
domain.name = '-example.test'
assert domain.invalid?
domain.name = 'example-.test'
assert domain.invalid?
domain.name = "#{'a' * subdomain_max_length.next}.test"
assert domain.invalid?
domain.name = 'рф.test'
assert domain.invalid?
domain.name = "#{'a' * subdomain_min_length}.test"
assert domain.valid?
domain.name = "#{'a' * subdomain_max_length}.test"
assert domain.valid?
domain.name = 'example-1-2.test'
assert domain.valid?
domain.name = 'EXAMPLE.test'
assert domain.valid?
domain.name = 'äõöüšž.test'
assert domain.valid?
domain.name = 'xn--mnchen-3ya.test'
assert domain.valid?
end
def test_invalid_when_name_is_already_taken
Setting.admin_contacts_min_count = Setting.tech_contacts_min_count = 0
another_domain = valid_domain
domain = another_domain.dup
domain.name = another_domain.name
assert domain.invalid?
domain.name = "new.#{dns_zones(:one).origin}"
assert domain.valid?, proc { domain.errors.full_messages }
end
def test_invalid_when_name_is_zone
name = dns_zones(:one).origin
domain = valid_domain
domain.name = name
assert domain.invalid?
assert_includes domain.errors.full_messages, 'Data management policy violation:' \
' Domain name is blocked [name]'
end
def test_invalid_without_transfer_code
domain = valid_domain
domain.transfer_code = ''
assert domain.invalid?
end
def test_invalid_when_domain_is_reserved
reserved_domain = reserved_domains(:one)
domain = valid_domain.dup
domain.name = reserved_domain.name
assert domain.invalid?
assert_includes domain.errors.full_messages, 'Required parameter missing; reserved>' \
'pw element required for reserved domains'
end
def test_invalid_without_registration_period
domain = valid_domain
domain.period = ''
assert domain.invalid?
end
def test_validates_registration_period_format
domain = valid_domain
domain.period = 'invalid'
assert domain.invalid?
domain.period = 1.1
assert domain.invalid?
domain.period = 1
assert domain.valid?
end
def test_invalid_when_the_same_admin_contact_is_linked_twice
domain = valid_domain
contact = contacts(:john)
domain.admin_contacts << contact
assert_raise ActiveRecord::RecordNotUnique do
domain.admin_contacts << contact
end
end
def test_invalid_when_the_same_tech_contact_is_linked_twice
domain = valid_domain
contact = contacts(:john)
domain.tech_contacts << contact
assert_raise ActiveRecord::RecordNotUnique do
domain.tech_contacts << contact
end
end
def test_validates_name_server_count_when_name_servers_are_required
nameserver_attributes = nameservers(:shop_ns1).dup.attributes
domain = valid_domain
Setting.nameserver_required = true
min_count = 1
max_count = 2
Setting.ns_min_count = min_count
Setting.ns_max_count = max_count
domain.nameservers.clear
min_count.times { domain.nameservers.build(nameserver_attributes) }
assert domain.valid?, proc { domain.errors.full_messages }
domain.nameservers.clear
max_count.times do |i|
domain.nameservers.build(nameserver_attributes.merge(hostname: "ns#{i}.test"))
end
assert domain.valid?, proc { domain.errors.full_messages }
domain.nameservers.clear
assert domain.invalid?
domain.nameservers.clear
max_count.next.times do |i|
domain.nameservers.build(nameserver_attributes.merge(hostname: "ns#{i}.test"))
end
assert domain.invalid?
end
def test_valid_without_name_servers_when_they_are_optional
domain = valid_domain
domain.nameservers.clear
Setting.nameserver_required = false
Setting.ns_min_count = 1
assert domain.valid?
end
def test_validates_admin_contact_count
domain_contact_attributes = domain_contacts(:shop_jane).dup.attributes
domain = valid_domain
min_count = 1
max_count = 2
Setting.admin_contacts_min_count = min_count
Setting.admin_contacts_max_count = max_count
domain.admin_domain_contacts.clear
min_count.times { domain.admin_domain_contacts.build(domain_contact_attributes) }
assert domain.valid?, proc { domain.errors.full_messages }
domain.admin_domain_contacts.clear
max_count.times { domain.admin_domain_contacts.build(domain_contact_attributes) }
assert domain.valid?, proc { domain.errors.full_messages }
domain.admin_domain_contacts.clear
assert domain.invalid?
domain.admin_domain_contacts.clear
max_count.next.times { domain.admin_domain_contacts.build(domain_contact_attributes) }
assert domain.invalid?
end
def test_validates_tech_contact_count
domain_contact_attributes = domain_contacts(:shop_william).dup.attributes
domain = valid_domain
min_count = 1
max_count = 2
Setting.tech_contacts_min_count = min_count
Setting.tech_contacts_max_count = max_count
domain.tech_domain_contacts.clear
min_count.times { domain.tech_domain_contacts.build(domain_contact_attributes) }
assert domain.valid?, proc { domain.errors.full_messages }
domain.tech_domain_contacts.clear
max_count.times { domain.tech_domain_contacts.build(domain_contact_attributes) }
assert domain.valid?, proc { domain.errors.full_messages }
domain.tech_domain_contacts.clear
assert domain.invalid?
domain.tech_domain_contacts.clear
max_count.next.times { domain.tech_domain_contacts.build(domain_contact_attributes) }
assert domain.invalid?
end
def test_outzone_candidates_scope_returns_records_with_outzone_at_in_the_past
travel_to Time.zone.parse('2010-07-05 08:00:00')
domain1 = domains(:shop)
domain1.update!(outzone_at: Time.zone.parse('2010-07-05 07:59:59'))
domain2 = domains(:airport)
domain2.update!(outzone_at: Time.zone.parse('2010-07-05 08:00:00'))
domain3 = domains(:library)
domain3.update!(outzone_at: Time.zone.parse('2010-07-05 08:00:01'))
Domain.connection.disable_referential_integrity do
Domain.where("id NOT IN (#{[domain1.id, domain2.id, domain3.id].join(',')})").delete_all
end
assert_equal [domain1.id], Domain.outzone_candidates.ids
end
def test_expired_scope_returns_records_with_valid_to_in_the_past
travel_to Time.zone.parse('2010-07-05 08:00:00')
domain1 = domains(:shop)
domain1.update!(valid_to: Time.zone.parse('2010-07-05 07:59:59'))
domain2 = domains(:airport)
domain2.update!(valid_to: Time.zone.parse('2010-07-05 08:00:00'))
domain3 = domains(:library)
domain3.update!(valid_to: Time.zone.parse('2010-07-05 08:00:01'))
Domain.connection.disable_referential_integrity do
Domain.where("id NOT IN (#{[domain1.id, domain2.id, domain3.id].join(',')})").delete_all
end
assert_equal [domain1.id, domain2.id].sort, Domain.expired.ids.sort
end
def test_domain_name
domain = Domain.new(name: 'shop.test')
assert_equal 'shop.test', domain.domain_name.to_s
end
def test_nil_name_doesnt_throw_error
domain = Domain.new(name: 'shop.test')
assert_nothing_raised do
domain.name = nil
end
end
def test_returns_registrant_user_domains_by_registrant
registrant = contacts(:john).becomes(Registrant)
assert_equal registrant, @domain.registrant
registrant_user = RegistrantUser.new
registrant_user = RegistrantUser.new(registrant_ident: 'US-12345')
registrant_user.stub(:contacts, [registrant]) do
assert_includes Domain.registrant_user_domains(registrant_user), @domain
@ -32,7 +291,7 @@ class DomainTest < ActiveSupport::TestCase
contact = contacts(:jane)
assert_not_equal contact.becomes(Registrant), @domain.registrant
assert_includes @domain.contacts, contact
registrant_user = RegistrantUser.new
registrant_user = RegistrantUser.new(registrant_ident: 'US-12345')
registrant_user.stub(:contacts, [contact]) do
assert_includes Domain.registrant_user_domains(registrant_user), @domain
@ -79,4 +338,103 @@ class DomainTest < ActiveSupport::TestCase
assert_equal %w[john@inbox.test william@inbox.test].sort, @domain.primary_contact_emails.sort
end
end
def test_normalizes_name
unnormalized_name = ' Foo.test '
domain = Domain.new(name: unnormalized_name)
assert_equal 'foo.test', domain.name
assert_equal 'foo.test', domain.name_puny
assert_equal unnormalized_name, domain.name_dirty
end
def test_converts_name_to_punycode
domain = Domain.new(name: 'münchen.test')
assert_equal 'xn--mnchen-3ya.test', domain.name_puny
end
def test_returns_new_registrant_id
id = 1
domain = Domain.new(pending_json: { new_registrant_id: id })
assert_equal id, domain.new_registrant_id
end
def test_returns_new_registrant_email
email = 'john@inbox.test'
domain = Domain.new(pending_json: { new_registrant_email: email })
assert_equal email, domain.new_registrant_email
end
def test_expiration
now = Time.zone.parse('2010-07-05 08:00:00')
travel_to now
domain = Domain.new
domain.valid_to = now + 1.second
assert domain.registered?
assert_not domain.expired?
domain.valid_to = now
assert domain.expired?
assert_not domain.registered?
domain.valid_to = now - 1.second
assert domain.expired?
assert_not domain.registered?
end
def test_activation
domain = inactive_domain
assert domain.inactive?
assert_not domain.active?
domain.activate
assert domain.active?
assert_not domain.inactive?
end
def test_deactivation
domain = @domain
assert domain.active?
assert_not domain.inactive?
domain.deactivate
assert domain.inactive?
assert_not domain.active?
end
def test_registrant_change_removes_force_delete
@domain.update_columns(valid_to: Time.zone.parse('2010-10-05'),
force_delete_date: nil)
@domain.update(template_name: 'legal_person')
travel_to Time.zone.parse('2010-07-05')
@domain.schedule_force_delete(type: :fast_track)
assert(@domain.force_delete_scheduled?)
other_registrant = Registrant.find_by(code: 'jane-001')
@domain.pending_json['new_registrant_id'] = other_registrant.id
@domain.registrant = other_registrant
@domain.save!
assert_not(@domain.force_delete_scheduled?)
end
private
def valid_domain
domains(:shop)
end
def inactive_domain
Setting.nameserver_required = true
domain = @domain
domain.update!(statuses: [DomainStatus::INACTIVE])
domain
end
end

View file

@ -0,0 +1,92 @@
require 'test_helper'
class EppResponseResultCodeTest < ActiveSupport::TestCase
def test_creates_code_by_key
key = :completed_successfully
assert_includes Epp::Response::Result::Code.codes.keys, key
assert_kind_of Epp::Response::Result::Code, Epp::Response::Result::Code.key(key)
end
def test_creates_new_code_by_string_value
code_value = Epp::Response::Result::Code.codes.values.first
code = Epp::Response::Result::Code.new(code_value.to_s)
assert_equal code_value, code.value
end
def test_invalid_code_value
invalid_code_value = 0000
refute_includes Epp::Response::Result::Code.codes.values, invalid_code_value
e = assert_raises ArgumentError do
Epp::Response::Result::Code.new(invalid_code_value)
end
assert_equal "Invalid value: #{invalid_code_value}", e.message
end
def test_returns_code_values
codes = {
completed_successfully: 1000,
completed_successfully_action_pending: 1001,
completed_without_address: 1100,
completed_successfully_no_messages: 1300,
completed_successfully_ack_to_dequeue: 1301,
completed_successfully_ending_session: 1500,
unknown_command: 2000,
syntax_error: 2001,
use_error: 2002,
required_parameter_missing: 2003,
parameter_value_range_error: 2004,
parameter_value_syntax_error: 2005,
billing_failure: 2104,
unimplemented: 2101,
object_is_not_eligible_for_renewal: 2105,
object_is_not_eligible_for_transfer: 2106,
authorization_error: 2201,
invalid_authorization_information: 2202,
object_does_not_exist: 2303,
object_status_prohibits_operation: 2304,
object_association_prohibits_operation: 2305,
parameter_value_policy_error: 2306,
data_management_policy_violation: 2308,
command_failed: 2400,
authentication_error_server_closing_connection: 2501,
}
assert_equal codes, Epp::Response::Result::Code.codes
end
def test_returns_default_descriptions
descriptions = {
1000 => 'Command completed successfully',
1001 => 'Command completed successfully; action pending',
1100 => 'Command completed successfully; Postal address data discarded',
1300 => 'Command completed successfully; no messages',
1301 => 'Command completed successfully; ack to dequeue',
1500 => 'Command completed successfully; ending session',
2000 => 'Unknown command',
2001 => 'Command syntax error',
2002 => 'Command use error',
2003 => 'Required parameter missing',
2004 => 'Parameter value range error',
2005 => 'Parameter value syntax error',
2101 => 'Unimplemented command',
2104 => 'Billing failure',
2105 => 'Object is not eligible for renewal',
2106 => 'Object is not eligible for transfer',
2201 => 'Authorization error',
2202 => 'Invalid authorization information',
2303 => 'Object does not exist',
2304 => 'Object status prohibits operation',
2305 => 'Object association prohibits operation',
2306 => 'Parameter value policy error',
2308 => 'Data management policy violation',
2400 => 'Command failed',
2501 => 'Authentication error; server closing connection',
}
assert_equal descriptions, Epp::Response::Result::Code.default_descriptions
end
def test_equality
assert_equal Epp::Response::Result::Code.new(1000), Epp::Response::Result::Code.new(1000)
end
end

View file

@ -0,0 +1,5 @@
require 'test_helper'
class EppResponseResultTest < ActiveSupport::TestCase
end

View file

@ -0,0 +1,29 @@
require 'test_helper'
class EppResponseTest < ActiveSupport::TestCase
def test_creates_new_response_from_xml_doc
xml = <<-XML
<?xml version="1.0" encoding="UTF-8"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="lib/schemas/epp-ee-1.0.xsd">
<response>
<result code="1000">
<msg>any</msg>
</result>
</response>
</epp>
XML
assert_kind_of Epp::Response, Epp::Response.xml(xml)
end
def test_code_predicate
present_code = Epp::Response::Result::Code.key(:completed_successfully)
absent_code = Epp::Response::Result::Code.key(:required_parameter_missing)
result = Epp::Response::Result.new(code: present_code)
response = Epp::Response.new(results: [result])
assert response.code?(present_code)
assert_not response.code?(absent_code)
end
end

View file

@ -11,7 +11,8 @@ class InvoiceTest < ActiveSupport::TestCase
def test_overdue_scope_returns_unpaid_uncancelled_invoices_with_past_due_date
travel_to Time.zone.parse('2010-07-05')
@invoice.update!(account_activity: nil, cancelled_at: nil, due_date: '2010-07-04')
@invoice.update!(account_activity: nil, cancelled_at: nil, issue_date: '2010-07-04',
due_date: '2010-07-04')
assert Invoice.overdue.include?(@invoice), 'Should return overdue invoice'
end
@ -108,4 +109,4 @@ class InvoiceTest < ActiveSupport::TestCase
seller_zip: nil)
assert_equal 'street, city, state', invoice.seller_address
end
end
end

View file

@ -5,23 +5,42 @@ class NameserverGlueRecordTest < ActiveSupport::TestCase
@nameserver = nameservers(:shop_ns1)
end
def test_invalid_without_ip_if_glue_record_is_required
@nameserver.hostname = 'ns1.shop.test'
@nameserver.ipv4 = @nameserver.ipv6 = ''
assert @nameserver.invalid?
assert_includes @nameserver.errors.full_messages, 'Either IPv4 or IPv6 is required' \
def test_invalid_when_glue_record_is_required_and_no_ip_is_provided
domain = Domain.new(name: 'shop.test')
nameserver = Nameserver.new(domain: domain, hostname: 'ns1.shop.test')
assert nameserver.invalid?
assert_includes nameserver.errors.full_messages, 'Either IPv4 or IPv6 is required' \
' for glue record generation'
end
def test_valid_with_ip_if_glue_record_is_required
@nameserver.hostname = 'ns1.shop.test'
@nameserver.ipv4 = ['192.0.2.1']
@nameserver.ipv6 = ''
assert @nameserver.valid?
def test_valid_when_glue_record_is_required_and_ipv4_is_provided
domain = Domain.new(name: 'shop.test')
nameserver = Nameserver.new(domain: domain, hostname: 'ns1.shop.test')
nameserver.ipv4 = ['192.0.2.1']
assert nameserver.valid?
end
def test_valid_without_ip_if_glue_record_is_not_required
@nameserver.ipv4 = @nameserver.ipv6 = ''
assert @nameserver.valid?
def test_valid_when_glue_record_is_required_and_ipv6_is_provided
domain = Domain.new(name: 'shop.test')
nameserver = Nameserver.new(domain: domain, hostname: 'ns1.shop.test')
nameserver.ipv6 = ['2001:db8::1']
assert nameserver.valid?
end
def test_valid_when_glue_record_is_not_required_and_no_ip_is_provided
domain = Domain.new(name: 'shop.test')
nameserver = Nameserver.new(domain: domain, hostname: 'ns1.registrar.test')
assert nameserver.valid?
end
def test_valid_when_glue_record_is_not_required_and_no_ip_is_provided_substring_match
domain = Domain.new(name: 'le.test')
nameserver = Nameserver.new(domain: domain, hostname: 'ns1.shop.test')
assert nameserver.valid?
end
end

View file

@ -8,7 +8,7 @@ class BankLinkTest < ActiveSupport::TestCase
super
@invoice = invoices(:one)
@invoice.update!(total: 12)
@invoice.update!(account_activity: nil, total: 12)
travel_to '2018-04-01 00:30 +0300'
create_new_bank_link
@ -36,11 +36,11 @@ class BankLinkTest < ActiveSupport::TestCase
'VK_MAC': 'CZZvcptkxfuOxRR88JmT4N+Lw6Hs4xiQfhBWzVYldAcRTQbcB/lPf9MbJzBE4e1/HuslQgkdCFt5g1xW2lJwrVDBQTtP6DAHfvxU3kkw7dbk0IcwhI4whUl68/QCwlXEQTAVDv1AFnGVxXZ40vbm/aLKafBYgrirB5SUe8+g9FE=',
'VK_ENCODING': 'UTF-8',
'VK_LANG': 'ENG'
}.with_indifferent_access
}.as_json
@completed_bank_link = PaymentOrders::BankLink.new(
'seb', @invoice, { response: params }
)
@completed_bank_link = PaymentOrder.new(type: 'PaymentOrders::Seb',
invoice: @invoice,
response: params)
end
def create_cancelled_bank_link
@ -55,16 +55,17 @@ class BankLinkTest < ActiveSupport::TestCase
'VK_MAC': 'PElE2mYXXN50q2UBvTuYU1rN0BmOQcbafPummDnWfNdm9qbaGQkGyOn0XaaFGlrdEcldXaHBbZKUS0HegIgjdDfl2NOk+wkLNNH0Iu38KzZaxHoW9ga7vqiyKHC8dcxkHiO9HsOnz77Sy/KpWCq6cz48bi3fcMgo+MUzBMauWoQ=',
'VK_ENCODING': 'UTF-8',
'VK_LANG': 'ENG'
}.with_indifferent_access
}.as_json
@cancelled_bank_link = PaymentOrders::BankLink.new(
'seb', @invoice, { response: params }
)
@cancelled_bank_link = PaymentOrder.new(type: 'PaymentOrders::Seb',
invoice: @invoice,
response: params)
end
def create_new_bank_link
params = { return_url: 'return.url', response_url: 'response.url' }
@new_bank_link = PaymentOrders::BankLink.new('seb', @invoice, params)
@new_bank_link = PaymentOrder.new(type: 'PaymentOrders::Seb', invoice: @invoice)
@new_bank_link.return_url = 'return.url'
@new_bank_link.response_url = 'response.url'
end
def test_response_is_not_valid_when_it_is_missing
@ -105,21 +106,14 @@ class BankLinkTest < ActiveSupport::TestCase
refute(@cancelled_bank_link.settled_payment?)
end
def test_complete_transaction_calls_methods_on_transaction
mock_transaction = MiniTest::Mock.new
mock_transaction.expect(:sum= , '12.00', ['12.00'])
mock_transaction.expect(:bank_reference= , '1', ['1'])
mock_transaction.expect(:buyer_bank_code= , 'testvpos', ['testvpos'])
mock_transaction.expect(:buyer_iban= , '1234', ['1234'])
mock_transaction.expect(:paid_at= , Date.parse('2018-04-01 00:30:00 +0300'), [Time.parse('2018-04-01T00:30:00+0300')])
mock_transaction.expect(:buyer_name=, 'John Doe', ['John Doe'])
mock_transaction.expect(:save!, true)
mock_transaction.expect(:autobind_invoice, AccountActivity.new)
def test_successful_payment_creates_bank_transaction
@completed_bank_link.complete_transaction
BankTransaction.stub(:find_by, mock_transaction) do
@completed_bank_link.complete_transaction
end
transaction = BankTransaction.find_by(
sum: @completed_bank_link.response['VK_AMOUNT'],
buyer_name: @completed_bank_link.response['VK_SND_NAME']
)
mock_transaction.verify
assert transaction.present?
end
end

View file

@ -4,36 +4,38 @@ class EveryPayTest < ActiveSupport::TestCase
def setup
super
@invoice = invoices(:one)
@invoice = invoices(:unpaid)
@invoice.update!(total: 12)
params = {
response:
{
utf8: '✓',
_method: 'put',
authenticity_token: 'OnA69vbccQtMt3C9wxEWigs5Gpf/7z+NoxRCMkFPlTvaATs8+OgMKF1I4B2f+vuK37zCgpWZaWWtyuslRRSwkw==',
nonce: '392f2d7748bc8cb0d14f263ebb7b8932',
timestamp: '1524136727',
api_username: 'ca8d6336dd750ddb',
transaction_result: 'completed',
payment_reference: 'fd5d27b59a1eb597393cd5ff77386d6cab81ae05067e18d530b10f3802e30b56',
payment_state: 'settled',
amount: '12.00',
order_reference: 'e468a2d59a731ccc546f2165c3b1a6',
account_id: 'EUR3D1',
cc_type: 'master_card',
cc_last_four_digits: '0487',
cc_month: '10',
cc_year: '2018',
cc_holder_name: 'John Doe',
hmac_fields: 'account_id,amount,api_username,cc_holder_name,cc_last_four_digits,cc_month,cc_type,cc_year,hmac_fields,nonce,order_reference,payment_reference,payment_state,timestamp,transaction_result',
hmac: 'efac1c732835668cd86023a7abc140506c692f0d',
invoice_id: '1',
},
}
@every_pay = PaymentOrders::EveryPay.new('every_pay', @invoice, params)
@other_pay = PaymentOrders::EveryPay.new('every_pay', @invoice, {})
response = {
"utf8": '✓',
"_method": 'put',
"authenticity_token": 'OnA69vbccQtMt3C9wxEWigs5Gpf/7z+NoxRCMkFPlTvaATs8+OgMKF1I4B2f+vuK37zCgpWZaWWtyuslRRSwkw=="',
"nonce": '392f2d7748bc8cb0d14f263ebb7b8932',
"timestamp": '1524136727',
"api_username": 'ca8d6336dd750ddb',
"transaction_result": 'completed',
"payment_reference": 'fd5d27b59a1eb597393cd5ff77386d6cab81ae05067e18d530b10f3802e30b56',
"payment_state": 'settled',
"amount": '12.00',
"order_reference": 'e468a2d59a731ccc546f2165c3b1a6',
"account_id": 'EUR3D1',
"cc_type": 'master_card',
"cc_last_four_digits": '0487',
"cc_month": '10',
"cc_year": '2018',
"cc_holder_name": 'John Doe',
"hmac_fields": 'account_id,amount,api_username,cc_holder_name,cc_last_four_digits,cc_month,cc_type,cc_year,hmac_fields,nonce,order_reference,payment_reference,payment_state,timestamp,transaction_result',
"hmac": 'efac1c732835668cd86023a7abc140506c692f0d',
"invoice_id": '2'
}.as_json
@successful_payment = PaymentOrder.new(type: 'PaymentOrders::EveryPay',
invoice: @invoice,
response: response)
@failed_payment = @successful_payment.dup
@failed_payment.response['payment_state'] = 'cancelled'
travel_to Time.zone.parse('2018-04-01 00:30:00 +0000')
end
@ -47,37 +49,37 @@ class EveryPayTest < ActiveSupport::TestCase
transaction_type: 'charge',
hmac_fields: 'account_id,amount,api_username,callback_url,customer_url,hmac_fields,nonce,order_reference,timestamp,transaction_type'
}
form_fields = @every_pay.form_fields
form_fields = @successful_payment.form_fields
expected_fields.each do |k, v|
assert_equal(v, form_fields[k])
end
end
def test_valid_response_from_intermediary?
assert(@every_pay.valid_response_from_intermediary?)
refute(@other_pay.valid_response_from_intermediary?)
assert(@successful_payment.valid_response_from_intermediary?)
@failed_payment.response = { 'what': 'definitely not valid everypay response' }
refute(@failed_payment.valid_response_from_intermediary?)
end
def test_valid_and_successful_payment_is_determined
assert(@successful_payment.payment_received?)
refute(@failed_payment.payment_received?)
end
def test_settled_payment?
assert(@every_pay.settled_payment?)
other_pay = PaymentOrders::EveryPay.new(
'every_pay', @invoice, {response: {payment_state: 'CANCELLED'}}
)
refute(other_pay.settled_payment?)
assert(@successful_payment.settled_payment?)
refute(@failed_payment.settled_payment?)
end
def test_complete_transaction_calls_methods_on_transaction
mock_transaction = MiniTest::Mock.new
mock_transaction.expect(:sum= , '12.00', ['12.00'])
mock_transaction.expect(:paid_at= , Date.strptime('1524136727', '%s'), [Date.strptime('1524136727', '%s')])
mock_transaction.expect(:buyer_name=, 'John Doe', ['John Doe'])
mock_transaction.expect(:save!, true)
mock_transaction.expect(:autobind_invoice, AccountActivity.new)
def test_successful_payment_creates_bank_transaction
@successful_payment.complete_transaction
BankTransaction.stub(:find_by, mock_transaction) do
@every_pay.complete_transaction
end
transaction = BankTransaction.find_by(
sum: @successful_payment.response['amount'],
buyer_name: @successful_payment.response['cc_holder_name']
)
mock_transaction.verify
assert transaction.present?
end
end

View file

@ -5,23 +5,21 @@ class PaymentOrdersTest < ActiveSupport::TestCase
super
@original_methods = ENV['payment_methods']
@original_seb_URL = ENV['seb_payment_url']
ENV['payment_methods'] = 'seb, swed, credit_card'
@original_seb_url = ENV['seb_payment_url']
ENV['payment_methods'] = 'seb, swed, every_pay'
ENV['seb_payment_url'] = nil
@not_implemented_payment = PaymentOrders::Base.new(
'not_implemented', Invoice.new
)
@not_implemented_payment = PaymentOrder.new(invoice: Invoice.new)
end
def teardown
super
ENV['payment_methods'] = @original_methods
ENV['seb_payment_url'] = @original_seb_URL
ENV['seb_payment_url'] = @original_seb_url
end
def test_variable_assignment
assert_equal 'not_implemented', @not_implemented_payment.type
assert_nil @not_implemented_payment.type
assert_nil @not_implemented_payment.response_url
assert_nil @not_implemented_payment.return_url
assert_nil @not_implemented_payment.form_url
@ -45,14 +43,61 @@ class PaymentOrdersTest < ActiveSupport::TestCase
end
end
def test_that_create_with_type_raises_argument_error
assert_raise ArgumentError do
PaymentOrders.create_with_type("not_implemented", Invoice.new)
def test_correct_channel_is_assigned
everypay_channel = PaymentOrder.new_with_type(type: 'every_pay', invoice: @invoice)
assert_equal everypay_channel.channel, 'EveryPay'
assert_equal everypay_channel.class.config_namespace_name, 'every_pay'
swed_channel = PaymentOrder.new_with_type(type: 'swed', invoice: @invoice)
assert_equal swed_channel.channel, 'Swed'
assert_equal swed_channel.class.config_namespace_name, 'swed'
seb_channel = PaymentOrder.new_with_type(type: 'seb', invoice: @invoice)
assert_equal seb_channel.channel, 'Seb'
assert_equal seb_channel.class.config_namespace_name, 'seb'
lhv_channel = PaymentOrder.new_with_type(type: 'lhv', invoice: @invoice)
assert_equal lhv_channel.channel, 'Lhv'
assert_equal lhv_channel.class.config_namespace_name, 'lhv'
admin_channel = PaymentOrder.new_with_type(type: 'admin_payment', invoice: @invoice)
assert_equal admin_channel.channel, 'AdminPayment'
assert_equal admin_channel.class.config_namespace_name, 'admin_payment'
system_channel = PaymentOrder.new_with_type(type: 'system_payment', invoice: @invoice)
assert_equal system_channel.channel, 'SystemPayment'
assert_equal system_channel.class.config_namespace_name, 'system_payment'
end
def test_can_not_create_order_for_paid_invoice
invoice = invoices(:one)
payment_order = PaymentOrder.new_with_type(type: 'every_pay', invoice: invoice)
assert payment_order.invalid?
assert_includes payment_order.errors[:invoice], 'is already paid'
end
def test_order_without_channel_is_invalid
payment_order = PaymentOrder.new
assert payment_order.invalid?
assert_includes payment_order.errors[:type], 'is not supported'
end
def test_can_not_create_order_with_invalid_type
assert_raise NameError do
PaymentOrder.new_with_type(type: 'not_implemented', invoice: Invoice.new)
end
end
def test_create_with_correct_subclass
payment = PaymentOrders.create_with_type('seb', Invoice.new)
assert_equal PaymentOrders::BankLink, payment.class
def test_supported_method_bool_does_not_fail
assert_not PaymentOrder.supported_method?('not_implemented', shortname: true)
assert PaymentOrder.supported_method?('every_pay', shortname: true)
assert_not PaymentOrder.supported_method?('PaymentOrders::NonExistant')
assert PaymentOrder.supported_method?('PaymentOrders::EveryPay')
end
def test_can_create_with_correct_subclass
payment = PaymentOrder.new_with_type(type: 'seb', invoice: Invoice.new)
assert_equal PaymentOrders::Seb, payment.class
end
end

View file

@ -0,0 +1,33 @@
require 'test_helper'
class RegistrantVerificationTest < ActiveSupport::TestCase
setup do
@domain = domains(:shop)
@initiator = users(:api_bestnames).username
@token = 'zzzzz'
@domain.update(statuses: [DomainStatus::PENDING_UPDATE],
registrant_verification_asked_at: Time.zone.now - 1.day,
registrant_verification_token: @token)
end
def test_audit_log
registrant_verification = registrant_verifications(:one)
random_action = "random#{rand(100)}"
assert_difference -> { RegistrantVerificationVersion.count } do
registrant_verification.update_attributes!(action: random_action)
end
end
def test_reject_changes
@registrant_verification = RegistrantVerification.new(domain_id: @domain.id,
verification_token: @token)
start_versions_count = RegistrantVerificationVersion.count
assert_nothing_raised do
@registrant_verification.domain_registrant_change_reject!("email link, #{@initiator}")
end
assert_equal RegistrantVerificationVersion.count, start_versions_count + 1
end
end

View file

@ -3,6 +3,15 @@ require 'test_helper'
class RegistrarTest < ActiveSupport::TestCase
setup do
@registrar = registrars(:bestnames)
@original_default_language = Setting.default_language
@original_days_to_keep_invoices_active = Setting.days_to_keep_invoices_active
@old_validation_type = Truemail.configure.default_validation_type
end
teardown do
Setting.default_language = @original_default_language
Setting.days_to_keep_invoices_active = @original_days_to_keep_invoices_active
Truemail.configure.default_validation_type = @old_validation_type
end
def test_valid_registrar_is_valid
@ -31,12 +40,123 @@ class RegistrarTest < ActiveSupport::TestCase
assert registrar.invalid?
end
def test_email_verification_valid
registrar = valid_registrar
registrar.email = 'info@internet.ee'
registrar.billing_email = nil
assert registrar.valid?
end
def test_email_verification_smtp_error
Truemail.configure.default_validation_type = :smtp
registrar = valid_registrar
registrar.email = 'somecrude1337joke@internet.ee'
registrar.billing_email = nil
assert registrar.invalid?
assert_equal I18n.t('activerecord.errors.models.contact.attributes.email.email_smtp_check_error'), registrar.errors.messages[:email].first
end
def test_email_verification_mx_error
Truemail.configure.default_validation_type = :mx
registrar = valid_registrar
registrar.email = 'somecrude31337joke@somestrange31337domain.ee'
registrar.billing_email = nil
assert registrar.invalid?
assert_equal I18n.t('activerecord.errors.models.contact.attributes.email.email_mx_check_error'), registrar.errors.messages[:email].first
end
def test_email_verification_regex_error
Truemail.configure.default_validation_type = :regex
registrar = valid_registrar
registrar.email = 'some@strangesentence@internet.ee'
registrar.billing_email = nil
assert registrar.invalid?
assert_equal I18n.t('activerecord.errors.models.contact.attributes.email.email_regex_check_error'), registrar.errors.messages[:email].first
end
def test_billing_email_verification_valid
registrar = valid_registrar
registrar.billing_email = 'info@internet.ee'
assert registrar.valid?
end
def test_billing_email_verification_smtp_error
Truemail.configure.default_validation_type = :smtp
registrar = valid_registrar
registrar.billing_email = 'somecrude1337joke@internet.ee'
assert registrar.invalid?
assert_equal I18n.t('activerecord.errors.models.contact.attributes.email.email_smtp_check_error'), registrar.errors.messages[:billing_email].first
end
def test_billing_email_verification_mx_error
Truemail.configure.default_validation_type = :mx
registrar = valid_registrar
registrar.billing_email = 'somecrude31337joke@somestrange31337domain.ee'
assert registrar.invalid?
assert_equal I18n.t('activerecord.errors.models.contact.attributes.email.email_mx_check_error'), registrar.errors.messages[:billing_email].first
end
def test_billing_email_verification_regex_error
Truemail.configure.default_validation_type = :regex
registrar = valid_registrar
registrar.billing_email = 'some@strangesentence@internet.ee'
assert registrar.invalid?
assert_equal I18n.t('activerecord.errors.models.contact.attributes.email.email_regex_check_error'), registrar.errors.messages[:billing_email].first
end
def test_creates_email_verification_in_unicode
unicode_email = 'suur@äri.ee'
punycode_email = Registrar.unicode_to_punycode(unicode_email)
unicode_billing_email = 'billing@äri.ee'
punycode_billing_email = Registrar.unicode_to_punycode(unicode_billing_email)
registrar = valid_registrar
registrar.email = punycode_email
registrar.billing_email = punycode_billing_email
registrar.save
assert_equal registrar.email_verification.email, unicode_email
assert_equal registrar.billing_email_verification.email, unicode_billing_email
end
def test_invalid_without_accounting_customer_code
registrar = valid_registrar
registrar.accounting_customer_code = ''
assert registrar.invalid?
end
def test_optional_billing_email
registrar = valid_registrar
registrar.billing_email = ''
assert registrar.valid?
end
def test_returns_billing_email_when_provided
billing_email = 'billing@registrar.test'
registrar = Registrar.new(billing_email: billing_email)
assert_equal billing_email, registrar.billing_email
end
def test_billing_email_fallback
contact_email = 'info@registrar.test'
registrar = Registrar.new(contact_email: contact_email, billing_email: '')
assert_equal contact_email, registrar.billing_email
end
def test_invalid_without_language
registrar = valid_registrar
registrar.language = ''
@ -82,15 +202,12 @@ class RegistrarTest < ActiveSupport::TestCase
def test_issues_new_invoice
travel_to Time.zone.parse('2010-07-05')
@original_days_to_keep_invoices_active_setting = Setting.days_to_keep_invoices_active
Setting.days_to_keep_invoices_active = 10
invoice = @registrar.issue_prepayment_invoice(100)
assert_equal Date.parse('2010-07-05'), invoice.issue_date
assert_equal Date.parse('2010-07-15'), invoice.due_date
Setting.days_to_keep_invoices_active = @original_days_to_keep_invoices_active_setting
end
def test_issues_e_invoice_along_with_invoice
@ -119,6 +236,12 @@ class RegistrarTest < ActiveSupport::TestCase
assert registrar.invalid?
end
def test_aliases_contact_email_to_email
email = 'info@registrar.test'
registrar = Registrar.new(email: email)
assert_equal email, registrar.contact_email
end
def test_full_address
registrar = Registrar.new(address_street: 'Main Street 1', address_zip: '1234',
address_city: 'NY', address_state: 'NY State')
@ -190,6 +313,33 @@ class RegistrarTest < ActiveSupport::TestCase
assert_equal iban, registrar.e_invoice_iban
end
def test_legal_doc_is_mandatory
old_value = Setting.legal_document_is_mandatory
Setting.legal_document_is_mandatory = true
assert @registrar.legaldoc_mandatory?
Setting.legal_document_is_mandatory = old_value
end
def test_legal_doc_is_not_mandatory_if_opted_out
old_value = Setting.legal_document_is_mandatory
Setting.legal_document_is_mandatory = true
@registrar.legaldoc_optout = true
@registrar.save(validate: false)
@registrar.reload
assert_not @registrar.legaldoc_mandatory?
Setting.legal_document_is_mandatory = old_value
end
def test_legal_doc_is_not_mandatory_globally
old_value = Setting.legal_document_is_mandatory
Setting.legal_document_is_mandatory = false
assert_not @registrar.legaldoc_mandatory?
Setting.legal_document_is_mandatory = old_value
end
private
def valid_registrar
@ -209,4 +359,4 @@ class RegistrarTest < ActiveSupport::TestCase
Registry.current.vat_country = Country.new(:us)
registrar
end
end
end

View file

@ -1,6 +1,16 @@
require 'test_helper'
class RegistryTest < ActiveSupport::TestCase
setup do
@original_registry_vat_rate = Setting.registry_vat_prc
@original_registry_country_code = Setting.registry_country_code
end
teardown do
Setting.registry_vat_prc = @original_registry_vat_rate
Setting.registry_country_code = @original_registry_country_code
end
def test_returns_current_registry
Setting.registry_vat_prc = 0.2
Setting.registry_country_code = 'US'

View file

@ -0,0 +1,120 @@
require 'test_helper'
class SettingEntryTest < ActiveSupport::TestCase
def setup
@new_setting = SettingEntry.new(code: 'new_setting', value: 'looks great', format: 'string', group: 'other')
end
def test_fixture_is_valid
assert setting_entries(:legal_document_is_mandatory).valid?
end
def test_can_be_retrieved_via_class_method
setting = setting_entries(:legal_document_is_mandatory)
assert setting.retrieve, Setting.legal_document_is_mandatory
end
def test_can_be_updated_via_class_method
setting = setting_entries(:legal_document_is_mandatory)
setting.update(value: 'false')
setting.reload
Setting.legal_document_is_mandatory = true
setting.reload
assert true, setting.retrieve
end
def test_setting_code_is_required
assert @new_setting.valid?
@new_setting.code = nil
assert_not @new_setting.valid?
end
def test_setting_code_can_only_include_underscore_and_characters
assert @new_setting.valid?
@new_setting.code = 'a b'
assert_not @new_setting.valid?
@new_setting.code = 'ab_'
assert_not @new_setting.valid?
@new_setting.code = '_ab'
assert_not @new_setting.valid?
@new_setting.code = '1_2'
assert_not @new_setting.valid?
@new_setting.code = 'a_b'
assert @new_setting.valid?
end
def test_setting_value_can_be_nil
assert @new_setting.valid?
@new_setting.value = nil
assert @new_setting.valid?
end
def test_setting_format_is_required
assert @new_setting.valid?
@new_setting.format = nil
assert_not @new_setting.valid?
@new_setting.format = 'nonexistant'
assert_not @new_setting.valid?
end
def test_setting_group_is_required
assert @new_setting.valid?
@new_setting.group = nil
assert_not @new_setting.valid?
@new_setting.group = 'random'
assert @new_setting.valid?
end
def test_returns_nil_for_unknown_setting
assert_nil Setting.unknown_and_definitely_not_saved_setting
end
def test_throws_error_if_updating_unknown_setting
assert_raises ActiveRecord::RecordNotFound do
Setting.unknown_and_definitely_not_saved_setting = 'hope it fails'
end
end
def test_parses_string_format
Setting.create(code: 'string_format', value: '1', format: 'string', group: 'random')
assert Setting.string_format.is_a? String
end
def test_parses_integer_format
Setting.create(code: 'integer_format', value: '1', format: 'integer', group: 'random')
assert Setting.integer_format.is_a? Integer
end
def test_parses_float_format
Setting.create(code: 'float_format', value: '0.5', format: 'float', group: 'random')
assert Setting.float_format.is_a? Float
end
def test_parses_boolean_format
Setting.create(code: 'boolean_format', value: 'true', format: 'boolean', group: 'random')
assert_equal true, Setting.boolean_format
Setting.boolean_format = 'false'
assert_equal false, Setting.boolean_format
Setting.boolean_format = nil
assert_equal false, Setting.boolean_format
end
def test_parses_hash_format
Setting.create(code: 'hash_format', value: '{"hello": "there"}', format: 'hash', group: 'random')
assert Setting.hash_format.is_a? Hash
end
def test_parses_array_format
Setting.create(code: 'array_format', value: '[1, 2, 3]', format: 'array', group: 'random')
assert Setting.array_format.is_a? Array
end
end

View file

@ -0,0 +1,54 @@
require 'test_helper'
class WhiteIpTest < ActiveSupport::TestCase
def test_either_ipv4_or_ipv6_is_required
white_ip = valid_white_ip
white_ip.ipv4 = ''
white_ip.ipv6 = ''
assert white_ip.invalid?
assert_includes white_ip.errors.full_messages, 'IPv4 or IPv6 must be present'
white_ip.ipv4 = valid_ipv4
white_ip.ipv6 = ''
assert white_ip.valid?
white_ip.ipv4 = ''
white_ip.ipv6 = valid_ipv6
assert white_ip.valid?
end
def test_validates_ipv4_format
white_ip = valid_white_ip
white_ip.ipv4 = 'invalid'
assert white_ip.invalid?
white_ip.ipv4 = valid_ipv4
assert white_ip.valid?
end
def test_validates_ipv6_format
white_ip = valid_white_ip
white_ip.ipv6 = 'invalid'
assert white_ip.invalid?
white_ip.ipv6 = valid_ipv6
assert white_ip.valid?
end
private
def valid_white_ip
white_ips(:one)
end
def valid_ipv4
'192.0.2.1'
end
def valid_ipv6
'2001:db8::1'
end
end

View file

@ -7,12 +7,12 @@ class Whois::RecordTest < ActiveSupport::TestCase
@whois_record = whois_records(:one)
@auction = auctions(:one)
@original_disclaimer_setting = Setting.registry_whois_disclaimer
@original_disclaimer = Setting.registry_whois_disclaimer
Setting.registry_whois_disclaimer = 'disclaimer'
end
teardown do
Setting.registry_whois_disclaimer = @original_disclaimer_setting
Setting.registry_whois_disclaimer = @original_disclaimer
end
def test_reads_disclaimer_setting
@ -40,24 +40,36 @@ class Whois::RecordTest < ActiveSupport::TestCase
end
def test_updates_whois_record_from_auction_when_awaiting_payment
@auction.update!(domain: 'domain.test', status: Auction.statuses[:awaiting_payment])
@auction.update!(domain: 'domain.test',
status: Auction.statuses[:awaiting_payment],
registration_deadline: registration_deadline)
@whois_record.update!(name: 'domain.test')
@whois_record.update_from_auction(@auction)
@whois_record.reload
assert_equal ({ 'name' => 'domain.test',
'status' => ['PendingRegistration'],
'disclaimer' => 'disclaimer' }), @whois_record.json
'disclaimer' => 'disclaimer',
'registration_deadline' => registration_deadline.try(:to_s, :iso8601) }),
@whois_record.json
end
def test_updates_whois_record_from_auction_when_payment_received
@auction.update!(domain: 'domain.test', status: Auction.statuses[:payment_received])
@auction.update!(domain: 'domain.test',
status: Auction.statuses[:payment_received],
registration_deadline: registration_deadline)
@whois_record.update!(name: 'domain.test')
@whois_record.update_from_auction(@auction)
@whois_record.reload
assert_equal ({ 'name' => 'domain.test',
'status' => ['PendingRegistration'],
'disclaimer' => 'disclaimer' }), @whois_record.json
'disclaimer' => 'disclaimer',
'registration_deadline' => registration_deadline.try(:to_s, :iso8601) }),
@whois_record.json
end
end
def registration_deadline
Time.zone.now + 10.days
end
end