mirror of
https://github.com/internetee/registry.git
synced 2025-06-11 07:04:47 +02:00
Merge branch 'master' into registry-790
This commit is contained in:
commit
c48cdf68b6
16 changed files with 918 additions and 56 deletions
117
test/integration/api/registrant/registrant_api_contacts_test.rb
Normal file
117
test/integration/api/registrant/registrant_api_contacts_test.rb
Normal file
|
@ -0,0 +1,117 @@
|
|||
require 'test_helper'
|
||||
require 'auth_token/auth_token_creator'
|
||||
|
||||
class RegistrantApiContactsTest < ApplicationIntegrationTest
|
||||
def setup
|
||||
super
|
||||
|
||||
@original_registry_time = Setting.days_to_keep_business_registry_cache
|
||||
Setting.days_to_keep_business_registry_cache = 1
|
||||
travel_to Time.zone.parse('2010-07-05')
|
||||
|
||||
@user = users(:registrant)
|
||||
@auth_headers = { 'HTTP_AUTHORIZATION' => auth_token }
|
||||
end
|
||||
|
||||
def teardown
|
||||
super
|
||||
|
||||
Setting.days_to_keep_business_registry_cache = @original_registry_time
|
||||
travel_back
|
||||
end
|
||||
|
||||
def test_root_returns_domain_list
|
||||
get '/api/v1/registrant/contacts', {}, @auth_headers
|
||||
assert_equal(200, response.status)
|
||||
|
||||
json_body = JSON.parse(response.body, symbolize_names: true)
|
||||
assert_equal(5, json_body.count)
|
||||
array_of_contact_codes = json_body.map { |x| x[:code] }
|
||||
assert(array_of_contact_codes.include?('william-001'))
|
||||
assert(array_of_contact_codes.include?('jane-001'))
|
||||
end
|
||||
|
||||
def test_root_accepts_limit_and_offset_parameters
|
||||
get '/api/v1/registrant/contacts', { 'limit' => 1, 'offset' => 0 }, @auth_headers
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
assert_equal(200, response.status)
|
||||
assert_equal(1, response_json.count)
|
||||
|
||||
get '/api/v1/registrant/contacts', {}, @auth_headers
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
assert_equal(5, response_json.count)
|
||||
end
|
||||
|
||||
def test_get_contact_details_by_uuid
|
||||
get '/api/v1/registrant/contacts/0aa54704-d6f7-4ca9-b8ca-2827d9a4e4eb', {}, @auth_headers
|
||||
assert_equal(200, response.status)
|
||||
|
||||
contact = JSON.parse(response.body, symbolize_names: true)
|
||||
assert_equal('william@inbox.test', contact[:email])
|
||||
end
|
||||
|
||||
def test_root_returns_503_when_business_registry_is_not_available
|
||||
raise_not_available = -> (a, b) { raise Soap::Arireg::NotAvailableError.new({}) }
|
||||
BusinessRegistryCache.stub :fetch_by_ident_and_cc, raise_not_available do
|
||||
get '/api/v1/registrant/contacts', {}, @auth_headers
|
||||
|
||||
assert_equal(503, response.status)
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
assert_equal({ errors: [base: ['Business Registry not available']] }, response_json)
|
||||
end
|
||||
end
|
||||
|
||||
def test_get_contact_details_by_uuid_returns_404_for_non_existent_contact
|
||||
get '/api/v1/registrant/contacts/nonexistent-uuid', {}, @auth_headers
|
||||
assert_equal(404, response.status)
|
||||
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
assert_equal({ errors: [{ base: ['Contact not found'] }] }, response_json)
|
||||
end
|
||||
|
||||
def test_root_does_not_accept_limit_higher_than_200
|
||||
get '/api/v1/registrant/contacts', { 'limit' => 400, 'offset' => 0 }, @auth_headers
|
||||
assert_equal(400, response.status)
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
assert_equal({ errors: [{ limit: ['parameter is out of range'] }] }, response_json)
|
||||
end
|
||||
|
||||
def test_root_does_not_accept_offset_lower_than_0
|
||||
get '/api/v1/registrant/contacts', { 'limit' => 200, 'offset' => "-10" }, @auth_headers
|
||||
assert_equal(400, response.status)
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
assert_equal({ errors: [{ offset: ['parameter is out of range'] }] }, response_json)
|
||||
end
|
||||
|
||||
def test_root_returns_401_without_authorization
|
||||
get '/api/v1/registrant/contacts', {}, {}
|
||||
assert_equal(401, response.status)
|
||||
json_body = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_equal({ errors: [base: ['Not authorized']] }, json_body)
|
||||
end
|
||||
|
||||
def test_details_returns_401_without_authorization
|
||||
get '/api/v1/registrant/contacts/c0a191d5-3793-4f0b-8f85-491612d0293e', {}, {}
|
||||
assert_equal(401, response.status)
|
||||
json_body = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_equal({ errors: [base: ['Not authorized']] }, json_body)
|
||||
end
|
||||
|
||||
def test_details_returns_404_for_non_existent_contact
|
||||
get '/api/v1/registrant/contacts/some-random-uuid', {}, @auth_headers
|
||||
assert_equal(404, response.status)
|
||||
json_body = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_equal({ errors: [base: ['Contact not found']] }, json_body)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def auth_token
|
||||
token_creator = AuthTokenCreator.create_with_defaults(@user)
|
||||
hash = token_creator.token_in_hash
|
||||
"Bearer #{hash[:access_token]}"
|
||||
end
|
||||
end
|
59
test/models/deposit_test.rb
Normal file
59
test/models/deposit_test.rb
Normal file
|
@ -0,0 +1,59 @@
|
|||
require 'test_helper'
|
||||
|
||||
class DepositTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
super
|
||||
|
||||
@deposit = Deposit.new(registrar: registrars(:bestnames))
|
||||
@minimum_deposit = Setting.minimum_deposit
|
||||
Setting.minimum_deposit = 1.00
|
||||
end
|
||||
|
||||
def teardown
|
||||
super
|
||||
|
||||
Setting.minimum_deposit = @minimum_deposit
|
||||
end
|
||||
|
||||
def test_validate_amount_cannot_be_lower_than_0_01
|
||||
Setting.minimum_deposit = 0.0
|
||||
@deposit.amount = -10
|
||||
refute(@deposit.valid?)
|
||||
assert(@deposit.errors.full_messages.include?("Amount is too small. Minimum deposit is 0.01 EUR"))
|
||||
end
|
||||
|
||||
def test_validate_amount_cannot_be_lower_than_minimum_deposit
|
||||
@deposit.amount = 0.10
|
||||
refute(@deposit.valid?)
|
||||
|
||||
assert(@deposit.errors.full_messages.include?("Amount is too small. Minimum deposit is 1.0 EUR"))
|
||||
end
|
||||
|
||||
def test_registrar_must_be_set
|
||||
deposit = Deposit.new(amount: 120)
|
||||
refute(deposit.valid?)
|
||||
|
||||
assert(deposit.errors.full_messages.include?("Registrar is missing"))
|
||||
end
|
||||
|
||||
def test_amount_is_converted_from_string
|
||||
@deposit.amount = "12.00"
|
||||
assert_equal(BigDecimal.new("12.00"), @deposit.amount)
|
||||
|
||||
@deposit.amount = "12,11"
|
||||
assert_equal(BigDecimal.new("12.11"), @deposit.amount)
|
||||
end
|
||||
|
||||
def test_amount_is_converted_from_float
|
||||
@deposit.amount = 12.0044
|
||||
assert_equal(BigDecimal.new("12.0044"), @deposit.amount)
|
||||
|
||||
@deposit.amount = 12.0144
|
||||
assert_equal(BigDecimal.new("12.0144"), @deposit.amount)
|
||||
end
|
||||
|
||||
def test_amount_is_converted_from_nil
|
||||
@deposit.amount = nil
|
||||
assert_equal(BigDecimal.new("0.00"), @deposit.amount)
|
||||
end
|
||||
end
|
|
@ -29,11 +29,10 @@ class NewInvoiceTest < ApplicationSystemTestCase
|
|||
assert_text 'Pay invoice'
|
||||
end
|
||||
|
||||
# This test case should fail once issue #651 gets fixed
|
||||
def test_create_new_invoice_with_amount_0_goes_through
|
||||
def test_create_new_invoice_with_comma_in_number
|
||||
visit registrar_invoices_path
|
||||
click_link_or_button 'Add deposit'
|
||||
fill_in 'Amount', with: '0.00'
|
||||
fill_in 'Amount', with: '200,00'
|
||||
fill_in 'Description', with: 'My first invoice'
|
||||
|
||||
assert_difference 'Invoice.count', 1 do
|
||||
|
@ -42,7 +41,33 @@ class NewInvoiceTest < ApplicationSystemTestCase
|
|||
|
||||
assert_text 'Please pay the following invoice'
|
||||
assert_text 'Invoice no. 131050'
|
||||
assert_text 'Subtotal 0,00 €'
|
||||
assert_text 'Subtotal 200,00 €'
|
||||
assert_text 'Pay invoice'
|
||||
end
|
||||
|
||||
def test_create_new_invoice_fails_when_amount_is_0
|
||||
visit registrar_invoices_path
|
||||
click_link_or_button 'Add deposit'
|
||||
fill_in 'Amount', with: '0.00'
|
||||
fill_in 'Description', with: 'My first invoice'
|
||||
|
||||
assert_no_difference 'Invoice.count' do
|
||||
click_link_or_button 'Add'
|
||||
end
|
||||
|
||||
assert_text 'Amount is too small. Minimum deposit is 0.01 EUR'
|
||||
end
|
||||
|
||||
def test_create_new_invoice_fails_when_amount_is_negative
|
||||
visit registrar_invoices_path
|
||||
click_link_or_button 'Add deposit'
|
||||
fill_in 'Amount', with: '-120.00'
|
||||
fill_in 'Description', with: 'My first invoice'
|
||||
|
||||
assert_no_difference 'Invoice.count' do
|
||||
click_link_or_button 'Add'
|
||||
end
|
||||
|
||||
assert_text 'Amount is too small. Minimum deposit is 0.01 EUR'
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue