mirror of
https://github.com/internetee/registry.git
synced 2025-06-10 06:34:46 +02:00
Merge branch 'master' into credit-and-debit-card-payments
This commit is contained in:
commit
eda6772c6f
112 changed files with 887 additions and 438 deletions
|
@ -1,7 +1,7 @@
|
|||
require 'test_helper'
|
||||
|
||||
class ContactTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
setup do
|
||||
@contact = contacts(:john)
|
||||
end
|
||||
|
||||
|
|
|
@ -12,11 +12,16 @@ class ContactIdenticalTest < ActiveSupport::TestCase
|
|||
org_name
|
||||
]
|
||||
|
||||
def setup
|
||||
setup do
|
||||
@original_address_processing = Setting.address_processing
|
||||
@contact = contacts(:william)
|
||||
@identical = contacts(:identical_to_william)
|
||||
end
|
||||
|
||||
teardown do
|
||||
Setting.address_processing = @original_address_processing
|
||||
end
|
||||
|
||||
def test_returns_identical
|
||||
assert_equal @identical, @contact.identical(@identical.registrar)
|
||||
end
|
||||
|
@ -33,30 +38,24 @@ class ContactIdenticalTest < ActiveSupport::TestCase
|
|||
assert_nil @contact.identical(@identical.registrar)
|
||||
end
|
||||
|
||||
def test_takes_address_into_account_when_processing_enabled
|
||||
def test_takes_address_into_account_when_address_processing_is_on
|
||||
Setting.address_processing = true
|
||||
|
||||
Contact.address_attribute_names.each do |attribute|
|
||||
previous_value = @identical.public_send(attribute)
|
||||
@identical.update_attribute(attribute, 'other')
|
||||
|
||||
Contact.stub :address_processing?, true do
|
||||
assert_nil @contact.identical(@identical.registrar)
|
||||
end
|
||||
|
||||
assert_nil @contact.identical(@identical.registrar)
|
||||
@identical.update_attribute(attribute, previous_value)
|
||||
end
|
||||
end
|
||||
|
||||
def test_ignores_address_when_processing_disabled
|
||||
def test_ignores_address_when_address_processing_is_off
|
||||
Setting.address_processing = false
|
||||
|
||||
Contact.address_attribute_names.each do |attribute|
|
||||
previous_value = @identical.public_send(attribute)
|
||||
@identical.update_attribute(attribute, 'other')
|
||||
|
||||
Contact.stub :address_processing?, false do
|
||||
assert_equal @identical, @contact.identical(@identical.registrar)
|
||||
end
|
||||
|
||||
assert_equal @identical, @contact.identical(@identical.registrar)
|
||||
@identical.update_attribute(attribute, previous_value)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
require 'test_helper'
|
||||
|
||||
class ContactPostalAddressTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
setup do
|
||||
@original_address_processing = Setting.address_processing
|
||||
@contact = contacts(:john)
|
||||
end
|
||||
|
||||
teardown do
|
||||
Setting.address_processing = @original_address_processing
|
||||
end
|
||||
|
||||
def test_invalid_if_country_code_is_invalid_and_address_processing_is_on
|
||||
Setting.address_processing = true
|
||||
@contact.country_code = 'invalid'
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'test_helper'
|
||||
|
||||
class ContactTransferTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
setup do
|
||||
@contact = contacts(:john)
|
||||
@new_registrar = registrars(:goodnames)
|
||||
end
|
||||
|
|
14
test/models/domain/deletable_test.rb
Normal file
14
test/models/domain/deletable_test.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
require 'test_helper'
|
||||
|
||||
class DomainDeletableTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@domain = domains(:shop)
|
||||
end
|
||||
|
||||
def test_discard
|
||||
refute @domain.discarded?
|
||||
@domain.discard
|
||||
@domain.reload
|
||||
assert @domain.discarded?
|
||||
end
|
||||
end
|
|
@ -1,7 +1,7 @@
|
|||
require 'test_helper'
|
||||
|
||||
class DomainTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
setup do
|
||||
@domain = domains(:shop)
|
||||
end
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'test_helper'
|
||||
|
||||
class DomainTransferableTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
setup do
|
||||
@domain = domains(:shop)
|
||||
@new_registrar = registrars(:goodnames)
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'test_helper'
|
||||
|
||||
class DomainTransferTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
setup do
|
||||
@domain_transfer = domain_transfers(:shop)
|
||||
end
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'test_helper'
|
||||
|
||||
class EppSessionTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
setup do
|
||||
@epp_session = epp_sessions(:api_bestnames)
|
||||
end
|
||||
|
||||
|
|
109
test/models/invoice_test.rb
Normal file
109
test/models/invoice_test.rb
Normal file
|
@ -0,0 +1,109 @@
|
|||
require 'test_helper'
|
||||
|
||||
class InvoiceTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@invoice = invoices(:valid)
|
||||
end
|
||||
|
||||
def test_valid
|
||||
assert @invoice.valid?
|
||||
end
|
||||
|
||||
def test_optional_vat_rate
|
||||
@invoice.vat_rate = nil
|
||||
assert @invoice.valid?
|
||||
end
|
||||
|
||||
def test_vat_rate_validation
|
||||
@invoice.vat_rate = -1
|
||||
assert @invoice.invalid?
|
||||
|
||||
@invoice.vat_rate = 0
|
||||
assert @invoice.valid?
|
||||
|
||||
@invoice.vat_rate = 99.9
|
||||
assert @invoice.valid?
|
||||
|
||||
@invoice.vat_rate = 100
|
||||
assert @invoice.invalid?
|
||||
end
|
||||
|
||||
def test_serializes_and_deserializes_vat_rate
|
||||
invoice = @invoice.dup
|
||||
invoice.invoice_items = @invoice.invoice_items
|
||||
invoice.vat_rate = BigDecimal('25.5')
|
||||
invoice.save!
|
||||
invoice.reload
|
||||
assert_equal BigDecimal('25.5'), invoice.vat_rate
|
||||
end
|
||||
|
||||
def test_vat_rate_defaults_to_effective_vat_rate_of_a_registrar
|
||||
registrar = registrars(:bestnames)
|
||||
invoice = @invoice.dup
|
||||
invoice.vat_rate = nil
|
||||
invoice.buyer = registrar
|
||||
invoice.invoice_items = @invoice.invoice_items
|
||||
|
||||
registrar.stub(:effective_vat_rate, BigDecimal(55)) do
|
||||
invoice.save!
|
||||
end
|
||||
|
||||
assert_equal BigDecimal(55), invoice.vat_rate
|
||||
end
|
||||
|
||||
def test_vat_rate_cannot_be_updated
|
||||
@invoice.vat_rate = BigDecimal(21)
|
||||
@invoice.save!
|
||||
@invoice.reload
|
||||
refute_equal BigDecimal(21), @invoice.vat_rate
|
||||
end
|
||||
|
||||
def test_calculates_vat_amount
|
||||
assert_equal BigDecimal('1.5'), @invoice.vat_amount
|
||||
end
|
||||
|
||||
def test_vat_amount_is_zero_when_vat_rate_is_blank
|
||||
@invoice.vat_rate = nil
|
||||
assert_equal 0, @invoice.vat_amount
|
||||
end
|
||||
|
||||
def test_calculates_subtotal
|
||||
line_item = InvoiceItem.new
|
||||
invoice = Invoice.new(invoice_items: [line_item, line_item])
|
||||
|
||||
line_item.stub(:item_sum_without_vat, BigDecimal('2.5')) do
|
||||
assert_equal BigDecimal(5), invoice.subtotal
|
||||
end
|
||||
end
|
||||
|
||||
def test_returns_persisted_total
|
||||
assert_equal BigDecimal('16.50'), @invoice.total
|
||||
end
|
||||
|
||||
def test_calculates_total
|
||||
line_item = InvoiceItem.new
|
||||
invoice = Invoice.new
|
||||
invoice.vat_rate = 10
|
||||
invoice.invoice_items = [line_item, line_item]
|
||||
|
||||
line_item.stub(:item_sum_without_vat, BigDecimal('2.5')) do
|
||||
assert_equal BigDecimal('5.50'), invoice.total
|
||||
end
|
||||
end
|
||||
|
||||
def test_valid_without_buyer_vat_no
|
||||
@invoice.buyer_vat_no = ''
|
||||
assert @invoice.valid?
|
||||
end
|
||||
|
||||
def test_buyer_vat_no_is_taken_from_registrar_by_default
|
||||
registrar = registrars(:bestnames)
|
||||
registrar.vat_no = 'US1234'
|
||||
invoice = @invoice.dup
|
||||
invoice.buyer_vat_no = nil
|
||||
invoice.buyer = registrar
|
||||
invoice.invoice_items = @invoice.invoice_items
|
||||
invoice.save!
|
||||
assert_equal 'US1234', invoice.buyer_vat_no
|
||||
end
|
||||
end
|
|
@ -1,7 +1,7 @@
|
|||
require 'test_helper'
|
||||
|
||||
class MessageTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
setup do
|
||||
@message = messages(:greeting)
|
||||
end
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'test_helper'
|
||||
|
||||
class NameserverGlueRecordTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
setup do
|
||||
@nameserver = nameservers(:shop_ns1)
|
||||
end
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'test_helper'
|
||||
|
||||
class NameserverTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
setup do
|
||||
@nameserver = nameservers(:shop_ns1)
|
||||
end
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'test_helper'
|
||||
|
||||
class RegistrarCodeTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
setup do
|
||||
@registrar = registrars(:bestnames).dup
|
||||
end
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'test_helper'
|
||||
|
||||
class DeleteRegistrarTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
setup do
|
||||
@registrar = registrars(:not_in_use)
|
||||
end
|
||||
|
||||
|
|
97
test/models/registrar/vat_test.rb
Normal file
97
test/models/registrar/vat_test.rb
Normal file
|
@ -0,0 +1,97 @@
|
|||
require 'test_helper'
|
||||
|
||||
class RegistrarVATTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@registrar = registrars(:bestnames)
|
||||
end
|
||||
|
||||
def test_optional_vat_no
|
||||
@registrar.vat_no = ''
|
||||
assert @registrar.valid?
|
||||
|
||||
@registrar.vat_no = 'any'
|
||||
assert @registrar.valid?
|
||||
end
|
||||
|
||||
def test_apply_vat_rate_from_registry_when_registrar_is_local_vat_payer
|
||||
Setting.registry_country_code = 'US'
|
||||
@registrar.country_code = 'US'
|
||||
|
||||
Registry.instance.stub(:vat_rate, BigDecimal('5.5')) do
|
||||
assert_equal BigDecimal('5.5'), @registrar.effective_vat_rate
|
||||
end
|
||||
end
|
||||
|
||||
def test_require_no_vat_rate_when_registrar_is_local_vat_payer
|
||||
@registrar.vat_rate = 1
|
||||
assert @registrar.invalid?
|
||||
|
||||
@registrar.vat_rate = nil
|
||||
assert @registrar.valid?
|
||||
end
|
||||
|
||||
def test_apply_vat_rate_from_registrar_when_registrar_is_foreign_vat_payer
|
||||
Setting.registry_country_code = 'US'
|
||||
@registrar.country_code = 'DE'
|
||||
@registrar.vat_rate = BigDecimal('5.6')
|
||||
assert_equal BigDecimal('5.6'), @registrar.effective_vat_rate
|
||||
end
|
||||
|
||||
def test_require_vat_rate_when_registrar_is_foreign_vat_payer_and_vat_no_is_absent
|
||||
@registrar.country_code = 'DE'
|
||||
@registrar.vat_no = ''
|
||||
|
||||
@registrar.vat_rate = ''
|
||||
assert @registrar.invalid?
|
||||
assert @registrar.errors.added?(:vat_rate, :blank)
|
||||
|
||||
@registrar.vat_rate = 5
|
||||
assert @registrar.valid?
|
||||
end
|
||||
|
||||
def test_require_no_vat_rate_when_registrar_is_foreign_vat_payer_and_vat_no_is_present
|
||||
@registrar.country_code = 'DE'
|
||||
@registrar.vat_no = 'valid'
|
||||
|
||||
@registrar.vat_rate = 1
|
||||
assert @registrar.invalid?
|
||||
|
||||
@registrar.vat_rate = nil
|
||||
assert @registrar.valid?
|
||||
end
|
||||
|
||||
def test_vat_rate_validation
|
||||
@registrar.country_code = 'DE'
|
||||
@registrar.vat_no = ''
|
||||
|
||||
@registrar.vat_rate = -1
|
||||
assert @registrar.invalid?
|
||||
|
||||
@registrar.vat_rate = 0
|
||||
assert @registrar.valid?
|
||||
|
||||
@registrar.vat_rate = 99.9
|
||||
assert @registrar.valid?
|
||||
|
||||
@registrar.vat_rate = 100
|
||||
assert @registrar.invalid?
|
||||
end
|
||||
|
||||
def test_serializes_and_deserializes_vat_rate
|
||||
@registrar.country_code = 'DE'
|
||||
@registrar.vat_rate = BigDecimal('25.5')
|
||||
@registrar.save!
|
||||
@registrar.reload
|
||||
assert_equal BigDecimal('25.5'), @registrar.vat_rate
|
||||
end
|
||||
|
||||
def test_parses_vat_rate_as_a_string
|
||||
@registrar.vat_rate = '25.5'
|
||||
assert_equal BigDecimal('25.5'), @registrar.vat_rate
|
||||
end
|
||||
|
||||
def test_treats_empty_vat_rate_as_nil
|
||||
@registrar.vat_rate = ''
|
||||
assert_nil @registrar.vat_rate
|
||||
end
|
||||
end
|
|
@ -1,7 +1,7 @@
|
|||
require 'test_helper'
|
||||
|
||||
class RegistrarTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
setup do
|
||||
@registrar = registrars(:bestnames)
|
||||
end
|
||||
|
||||
|
@ -29,7 +29,7 @@ class RegistrarTest < ActiveSupport::TestCase
|
|||
assert @registrar.invalid?
|
||||
end
|
||||
|
||||
def test_requires_country_code
|
||||
def test_invalid_without_country_code
|
||||
@registrar.country_code = ''
|
||||
assert @registrar.invalid?
|
||||
end
|
||||
|
|
16
test/models/registry_test.rb
Normal file
16
test/models/registry_test.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
require 'test_helper'
|
||||
|
||||
class RegistryTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@registry = Registry.send(:new)
|
||||
end
|
||||
|
||||
def test_implements_singleton
|
||||
assert_equal Registry.instance.object_id, Registry.instance.object_id
|
||||
end
|
||||
|
||||
def test_vat_rate
|
||||
Setting.registry_vat_prc = 0.25
|
||||
assert_equal BigDecimal(25), @registry.vat_rate
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue