Use Estonian reference number format instead of ISO 11649

This commit is contained in:
Artur Beljajev 2018-10-01 13:43:50 +03:00
parent aa6e8f8a93
commit 5738c17731
25 changed files with 244 additions and 47 deletions

View file

@ -8,6 +8,7 @@ DEFAULTS: &DEFAULTS
buyer_name: Jane Doe
vat_rate: 0.1
total: 16.50
reference_no: 13
valid:
<<: *DEFAULTS

View file

@ -12,6 +12,7 @@ bestnames:
language: en
billing_email: billing@example.com
website: bestnames.test
reference_no: 13
goodnames:
name: Good Names
@ -22,6 +23,7 @@ goodnames:
vat_no: DE123456789
accounting_customer_code: goodnames
language: en
reference_no: 26
not_in_use:
name: any
@ -31,3 +33,4 @@ not_in_use:
country_code: US
accounting_customer_code: any
language: en
reference_no: 39

View file

@ -0,0 +1,50 @@
require 'test_helper'
class RegenerateRegistrarReferenceNumbersTaskTest < ActiveSupport::TestCase
def test_regenerates_registrar_reference_numbers_to_estonian_format
registrar = registrars(:bestnames)
registrar.update_column(:reference_no, 'RF1111')
capture_io { run_task }
registrar.reload
assert_not registrar.reference_no.start_with?('RF')
end
def test_does_not_regenerate_when_the_task_is_run_again
registrar = registrars(:bestnames)
registrar.update!(reference_no: '1111')
capture_io { run_task }
registrar.reload
assert_equal '1111', registrar.reference_no
end
def test_keeps_iso_reference_number_on_the_invoice_unchanged
registrar = registrars(:bestnames)
registrar.update_column(:reference_no, 'RF1111')
invoice = registrar.invoices.first
invoice.update!(reference_no: 'RF2222')
capture_io { run_task }
invoice.reload
assert_equal 'RF2222', invoice.reference_no
end
def test_output
registrar = registrars(:bestnames)
registrar.update_column(:reference_no, 'RF1111')
assert_output "Registrars processed: 1\n" do
run_task
end
end
private
def run_task
Rake::Task['data_migrations:regenerate_registrar_reference_numbers'].execute
end
end

View file

@ -0,0 +1,29 @@
require 'test_helper'
# https://www.pangaliit.ee/settlements-and-standards/reference-number-of-the-invoice
class ReferenceNoBaseTest < ActiveSupport::TestCase
def test_generates_random_base
assert_not_equal Billing::ReferenceNo::Base.generate, Billing::ReferenceNo::Base.generate
end
def test_randomly_generated_base_conforms_to_standard
base = Billing::ReferenceNo::Base.generate
format = /\A\d{1,19}\z/
assert_match format, base.to_s
end
def test_generates_check_digit_for_a_given_base
assert_equal 3, Billing::ReferenceNo::Base.new('1').check_digit
assert_equal 7, Billing::ReferenceNo::Base.new('1234567891234567891').check_digit
end
def test_returns_string_representation
base = Billing::ReferenceNo::Base.new('1')
assert_equal '1', base.to_s
end
def test_normalizes_non_string_values
base = Billing::ReferenceNo::Base.new(1)
assert_equal '1', base.to_s
end
end

View file

@ -0,0 +1,13 @@
require 'test_helper'
class ReferenceNoTest < ActiveSupport::TestCase
def test_returns_format_regexp
format = /\A\d{2,20}\z/
assert_equal format, Billing::ReferenceNo::REGEXP
end
def test_generated_reference_number_conforms_to_format
reference_no = Billing::ReferenceNo.generate
assert_match Billing::ReferenceNo::REGEXP, reference_no
end
end

View file

@ -6,7 +6,7 @@ class RegistrarTest < ActiveSupport::TestCase
end
def test_valid
assert @registrar.valid?
assert @registrar.valid?, proc { @registrar.errors.full_messages }
end
def test_invalid_without_name
@ -55,8 +55,28 @@ class RegistrarTest < ActiveSupport::TestCase
assert_equal 'Main Street, New York, New York, 12345', @registrar.address
end
def test_reference_number_generation
@registrar.validate
refute_empty @registrar.reference_no
def test_validates_reference_number_format
@registrar.reference_no = '1'
assert @registrar.invalid?
@registrar.reference_no = '11'
assert @registrar.valid?
@registrar.reference_no = '1' * 20
assert @registrar.valid?
@registrar.reference_no = '1' * 21
assert @registrar.invalid?
@registrar.reference_no = '1a'
assert @registrar.invalid?
end
def test_disallows_non_unique_reference_numbers
registrars(:bestnames).update!(reference_no: '1234')
assert_raises ActiveRecord::RecordNotUnique do
registrars(:goodnames).update!(reference_no: '1234')
end
end
end

View file

@ -17,9 +17,9 @@ class ContactVersionsTest < ApplicationSystemTestCase
def create_contact_with_history
sql = <<-SQL.squish
INSERT INTO registrars (id, name, reg_no, email, country_code, code,
accounting_customer_code, language)
accounting_customer_code, language, reference_no)
VALUES (75, 'test_registrar', 'test123', 'test@test.com', 'EE', 'TEST123',
'test123', 'en');
'test123', 'en', '1234');
INSERT INTO contacts (id, code, email, auth_info, registrar_id)
VALUES (75, 'test_code', 'test@inbox.test', '8b4d462aa04194ca78840a', 75);

View file

@ -17,9 +17,9 @@ class DomainVersionsTest < ApplicationSystemTestCase
def create_domain_with_history
sql = <<-SQL.squish
INSERT INTO registrars (id, name, reg_no, email, country_code, code,
accounting_customer_code, language)
accounting_customer_code, language, reference_no)
VALUES (54, 'test_registrar', 'test123', 'test@test.com', 'EE', 'TEST123',
'test123', 'en');
'test123', 'en', '1234');
INSERT INTO contacts (id, code, email, auth_info, registrar_id)
VALUES (54, 'test_code', 'test@inbox.test', '8b4d462aa04194ca78840a', 54);