mirror of
https://github.com/internetee/registry.git
synced 2025-06-10 14:44:47 +02:00
Merge branch 'master' into registry-662
This commit is contained in:
commit
4bae19b66d
61 changed files with 644 additions and 225 deletions
18
test/fixtures/invoice_items.yml
vendored
18
test/fixtures/invoice_items.yml
vendored
|
@ -1,13 +1,13 @@
|
|||
DEFAULTS: &DEFAULTS
|
||||
one:
|
||||
description: Acme services
|
||||
price: 5
|
||||
amount: 1
|
||||
unit: pc
|
||||
invoice: valid
|
||||
|
||||
two:
|
||||
description: Acme services
|
||||
price: 5
|
||||
amount: 2
|
||||
unit: pc
|
||||
price: 5
|
||||
|
||||
valid:
|
||||
<<: *DEFAULTS
|
||||
invoice: valid
|
||||
|
||||
another:
|
||||
<<: *DEFAULTS
|
||||
invoice: valid
|
||||
|
|
7
test/fixtures/invoices.yml
vendored
7
test/fixtures/invoices.yml
vendored
|
@ -1,12 +1,13 @@
|
|||
DEFAULTS: &DEFAULTS
|
||||
created_at: <%= Date.parse '2010-07-05' %>
|
||||
due_date: <%= Date.parse '2010-07-06' %>
|
||||
invoice_type: DEB
|
||||
currency: EUR
|
||||
seller_name: John Doe
|
||||
seller_iban: 1234
|
||||
buyer: bestnames
|
||||
buyer_name: Jane Doe
|
||||
vat_prc: 0.2
|
||||
vat_rate: 0.1
|
||||
total: 16.50
|
||||
|
||||
valid:
|
||||
<<: *DEFAULTS
|
||||
|
@ -21,7 +22,7 @@ cancelled:
|
|||
|
||||
paid:
|
||||
<<: *DEFAULTS
|
||||
sum_cache: 1
|
||||
total: 1
|
||||
|
||||
outstanding:
|
||||
<<: *DEFAULTS
|
||||
|
|
23
test/fixtures/registrars.yml
vendored
23
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
|
||||
|
||||
|
@ -29,3 +30,23 @@ not_in_use:
|
|||
country_code: US
|
||||
accounting_customer_code: any
|
||||
language: en
|
||||
|
||||
complete:
|
||||
name: Complete Names
|
||||
reg_no: 123456
|
||||
code: completenames
|
||||
email: completenames@example.com
|
||||
country_code: US
|
||||
accounting_customer_code: US0001
|
||||
language: en
|
||||
vat_no: US12345
|
||||
vat_rate: 0.05
|
||||
|
||||
not_in_use:
|
||||
name: any
|
||||
reg_no: any
|
||||
code: any
|
||||
email: any@example.com
|
||||
country_code: US
|
||||
accounting_customer_code: any
|
||||
language: en
|
||||
|
|
14
test/integration/admin/mail_templates/new_test.rb
Normal file
14
test/integration/admin/mail_templates/new_test.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
require 'test_helper'
|
||||
|
||||
class AdminAreaNewMailTemplateTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
login_as users(:admin)
|
||||
end
|
||||
|
||||
def test_new_mail_template_does_not_throw_template_error
|
||||
visit admin_mail_templates_url
|
||||
click_link_or_button 'New'
|
||||
assert_text "HTML body"
|
||||
assert_text "New mail template"
|
||||
end
|
||||
end
|
18
test/integration/admin/registrars/details_test.rb
Normal file
18
test/integration/admin/registrars/details_test.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
require 'test_helper'
|
||||
|
||||
class AdminAreaRegistrarDetailsTest < ActionDispatch::IntegrationTest
|
||||
include ActionView::Helpers::NumberHelper
|
||||
|
||||
setup do
|
||||
login_as users(:admin)
|
||||
@registrar = registrars(:complete)
|
||||
end
|
||||
|
||||
def test_registrar_details
|
||||
visit admin_registrar_path(@registrar)
|
||||
assert_text 'Accounting customer code US0001'
|
||||
assert_text 'VAT number US12345'
|
||||
assert_text 'VAT rate 5.0%'
|
||||
assert_text 'Language English'
|
||||
end
|
||||
end
|
|
@ -12,6 +12,7 @@ class AdminAreaNewRegistrarTest < ActionDispatch::IntegrationTest
|
|||
fill_in 'Name', with: 'Brand new names'
|
||||
fill_in 'Reg no', with: '55555555'
|
||||
fill_in 'Contact e-mail', with: 'test@example.com'
|
||||
select 'United States', from: 'Country'
|
||||
fill_in 'Accounting customer code', with: 'test'
|
||||
fill_in 'Code', with: 'test'
|
||||
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
require 'test_helper'
|
||||
|
||||
class ShowRegistrarTest < ActionDispatch::IntegrationTest
|
||||
include ActionView::Helpers::NumberHelper
|
||||
|
||||
setup do
|
||||
login_as users(:admin)
|
||||
@registrar = registrars(:bestnames)
|
||||
visit admin_registrar_path(@registrar)
|
||||
end
|
||||
|
||||
def test_accounting_customer_code
|
||||
assert_text 'bestnames'
|
||||
end
|
||||
|
||||
def test_language
|
||||
assert_text 'Language English'
|
||||
end
|
||||
end
|
25
test/integration/registrar/billing/balance_top_up_test.rb
Normal file
25
test/integration/registrar/billing/balance_top_up_test.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
require 'test_helper'
|
||||
|
||||
class BalanceTopUpTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
login_as users(:api_bestnames)
|
||||
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'
|
||||
|
||||
assert_difference 'Invoice.count' do
|
||||
click_link_or_button 'Add'
|
||||
end
|
||||
|
||||
invoice = Invoice.last
|
||||
|
||||
assert_equal BigDecimal(10), invoice.vat_rate
|
||||
assert_equal BigDecimal('28.05'), invoice.total
|
||||
assert_text 'Please pay the following invoice'
|
||||
end
|
||||
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
|
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
|
|
@ -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
|
|
@ -14,6 +14,7 @@ require 'webmock/minitest'
|
|||
require 'support/rails5_assetions' # Remove once upgraded to Rails 5
|
||||
|
||||
Setting.address_processing = false
|
||||
Setting.registry_country_code = 'US'
|
||||
|
||||
class ActiveSupport::TestCase
|
||||
include FactoryBot::Syntax::Methods
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue