mirror of
https://github.com/internetee/registry.git
synced 2025-06-06 12:47:29 +02:00
parent
1eb13341a7
commit
4d0117431c
3 changed files with 56 additions and 35 deletions
|
@ -19,19 +19,15 @@ module Api
|
||||||
end
|
end
|
||||||
|
|
||||||
contacts = current_user_contacts.limit(limit).offset(offset)
|
contacts = current_user_contacts.limit(limit).offset(offset)
|
||||||
serialized_contacts = contacts.map do |item|
|
serialized_contacts = contacts.collect { |contact| serialize_contact(contact) }
|
||||||
serializer = Serializers::RegistrantApi::Contact.new(item)
|
|
||||||
serializer.to_json
|
|
||||||
end
|
|
||||||
|
|
||||||
render json: serialized_contacts
|
render json: serialized_contacts
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@contact = current_user_contacts.find_by(uuid: params[:uuid])
|
contact = current_user_contacts.find_by(uuid: params[:uuid])
|
||||||
|
|
||||||
if @contact
|
if contact
|
||||||
render json: @contact
|
render json: serialize_contact(contact)
|
||||||
else
|
else
|
||||||
render json: { errors: [{ base: ['Contact not found'] }] }, status: :not_found
|
render json: { errors: [{ base: ['Contact not found'] }] }, status: :not_found
|
||||||
end
|
end
|
||||||
|
@ -89,8 +85,7 @@ module Api
|
||||||
contact.registrar.notify(action)
|
contact.registrar.notify(action)
|
||||||
end
|
end
|
||||||
|
|
||||||
serializer = Serializers::RegistrantApi::Contact.new(contact)
|
render json: serialize_contact(contact)
|
||||||
render json: serializer.to_json
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -100,6 +95,10 @@ module Api
|
||||||
rescue CompanyRegister::NotAvailableError
|
rescue CompanyRegister::NotAvailableError
|
||||||
current_registrant_user.direct_contacts
|
current_registrant_user.direct_contacts
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def serialize_contact(contact)
|
||||||
|
Serializers::RegistrantApi::Contact.new(contact).to_json
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -32,14 +32,6 @@ class RegistrantApiContactsTest < ApplicationIntegrationTest
|
||||||
assert_equal 'john@inbox.test', response_json[:email]
|
assert_equal 'john@inbox.test', response_json[:email]
|
||||||
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
|
def test_root_does_not_accept_limit_higher_than_200
|
||||||
get '/api/v1/registrant/contacts', { 'limit' => 400, 'offset' => 0 }, @auth_headers
|
get '/api/v1/registrant/contacts', { 'limit' => 400, 'offset' => 0 }, @auth_headers
|
||||||
assert_equal(400, response.status)
|
assert_equal(400, response.status)
|
||||||
|
@ -62,22 +54,6 @@ class RegistrantApiContactsTest < ApplicationIntegrationTest
|
||||||
assert_equal({ errors: [base: ['Not authorized']] }, json_body)
|
assert_equal({ errors: [base: ['Not authorized']] }, json_body)
|
||||||
end
|
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
|
private
|
||||||
|
|
||||||
def auth_token
|
def auth_token
|
||||||
|
|
|
@ -13,6 +13,52 @@ class RegistrantApiV1ContactDetailsTest < ActionDispatch::IntegrationTest
|
||||||
@user = users(:registrant)
|
@user = users(:registrant)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_returns_contact_details
|
||||||
|
get api_v1_registrant_contact_path(@contact.uuid), nil, 'HTTP_AUTHORIZATION' => auth_token,
|
||||||
|
'Content-Type' => Mime::JSON.to_s
|
||||||
|
|
||||||
|
assert_response :ok
|
||||||
|
assert_equal ({ id: @contact.uuid,
|
||||||
|
name: @contact.name,
|
||||||
|
code: @contact.code,
|
||||||
|
fax: @contact.fax,
|
||||||
|
ident: {
|
||||||
|
code: @contact.ident,
|
||||||
|
type: @contact.ident_type,
|
||||||
|
country_code: @contact.ident_country_code,
|
||||||
|
},
|
||||||
|
email: @contact.email,
|
||||||
|
phone: @contact.phone,
|
||||||
|
address: {
|
||||||
|
street: @contact.street,
|
||||||
|
zip: @contact.zip,
|
||||||
|
city: @contact.city,
|
||||||
|
state: @contact.state,
|
||||||
|
country_code: @contact.country_code,
|
||||||
|
},
|
||||||
|
auth_info: @contact.auth_info,
|
||||||
|
statuses: @contact.statuses,
|
||||||
|
disclosed_attributes: @contact.disclosed_attributes }),
|
||||||
|
JSON.parse(response.body, symbolize_names: true)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_non_existent_contact
|
||||||
|
get api_v1_registrant_contact_path('non-existent'), nil, 'HTTP_AUTHORIZATION' => auth_token,
|
||||||
|
'Content-Type' => Mime::JSON.to_s
|
||||||
|
|
||||||
|
assert_response :not_found
|
||||||
|
assert_equal({ errors: [base: ['Contact not found']] }, JSON.parse(response.body,
|
||||||
|
symbolize_names: true))
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_anonymous_user
|
||||||
|
get api_v1_registrant_contact_path(@contact.uuid), nil, 'Content-Type' => Mime::JSON.to_s
|
||||||
|
|
||||||
|
assert_response :unauthorized
|
||||||
|
assert_equal({ errors: [base: ['Not authorized']] }, JSON.parse(response.body,
|
||||||
|
symbolize_names: true))
|
||||||
|
end
|
||||||
|
|
||||||
def test_returns_direct_contact_when_company_register_is_unavailable
|
def test_returns_direct_contact_when_company_register_is_unavailable
|
||||||
assert_equal '1234', @contact.ident
|
assert_equal '1234', @contact.ident
|
||||||
assert_equal Contact::PRIV, @contact.ident_type
|
assert_equal Contact::PRIV, @contact.ident_type
|
||||||
|
@ -25,7 +71,7 @@ class RegistrantApiV1ContactDetailsTest < ActionDispatch::IntegrationTest
|
||||||
end
|
end
|
||||||
|
|
||||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||||
assert_equal '1234', response_json[:ident]
|
assert_equal '1234', response_json[:ident][:code]
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_unmanaged_contact_cannot_be_accessed
|
def test_unmanaged_contact_cannot_be_accessed
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue