mirror of
https://github.com/internetee/registry.git
synced 2025-06-11 07:04:47 +02:00
parent
026c36d066
commit
7d72d9cb34
8 changed files with 121 additions and 94 deletions
1
test/fixtures/invoices.yml
vendored
1
test/fixtures/invoices.yml
vendored
|
@ -4,6 +4,7 @@ DEFAULTS: &DEFAULTS
|
|||
currency: EUR
|
||||
seller_name: John Doe
|
||||
seller_iban: 1234
|
||||
buyer: bestnames
|
||||
buyer_name: Jane Doe
|
||||
vat_rate: 0.2
|
||||
|
||||
|
|
3
test/fixtures/registrars.yml
vendored
3
test/fixtures/registrars.yml
vendored
|
@ -17,7 +17,8 @@ goodnames:
|
|||
reg_no: 12345
|
||||
code: goodnames
|
||||
email: info@goodnames.test
|
||||
country_code: US
|
||||
country_code: DE
|
||||
vat_no: DE123456789
|
||||
accounting_customer_code: goodnames
|
||||
language: en
|
||||
|
||||
|
|
51
test/models/invoice/vat_rate_test.rb
Normal file
51
test/models/invoice/vat_rate_test.rb
Normal file
|
@ -0,0 +1,51 @@
|
|||
require 'test_helper'
|
||||
|
||||
class InvoiceVATRateTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
@invoice = invoices(:valid)
|
||||
end
|
||||
|
||||
def test_valid_without_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)
|
||||
|
||||
registrar.stub(:effective_vat_rate, 55) do
|
||||
invoice = Invoice.new(buyer: registrar)
|
||||
assert_equal 55, invoice.vat_rate
|
||||
end
|
||||
end
|
||||
|
||||
def test_vat_rate_cannot_be_updated
|
||||
@invoice.vat_rate = 21
|
||||
@invoice.save!
|
||||
@invoice.reload
|
||||
refute_equal 21, @invoice.vat_rate
|
||||
end
|
||||
end
|
|
@ -8,23 +8,4 @@ class InvoiceTest < ActiveSupport::TestCase
|
|||
def test_valid
|
||||
assert @invoice.valid?
|
||||
end
|
||||
|
||||
def test_valid_without_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 = 1
|
||||
assert @invoice.valid?
|
||||
|
||||
@invoice.vat_rate = 99.9
|
||||
assert @invoice.valid?
|
||||
|
||||
@invoice.vat_rate = 100
|
||||
assert @invoice.invalid?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,28 +13,6 @@ class RegistrarVATTest < ActiveSupport::TestCase
|
|||
assert @registrar.valid?
|
||||
end
|
||||
|
||||
def test_requires_vat_rate_when_registrar_is_foreign_vat_payer_and_vat_no_is_absent
|
||||
@registrar.vat_no = ''
|
||||
|
||||
Registry.instance.stub(:legal_address_country, Country.new('GB')) do
|
||||
@registrar.vat_rate = ''
|
||||
assert @registrar.invalid?
|
||||
assert @registrar.errors.added?(:vat_rate, :blank)
|
||||
|
||||
@registrar.vat_rate = -1
|
||||
assert @registrar.invalid?
|
||||
|
||||
@registrar.vat_rate = 1
|
||||
assert @registrar.valid?
|
||||
|
||||
@registrar.vat_rate = 99.9
|
||||
assert @registrar.valid?
|
||||
|
||||
@registrar.vat_rate = 100
|
||||
assert @registrar.invalid?
|
||||
end
|
||||
end
|
||||
|
||||
def test_vat_is_not_applied_when_registrar_is_local_vat_payer
|
||||
@registrar.vat_rate = 1
|
||||
assert @registrar.invalid?
|
||||
|
@ -43,30 +21,57 @@ class RegistrarVATTest < ActiveSupport::TestCase
|
|||
assert @registrar.valid?
|
||||
end
|
||||
|
||||
def test_requires_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)
|
||||
end
|
||||
|
||||
def test_vat_is_not_applied_when_registrar_is_foreign_vat_payer_and_vat_no_is_present
|
||||
@registrar.country_code = 'DE'
|
||||
@registrar.vat_no = 'valid'
|
||||
|
||||
Registry.instance.stub(:legal_address_country, Country.new('GB')) do
|
||||
@registrar.vat_rate = 1
|
||||
assert @registrar.invalid?
|
||||
@registrar.vat_rate = 1
|
||||
assert @registrar.invalid?
|
||||
|
||||
@registrar.vat_rate = nil
|
||||
assert @registrar.valid?
|
||||
end
|
||||
@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.vat_rate = '25.5'
|
||||
|
||||
Registry.instance.stub(:legal_address_country, Country.new('GB')) do
|
||||
@registrar.save!
|
||||
end
|
||||
|
||||
@registrar.country_code = 'DE'
|
||||
@registrar.vat_rate = BigDecimal('25.5')
|
||||
@registrar.save!
|
||||
@registrar.reload
|
||||
assert_equal 25.5, @registrar.vat_rate
|
||||
assert_equal BigDecimal('25.5'), @registrar.vat_rate
|
||||
end
|
||||
|
||||
def test_treats_empty_vat_rate_as_absent
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue