mirror of
https://github.com/internetee/registry.git
synced 2025-06-11 15:14:47 +02:00
parent
cee51e1ac5
commit
0f6a47d73d
47 changed files with 644 additions and 640 deletions
|
@ -1,30 +0,0 @@
|
|||
require 'test_helper'
|
||||
|
||||
class RegistrarsControllerTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
login_as users(:admin)
|
||||
@registrar = registrars(:bestnames)
|
||||
end
|
||||
|
||||
def test_updates_website
|
||||
patch admin_registrar_path(@registrar), registrar: @registrar.attributes.merge(website: 'new.example.com')
|
||||
@registrar.reload
|
||||
|
||||
assert_equal 'new.example.com', @registrar.website
|
||||
end
|
||||
|
||||
def test_updates_email
|
||||
patch admin_registrar_path(@registrar), registrar: @registrar.attributes.merge(email: 'new@example.com')
|
||||
@registrar.reload
|
||||
|
||||
assert_equal 'new@example.com', @registrar.email
|
||||
end
|
||||
|
||||
def test_updates_billing_email
|
||||
patch admin_registrar_path(@registrar),
|
||||
registrar: @registrar.attributes.merge(billing_email: 'new-billing@example.com')
|
||||
@registrar.reload
|
||||
|
||||
assert_equal 'new-billing@example.com', @registrar.billing_email
|
||||
end
|
||||
end
|
6
test/fixtures/accounts.yml
vendored
6
test/fixtures/accounts.yml
vendored
|
@ -3,3 +3,9 @@ cash:
|
|||
balance: 100
|
||||
currency: EUR
|
||||
registrar: bestnames
|
||||
|
||||
not_in_use_cash:
|
||||
account_type: cash
|
||||
balance: 0
|
||||
currency: EUR
|
||||
registrar: not_in_use
|
||||
|
|
13
test/fixtures/registrars.yml
vendored
13
test/fixtures/registrars.yml
vendored
|
@ -3,6 +3,10 @@ bestnames:
|
|||
reg_no: 1234
|
||||
code: bestnames
|
||||
email: info@bestnames.test
|
||||
street: Main Street
|
||||
zip: 12345
|
||||
city: New York
|
||||
state: New York
|
||||
country_code: US
|
||||
accounting_customer_code: bestnames
|
||||
language: en
|
||||
|
@ -16,3 +20,12 @@ goodnames:
|
|||
country_code: US
|
||||
accounting_customer_code: goodnames
|
||||
language: en
|
||||
|
||||
not_in_use:
|
||||
name: any
|
||||
reg_no: any
|
||||
code: any
|
||||
email: any@example.com
|
||||
country_code: US
|
||||
accounting_customer_code: any
|
||||
language: en
|
||||
|
|
30
test/integration/admin/registrars/delete_test.rb
Normal file
30
test/integration/admin/registrars/delete_test.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
require 'test_helper'
|
||||
|
||||
class AdminAreaDeleteRegistrarTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
login_as users(:admin)
|
||||
end
|
||||
|
||||
def test_can_be_deleted_when_not_in_use
|
||||
visit admin_registrar_url(registrars(:not_in_use))
|
||||
|
||||
assert_difference 'Registrar.count', -1 do
|
||||
click_link_or_button 'Delete'
|
||||
end
|
||||
|
||||
assert_current_path admin_registrars_path
|
||||
assert_text 'Registrar has been successfully deleted'
|
||||
end
|
||||
|
||||
def test_cannot_be_deleted_when_in_use
|
||||
registrar = registrars(:bestnames)
|
||||
visit admin_registrar_url(registrar)
|
||||
|
||||
assert_no_difference 'Registrar.count' do
|
||||
click_link_or_button 'Delete'
|
||||
end
|
||||
|
||||
assert_current_path admin_registrar_path(registrar)
|
||||
assert_text 'Cannot delete record because dependent domains exist'
|
||||
end
|
||||
end
|
|
@ -1,17 +0,0 @@
|
|||
require 'test_helper'
|
||||
|
||||
class EditRegistrarTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
login_as users(:admin)
|
||||
@registrar = registrars(:bestnames)
|
||||
end
|
||||
|
||||
def test_updates_registrar
|
||||
visit admin_registrar_path(@registrar)
|
||||
click_link_or_button 'Edit'
|
||||
click_link_or_button 'Update registrar'
|
||||
|
||||
assert_current_path admin_registrar_path(@registrar)
|
||||
assert_text 'Registrar has been successfully updated'
|
||||
end
|
||||
end
|
69
test/integration/admin/registrars/edit_test.rb
Normal file
69
test/integration/admin/registrars/edit_test.rb
Normal file
|
@ -0,0 +1,69 @@
|
|||
require 'test_helper'
|
||||
|
||||
class AdminAreaEditRegistrarTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
login_as users(:admin)
|
||||
@registrar = registrars(:bestnames)
|
||||
end
|
||||
|
||||
def test_attributes_update
|
||||
visit admin_registrar_path(@registrar)
|
||||
click_link_or_button 'Edit'
|
||||
|
||||
fill_in 'Name', with: 'new name'
|
||||
fill_in 'Reg no', with: '4727673'
|
||||
fill_in 'Contact phone', with: '2570937'
|
||||
fill_in 'Website', with: 'http://new.example.com'
|
||||
fill_in 'Contact e-mail', with: 'new@example.com'
|
||||
|
||||
fill_in 'Street', with: 'new street'
|
||||
fill_in 'Zip', with: 'new zip'
|
||||
fill_in 'City', with: 'new city'
|
||||
fill_in 'State / Province', with: 'new state'
|
||||
select 'Germany', from: 'Country'
|
||||
|
||||
fill_in 'VAT number', with: '2386449'
|
||||
fill_in 'Accounting customer code', with: '866477'
|
||||
fill_in 'Billing email', with: 'new-billing@example.com'
|
||||
|
||||
select 'Estonian', from: 'Language'
|
||||
click_link_or_button 'Update registrar'
|
||||
|
||||
@registrar.reload
|
||||
assert_equal 'new name', @registrar.name
|
||||
assert_equal '4727673', @registrar.reg_no
|
||||
assert_equal '2570937', @registrar.phone
|
||||
assert_equal 'http://new.example.com', @registrar.website
|
||||
assert_equal 'new@example.com', @registrar.email
|
||||
|
||||
assert_equal 'new street', @registrar.street
|
||||
assert_equal 'new zip', @registrar.zip
|
||||
assert_equal 'new city', @registrar.city
|
||||
assert_equal 'new state', @registrar.state
|
||||
assert_equal Country.new('DE'), @registrar.country
|
||||
|
||||
assert_equal '2386449', @registrar.vat_no
|
||||
assert_equal '866477', @registrar.accounting_customer_code
|
||||
assert_equal 'new-billing@example.com', @registrar.billing_email
|
||||
|
||||
assert_equal 'et', @registrar.language
|
||||
assert_current_path admin_registrar_path(@registrar)
|
||||
assert_text 'Registrar has been successfully updated'
|
||||
end
|
||||
|
||||
def test_code_cannot_be_changed
|
||||
visit admin_registrar_path(@registrar)
|
||||
click_link_or_button 'Edit'
|
||||
assert_no_field 'Code'
|
||||
end
|
||||
|
||||
def test_fails_gracefully
|
||||
visit admin_registrar_path(@registrar)
|
||||
click_link_or_button 'Edit'
|
||||
fill_in 'Name', with: 'Good Names'
|
||||
click_link_or_button 'Update registrar'
|
||||
|
||||
assert_field 'Name', with: 'Good Names'
|
||||
assert_text 'Name has already been taken'
|
||||
end
|
||||
end
|
|
@ -1,23 +0,0 @@
|
|||
require 'test_helper'
|
||||
|
||||
class NewRegistrarTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
login_as users(:admin)
|
||||
end
|
||||
|
||||
def test_creates_registrar
|
||||
visit admin_registrars_path
|
||||
click_link_or_button 'New registrar'
|
||||
|
||||
fill_in 'registrar[name]', with: 'John Doe'
|
||||
fill_in 'registrar[reg_no]', with: '1234567'
|
||||
fill_in 'registrar[email]', with: 'test@test.com'
|
||||
fill_in 'registrar[code]', with: 'test'
|
||||
fill_in 'registrar[accounting_customer_code]', with: 'test'
|
||||
click_link_or_button 'Create registrar'
|
||||
|
||||
assert_current_path admin_registrar_path(Registrar.last)
|
||||
assert_text 'Registrar has been successfully created'
|
||||
assert_text 'John Doe'
|
||||
end
|
||||
end
|
49
test/integration/admin/registrars/new_test.rb
Normal file
49
test/integration/admin/registrars/new_test.rb
Normal file
|
@ -0,0 +1,49 @@
|
|||
require 'test_helper'
|
||||
|
||||
class AdminAreaNewRegistrarTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
login_as users(:admin)
|
||||
end
|
||||
|
||||
def test_new_registrar_creation_with_required_params
|
||||
visit admin_registrars_url
|
||||
click_link_or_button 'New registrar'
|
||||
|
||||
fill_in 'Name', with: 'Brand new names'
|
||||
fill_in 'Reg no', with: '55555555'
|
||||
fill_in 'Contact e-mail', with: 'test@example.com'
|
||||
fill_in 'Accounting customer code', with: 'test'
|
||||
fill_in 'Code', with: 'test'
|
||||
|
||||
assert_difference 'Registrar.count' do
|
||||
click_link_or_button 'Create registrar'
|
||||
end
|
||||
|
||||
assert_current_path admin_registrar_path(Registrar.last)
|
||||
assert_text 'Registrar has been successfully created'
|
||||
end
|
||||
|
||||
def test_fails_gracefully
|
||||
visit admin_registrars_url
|
||||
click_link_or_button 'New registrar'
|
||||
|
||||
fill_in 'Name', with: 'Best Names'
|
||||
fill_in 'Reg no', with: '55555555'
|
||||
fill_in 'Contact e-mail', with: 'test@example.com'
|
||||
fill_in 'Accounting customer code', with: 'test'
|
||||
fill_in 'Code', with: 'test'
|
||||
|
||||
assert_no_difference 'Registrar.count' do
|
||||
click_link_or_button 'Create registrar'
|
||||
end
|
||||
assert_field 'Name', with: 'Best Names'
|
||||
assert_text 'Name has already been taken'
|
||||
end
|
||||
|
||||
def test_pre_populated_default_language
|
||||
Setting.default_language = 'en'
|
||||
visit admin_registrars_url
|
||||
click_link_or_button 'New registrar'
|
||||
assert_field 'Language', with: 'en'
|
||||
end
|
||||
end
|
29
test/models/registrar/code_test.rb
Normal file
29
test/models/registrar/code_test.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
require 'test_helper'
|
||||
|
||||
class RegistrarCodeTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
@registrar = registrars(:bestnames).dup
|
||||
end
|
||||
|
||||
def test_registrar_is_invalid_without_code
|
||||
@registrar.code = ''
|
||||
assert @registrar.invalid?
|
||||
end
|
||||
|
||||
def test_special_code_validation
|
||||
@registrar.code = 'CID'
|
||||
assert @registrar.invalid?
|
||||
assert_includes @registrar.errors.full_messages, 'Code is forbidden'
|
||||
end
|
||||
|
||||
def test_cannot_be_changed_once_registrar_is_created
|
||||
registrar = registrars(:bestnames)
|
||||
registrar.update!(code: 'new-code')
|
||||
refute_equal 'new-code', registrar.code
|
||||
end
|
||||
|
||||
def test_normalization
|
||||
@registrar.code = 'with spaces:and:colon.'
|
||||
assert_equal 'WITHSPACESANDCOLON.', @registrar.code
|
||||
end
|
||||
end
|
37
test/models/registrar/delete_test.rb
Normal file
37
test/models/registrar/delete_test.rb
Normal file
|
@ -0,0 +1,37 @@
|
|||
require 'test_helper'
|
||||
|
||||
class DeleteRegistrarTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
@registrar = registrars(:not_in_use)
|
||||
end
|
||||
|
||||
def test_can_be_deleted_if_not_in_use
|
||||
assert_difference 'Registrar.count', -1 do
|
||||
@registrar.destroy
|
||||
end
|
||||
end
|
||||
|
||||
def test_cannot_be_deleted_if_has_at_least_one_user
|
||||
users(:api_bestnames).update!(registrar: @registrar)
|
||||
|
||||
assert_no_difference 'Registrar.count' do
|
||||
@registrar.destroy
|
||||
end
|
||||
end
|
||||
|
||||
def test_cannot_be_deleted_if_has_at_least_one_contact
|
||||
contacts(:john).update!(registrar: @registrar)
|
||||
|
||||
assert_no_difference 'Registrar.count' do
|
||||
@registrar.destroy
|
||||
end
|
||||
end
|
||||
|
||||
def test_cannot_be_deleted_if_has_at_least_one_domain
|
||||
domains(:shop).update!(registrar: @registrar)
|
||||
|
||||
assert_no_difference 'Registrar.count' do
|
||||
@registrar.destroy
|
||||
end
|
||||
end
|
||||
end
|
|
@ -9,21 +9,33 @@ class RegistrarTest < ActiveSupport::TestCase
|
|||
assert @registrar.valid?
|
||||
end
|
||||
|
||||
def test_rejects_absent_accounting_customer_code
|
||||
@registrar.accounting_customer_code = nil
|
||||
@registrar.validate
|
||||
def test_invalid_without_name
|
||||
@registrar.name = ''
|
||||
assert @registrar.invalid?
|
||||
end
|
||||
|
||||
def test_invalid_without_reg_no
|
||||
@registrar.reg_no = ''
|
||||
assert @registrar.invalid?
|
||||
end
|
||||
|
||||
def test_invalid_without_email
|
||||
@registrar.email = ''
|
||||
assert @registrar.invalid?
|
||||
end
|
||||
|
||||
def test_invalid_without_accounting_customer_code
|
||||
@registrar.accounting_customer_code = ''
|
||||
assert @registrar.invalid?
|
||||
end
|
||||
|
||||
def test_requires_country_code
|
||||
@registrar.country_code = nil
|
||||
@registrar.validate
|
||||
@registrar.country_code = ''
|
||||
assert @registrar.invalid?
|
||||
end
|
||||
|
||||
def test_requires_language
|
||||
@registrar.language = nil
|
||||
@registrar.validate
|
||||
def test_invalid_without_language
|
||||
@registrar.language = ''
|
||||
assert @registrar.invalid?
|
||||
end
|
||||
|
||||
|
@ -38,4 +50,13 @@ class RegistrarTest < ActiveSupport::TestCase
|
|||
registrar = Registrar.new(language: 'de')
|
||||
assert_equal 'de', registrar.language
|
||||
end
|
||||
|
||||
def test_full_address
|
||||
assert_equal 'Main Street, New York, New York, 12345', @registrar.address
|
||||
end
|
||||
|
||||
def test_reference_number_generation
|
||||
@registrar.validate
|
||||
refute_empty @registrar.reference_no
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue