mirror of
https://github.com/internetee/registry.git
synced 2025-07-20 09:46:09 +02:00
Wrote test for admin users
This commit is contained in:
parent
3cefaedd4d
commit
0c1c015fc9
4 changed files with 164 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
|||
require 'test_helper'
|
||||
require 'auth_token/auth_token_creator'
|
||||
require 'json'
|
||||
|
||||
CompanyRegisterClientStub = Struct.new(:any_method) do
|
||||
def representation_rights(citizen_personal_code:, citizen_country_code:)
|
||||
|
@ -55,6 +56,42 @@ class RegistrantApiV1ContactListTest < ActionDispatch::IntegrationTest
|
|||
assert_equal '1234', response_json.first[:ident][:code]
|
||||
end
|
||||
|
||||
def test_out_of_range_limit
|
||||
get api_v1_registrant_contacts_path + "?limit=300", as: :json, headers: { 'HTTP_AUTHORIZATION' => auth_token }
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
text_response = JSON.pretty_generate(response_json[:errors][0][:limit][0])
|
||||
|
||||
assert_equal text_response, '"parameter is out of range"'
|
||||
end
|
||||
|
||||
def test_negative_offset
|
||||
get api_v1_registrant_contacts_path + "?offset=-300", as: :json, headers: { 'HTTP_AUTHORIZATION' => auth_token }
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
text_response = JSON.pretty_generate(response_json[:errors][0][:offset][0])
|
||||
|
||||
assert_equal text_response, '"parameter is out of range"'
|
||||
end
|
||||
|
||||
def test_show_valid_contact
|
||||
get api_v1_registrant_contacts_path + "/eb2f2766-b44c-4e14-9f16-32ab1a7cb957", as: :json, headers: { 'HTTP_AUTHORIZATION' => auth_token }
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
text_response = response_json[:name]
|
||||
|
||||
assert_equal @contact[:name], text_response
|
||||
end
|
||||
|
||||
def test_show_invalid_contact
|
||||
get api_v1_registrant_contacts_path + "/435", as: :json, headers: { 'HTTP_AUTHORIZATION' => auth_token }
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
text_response = response_json[:errors][0][:base][0]
|
||||
|
||||
assert_equal text_response, 'Contact not found'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def delete_direct_contact
|
||||
|
|
|
@ -4,11 +4,12 @@ require 'auth_token/auth_token_creator'
|
|||
class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@contact = contacts(:john)
|
||||
@contact_org = contacts(:acme_ltd)
|
||||
|
||||
@original_address_processing = Setting.address_processing
|
||||
@original_fax_enabled_setting = ENV['fax_enabled']
|
||||
|
||||
@user = users(:registrant)
|
||||
|
||||
end
|
||||
|
||||
teardown do
|
||||
|
@ -90,6 +91,32 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest
|
|||
@contact.address
|
||||
end
|
||||
|
||||
def test_update_address_when_enabled_without_address_params
|
||||
Setting.address_processing = true
|
||||
|
||||
patch api_v1_registrant_contact_path(@contact.uuid), params: { address: { } },
|
||||
as: :json,
|
||||
headers: { 'HTTP_AUTHORIZATION' => auth_token }
|
||||
|
||||
assert_response :bad_request
|
||||
@contact.reload
|
||||
assert_equal Contact::Address.new(nil, nil, nil, nil, nil),
|
||||
@contact.address
|
||||
end
|
||||
|
||||
def test_update_address_when_enabled_without_address_params
|
||||
Setting.address_processing = true
|
||||
|
||||
patch api_v1_registrant_contact_path(@contact.uuid), params: { },
|
||||
as: :json,
|
||||
headers: { 'HTTP_AUTHORIZATION' => auth_token }
|
||||
|
||||
assert_response :bad_request
|
||||
@contact.reload
|
||||
assert_equal Contact::Address.new(nil, nil, nil, nil, nil),
|
||||
@contact.address
|
||||
end
|
||||
|
||||
def test_address_is_optional_when_enabled
|
||||
Setting.address_processing = true
|
||||
@contact.update!(street: 'any', zip: 'any', city: 'any', state: 'any', country_code: 'US')
|
||||
|
@ -211,6 +238,21 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest
|
|||
symbolize_names: true)
|
||||
end
|
||||
|
||||
def test_org_disclosed_attributes
|
||||
patch api_v1_registrant_contact_path(@contact_org.uuid), params: { disclosed_attributes: ["some_attr"] },
|
||||
as: :json,
|
||||
headers: { 'HTTP_AUTHORIZATION' => auth_token }
|
||||
|
||||
assert_response :bad_request
|
||||
|
||||
err_msg = "Legal person's data is visible by default and cannot be concealed. Please remove this parameter."
|
||||
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
response_msg = response_json[:errors][0][:disclosed_attributes][0]
|
||||
|
||||
assert_equal err_msg, response_msg
|
||||
end
|
||||
|
||||
def test_unmanaged_contact_cannot_be_updated
|
||||
assert_equal 'US-1234', @user.registrant_ident
|
||||
@contact.update!(ident: '12345')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue