mirror of
https://github.com/internetee/registry.git
synced 2025-07-23 03:06:14 +02:00
parent
4f51f6c736
commit
d6d20a81a9
5 changed files with 108 additions and 23 deletions
73
test/models/registrar/vat_test.rb
Normal file
73
test/models/registrar/vat_test.rb
Normal file
|
@ -0,0 +1,73 @@
|
|||
require 'test_helper'
|
||||
|
||||
class RegistrarVATTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
@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_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?
|
||||
|
||||
@registrar.vat_rate = nil
|
||||
assert @registrar.valid?
|
||||
end
|
||||
|
||||
def test_vat_is_not_applied_when_registrar_is_foreign_vat_payer_and_vat_no_is_present
|
||||
@registrar.vat_no = 'valid'
|
||||
|
||||
Registry.instance.stub(:legal_address_country, Country.new('GB')) do
|
||||
@registrar.vat_rate = 1
|
||||
assert @registrar.invalid?
|
||||
|
||||
@registrar.vat_rate = nil
|
||||
assert @registrar.valid?
|
||||
end
|
||||
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.reload
|
||||
assert_equal 25.5, @registrar.vat_rate
|
||||
end
|
||||
|
||||
def test_treats_empty_vat_rate_as_absent
|
||||
@registrar.vat_rate = ''
|
||||
assert_nil @registrar.vat_rate
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue