vat_rate/test/test_vat_rate.rb

44 lines
1.3 KiB
Ruby
Raw Permalink Normal View History

2024-11-12 14:37:26 +01:00
require 'minitest/autorun'
require 'vat_rate'
class TestVatRate < Minitest::Test
def test_should_check_data
assert_kind_of Hash, VatRate::RATES
VatRate::CATEGORIES.each do |category|
VatRate::RATES["#{category}_rates"].each do |country, rates|
assert_kind_of String, country
assert_kind_of Array, rates
rates.each do |rate|
assert rate.key?('rate')
assert_kind_of Numeric, rate['rate']
assert_kind_of Date, rate['from'] if rate['from']
end
end
end
end
def test_should_initialize_rate
vat_rate = VatRate.new(country: :FR)
assert_equal 20, vat_rate.rate
vat_rate = VatRate.new(country: "FR")
assert_equal 20, vat_rate.rate
end
def test_should_get_correct_rate_for_date
vat_rate = VatRate.new(country: "FR", date: Date.new(2011))
assert_equal 19.6, vat_rate.rate
end
def test_should_get_amounts
vat_rate = VatRate.new(country: "FR")
assert_equal 20, vat_rate.rate
assert_equal 40, vat_rate.vat_amount(200)
assert_equal 40, vat_rate.vat_amount(200, has_vat: false)
assert_equal 40, vat_rate.vat_amount(240, has_vat: true)
assert_equal 240, vat_rate.amount_with_vat(200)
assert_equal 200, vat_rate.amount_without_vat(240)
end
end