Merge branch 'master' into credit-and-debit-card-payments

This commit is contained in:
Maciej Szlosarczyk 2018-04-18 13:44:03 +03:00
commit eda6772c6f
No known key found for this signature in database
GPG key ID: 41D62D42D3B0D765
112 changed files with 887 additions and 438 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,16 @@
require 'test_helper'
class AdminAreaDomainDetailsTest < ActionDispatch::IntegrationTest
setup do
login_as users(:admin)
@domain = domains(:shop)
end
def test_discarded_domain_has_corresponding_label
visit admin_domain_url(@domain)
assert_no_css 'span.label.label-warning', text: 'deleteCandidate'
@domain.discard
visit admin_domain_url(@domain)
assert_css 'span.label.label-warning', text: 'deleteCandidate'
end
end

View file

@ -3,7 +3,7 @@ require 'test_helper'
class AdminAreaDomainForceDeleteTest < ActionDispatch::IntegrationTest
include ActionMailer::TestHelper
def setup
setup do
login_as users(:admin)
@domain = domains(:shop)
ActionMailer::Base.deliveries.clear

View file

@ -1,7 +1,7 @@
require 'test_helper'
class AdminDomainsTestTest < ActionDispatch::IntegrationTest
def setup
setup do
login_as users(:admin)
end

View 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

View file

@ -1,7 +1,7 @@
require 'test_helper'
class AdminAreaDeleteRegistrarTest < ActionDispatch::IntegrationTest
def setup
setup do
login_as users(:admin)
end

View 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

View file

@ -1,7 +1,7 @@
require 'test_helper'
class AdminAreaEditRegistrarTest < ActionDispatch::IntegrationTest
def setup
setup do
login_as users(:admin)
@registrar = registrars(:bestnames)
end

View file

@ -1,7 +1,7 @@
require 'test_helper'
class AdminAreaNewRegistrarTest < ActionDispatch::IntegrationTest
def setup
setup do
login_as users(:admin)
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'

View file

@ -1,19 +0,0 @@
require 'test_helper'
class ShowRegistrarTest < ActionDispatch::IntegrationTest
include ActionView::Helpers::NumberHelper
def setup
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

View file

@ -1,7 +1,7 @@
require 'test_helper'
class APIDomainTransfersTest < ActionDispatch::IntegrationTest
def setup
setup do
@domain = domains(:shop)
@new_registrar = registrars(:goodnames)
Setting.transfer_wait_time = 0 # Auto-approval

View file

@ -1,7 +1,7 @@
require 'test_helper'
class EppDomainCreateTransferCodeTest < ActionDispatch::IntegrationTest
def setup
setup do
travel_to Time.zone.parse('2010-07-05')
end

View file

@ -25,4 +25,31 @@ class EppDomainDeleteTest < ActionDispatch::IntegrationTest
assert_equal '1001', Nokogiri::XML(response.body).at_css('result')[:code]
assert_equal 1, Nokogiri::XML(response.body).css('result').size
end
def test_discarded_domain_cannot_be_deleted
domains(:shop).discard
request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<delete>
<domain:delete xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>shop.test</domain:name>
</domain:delete>
</delete>
<extension>
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
<eis:legalDocument type="pdf">dGVzdCBmYWlsCg==</eis:legalDocument>
</eis:extdata>
</extension>
</command>
</epp>
XML
assert_no_difference 'Domain.count' do
post '/epp/command/delete', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
end
assert_equal '2105', Nokogiri::XML(response.body).at_css('result')[:code]
end
end

View file

@ -3,7 +3,7 @@ require 'test_helper'
class EppDomainRenewTest < ActionDispatch::IntegrationTest
self.use_transactional_fixtures = false
def setup
setup do
travel_to Time.zone.parse('2010-07-05')
end

View file

@ -1,7 +1,7 @@
require 'test_helper'
class EppDomainUpdateTest < ActionDispatch::IntegrationTest
def test_overwrites_existing
def test_update_domain
request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
@ -20,9 +20,29 @@ class EppDomainUpdateTest < ActionDispatch::IntegrationTest
</epp>
XML
post '/epp/command/update', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_bestnames' }
post '/epp/command/update', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
assert_equal 'f0ff7d17b0', domains(:shop).transfer_code
assert_equal '1000', Nokogiri::XML(response.body).at_css('result')[:code]
assert_equal 1, Nokogiri::XML(response.body).css('result').size
end
def test_discarded_domain_cannot_be_updated
domains(:shop).discard
request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<update>
<domain:update xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>shop.test</domain:name>
</domain:update>
</update>
</command>
</epp>
XML
post '/epp/command/update', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
assert_equal '2105', Nokogiri::XML(response.body).at_css('result')[:code]
end
end

View file

@ -1,7 +1,7 @@
require 'test_helper'
class EppDomainTransferRequestTest < ActionDispatch::IntegrationTest
def setup
setup do
@domain = domains(:shop)
@new_registrar = registrars(:goodnames)
Setting.transfer_wait_time = 0

View file

@ -1,7 +1,7 @@
require 'test_helper'
class EppLoginSessionLimitTest < ActionDispatch::IntegrationTest
def setup
setup do
travel_to Time.zone.parse('2010-07-05')
EppSession.delete_all
end

View file

@ -1,7 +1,7 @@
require 'test_helper'
class RegistrantDomainsTest < ActionDispatch::IntegrationTest
def setup
setup do
login_as users(:registrant)
Setting.days_to_keep_business_registry_cache = 1

View 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

View file

@ -1,7 +1,7 @@
require 'test_helper'
class RegistrarDomainTransfersTest < ActionDispatch::IntegrationTest
def setup
setup do
WebMock.reset!
login_as users(:api_goodnames)
end

View file

@ -1,7 +1,7 @@
require 'test_helper'
class RegistrarNameserverReplacementTest < ActionDispatch::IntegrationTest
def setup
setup do
WebMock.reset!
login_as users(:api_goodnames)
end

View file

@ -1,7 +1,7 @@
require 'test_helper'
class ContactTest < ActiveSupport::TestCase
def setup
setup do
@contact = contacts(:john)
end

View file

@ -12,11 +12,16 @@ class ContactIdenticalTest < ActiveSupport::TestCase
org_name
]
def setup
setup do
@original_address_processing = Setting.address_processing
@contact = contacts(:william)
@identical = contacts(:identical_to_william)
end
teardown do
Setting.address_processing = @original_address_processing
end
def test_returns_identical
assert_equal @identical, @contact.identical(@identical.registrar)
end
@ -33,30 +38,24 @@ class ContactIdenticalTest < ActiveSupport::TestCase
assert_nil @contact.identical(@identical.registrar)
end
def test_takes_address_into_account_when_processing_enabled
def test_takes_address_into_account_when_address_processing_is_on
Setting.address_processing = true
Contact.address_attribute_names.each do |attribute|
previous_value = @identical.public_send(attribute)
@identical.update_attribute(attribute, 'other')
Contact.stub :address_processing?, true do
assert_nil @contact.identical(@identical.registrar)
end
assert_nil @contact.identical(@identical.registrar)
@identical.update_attribute(attribute, previous_value)
end
end
def test_ignores_address_when_processing_disabled
def test_ignores_address_when_address_processing_is_off
Setting.address_processing = false
Contact.address_attribute_names.each do |attribute|
previous_value = @identical.public_send(attribute)
@identical.update_attribute(attribute, 'other')
Contact.stub :address_processing?, false do
assert_equal @identical, @contact.identical(@identical.registrar)
end
assert_equal @identical, @contact.identical(@identical.registrar)
@identical.update_attribute(attribute, previous_value)
end
end

View file

@ -1,10 +1,15 @@
require 'test_helper'
class ContactPostalAddressTest < ActiveSupport::TestCase
def setup
setup do
@original_address_processing = Setting.address_processing
@contact = contacts(:john)
end
teardown do
Setting.address_processing = @original_address_processing
end
def test_invalid_if_country_code_is_invalid_and_address_processing_is_on
Setting.address_processing = true
@contact.country_code = 'invalid'

View file

@ -1,7 +1,7 @@
require 'test_helper'
class ContactTransferTest < ActiveSupport::TestCase
def setup
setup do
@contact = contacts(:john)
@new_registrar = registrars(:goodnames)
end

View file

@ -0,0 +1,14 @@
require 'test_helper'
class DomainDeletableTest < ActiveSupport::TestCase
setup do
@domain = domains(:shop)
end
def test_discard
refute @domain.discarded?
@domain.discard
@domain.reload
assert @domain.discarded?
end
end

View file

@ -1,7 +1,7 @@
require 'test_helper'
class DomainTest < ActiveSupport::TestCase
def setup
setup do
@domain = domains(:shop)
end

View file

@ -1,7 +1,7 @@
require 'test_helper'
class DomainTransferableTest < ActiveSupport::TestCase
def setup
setup do
@domain = domains(:shop)
@new_registrar = registrars(:goodnames)
end

View file

@ -1,7 +1,7 @@
require 'test_helper'
class DomainTransferTest < ActiveSupport::TestCase
def setup
setup do
@domain_transfer = domain_transfers(:shop)
end

View file

@ -1,7 +1,7 @@
require 'test_helper'
class EppSessionTest < ActiveSupport::TestCase
def setup
setup do
@epp_session = epp_sessions(:api_bestnames)
end

109
test/models/invoice_test.rb Normal file
View 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

View file

@ -1,7 +1,7 @@
require 'test_helper'
class MessageTest < ActiveSupport::TestCase
def setup
setup do
@message = messages(:greeting)
end

View file

@ -1,7 +1,7 @@
require 'test_helper'
class NameserverGlueRecordTest < ActiveSupport::TestCase
def setup
setup do
@nameserver = nameservers(:shop_ns1)
end

View file

@ -1,7 +1,7 @@
require 'test_helper'
class NameserverTest < ActiveSupport::TestCase
def setup
setup do
@nameserver = nameservers(:shop_ns1)
end

View file

@ -1,7 +1,7 @@
require 'test_helper'
class RegistrarCodeTest < ActiveSupport::TestCase
def setup
setup do
@registrar = registrars(:bestnames).dup
end

View file

@ -1,7 +1,7 @@
require 'test_helper'
class DeleteRegistrarTest < ActiveSupport::TestCase
def setup
setup do
@registrar = registrars(:not_in_use)
end

View 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

View file

@ -1,7 +1,7 @@
require 'test_helper'
class RegistrarTest < ActiveSupport::TestCase
def setup
setup do
@registrar = registrars(:bestnames)
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

View 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

View file

@ -14,12 +14,17 @@ 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
ActiveRecord::Migration.check_pending!
fixtures :all
teardown do
travel_back
end
end
class ActionDispatch::IntegrationTest
@ -28,7 +33,7 @@ class ActionDispatch::IntegrationTest
include Capybara::Minitest::Assertions
include AbstractController::Translation
def teardown
teardown do
Warden.test_reset!
WebMock.reset!
Capybara.reset_sessions!