mirror of
https://github.com/internetee/registry.git
synced 2025-06-10 22:54:47 +02:00
parent
3d107bd198
commit
b68fe6e312
16 changed files with 110 additions and 92 deletions
3
test/fixtures/invoices.yml
vendored
3
test/fixtures/invoices.yml
vendored
|
@ -7,6 +7,7 @@ DEFAULTS: &DEFAULTS
|
|||
buyer: bestnames
|
||||
buyer_name: Jane Doe
|
||||
vat_rate: 0.1
|
||||
total: 16.50
|
||||
|
||||
valid:
|
||||
<<: *DEFAULTS
|
||||
|
@ -21,7 +22,7 @@ cancelled:
|
|||
|
||||
paid:
|
||||
<<: *DEFAULTS
|
||||
sum_cache: 1
|
||||
total: 1
|
||||
|
||||
outstanding:
|
||||
<<: *DEFAULTS
|
||||
|
|
|
@ -6,19 +6,20 @@ class BalanceTopUpTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
|
||||
def test_creates_new_invoice
|
||||
Setting.registry_vat_prc = 0.1
|
||||
|
||||
visit registrar_invoices_url
|
||||
click_link_or_button 'Add deposit'
|
||||
fill_in 'Amount', with: '25.5'
|
||||
|
||||
Registry.instance.stub(:vat_rate, 10) do
|
||||
assert_difference 'Invoice.count' do
|
||||
click_link_or_button 'Add'
|
||||
end
|
||||
assert_difference 'Invoice.count' do
|
||||
click_link_or_button 'Add'
|
||||
end
|
||||
|
||||
invoice = Invoice.last
|
||||
|
||||
assert_equal BigDecimal('28.05'), invoice.sum_cache
|
||||
assert_equal BigDecimal(10), invoice.vat_rate
|
||||
assert_equal BigDecimal('28.05'), invoice.total
|
||||
assert_text 'Please pay the following invoice'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,56 +0,0 @@
|
|||
require 'test_helper'
|
||||
|
||||
class InvoiceVATRateTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
@invoice = invoices(: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
|
||||
end
|
|
@ -9,15 +9,81 @@ class InvoiceTest < ActiveSupport::TestCase
|
|||
assert @invoice.valid?
|
||||
end
|
||||
|
||||
def test_calculates_subtotal
|
||||
assert_equal BigDecimal('15'), @invoice.sum_without_vat
|
||||
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
|
||||
end
|
||||
|
||||
def test_vat_amount_is_zero_when_vat_rate_is_blank
|
||||
@invoice.vat_rate = nil
|
||||
assert_equal 0, @invoice.vat
|
||||
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_calculates_total
|
||||
assert_equal BigDecimal('16.5'), @invoice.sum
|
||||
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
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue