mirror of
https://github.com/internetee/registry.git
synced 2025-07-23 11:16:00 +02:00
Merge pull request #1058 from internetee/registry-992
Support JSON only
This commit is contained in:
commit
d07db9a6c3
6 changed files with 37 additions and 23 deletions
|
@ -53,7 +53,8 @@ module Api
|
||||||
|
|
||||||
if disclosed_attributes
|
if disclosed_attributes
|
||||||
if contact.org?
|
if contact.org?
|
||||||
error_msg = "Legal person's data cannot be concealed. Please remove this parameter."
|
error_msg = "Legal person's data is visible by default and cannot be concealed." \
|
||||||
|
' Please remove this parameter.'
|
||||||
render json: { errors: [{ disclosed_attributes: [error_msg] }] }, status: :bad_request
|
render json: { errors: [{ disclosed_attributes: [error_msg] }] }, status: :bad_request
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
|
@ -106,13 +106,15 @@ class Registrant::ContactsController < RegistrantController
|
||||||
|
|
||||||
def normalize_address_attributes_for_api(params)
|
def normalize_address_attributes_for_api(params)
|
||||||
normalized = params
|
normalized = params
|
||||||
|
address_parts = {}
|
||||||
|
|
||||||
Contact.address_attribute_names.each do |attr|
|
Contact.address_attribute_names.each do |attr|
|
||||||
attr = attr.to_sym
|
attr = attr.to_sym
|
||||||
normalized["address[#{attr}]"] = params[attr]
|
address_parts[attr] = params[attr]
|
||||||
normalized.delete(attr)
|
normalized.delete(attr)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
normalized[:address] = address_parts
|
||||||
normalized
|
normalized
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -120,7 +122,8 @@ class Registrant::ContactsController < RegistrantController
|
||||||
uri = URI.parse("#{ENV['registrant_api_base_url']}/api/v1/registrant/contacts/#{uuid}")
|
uri = URI.parse("#{ENV['registrant_api_base_url']}/api/v1/registrant/contacts/#{uuid}")
|
||||||
request = Net::HTTP::Patch.new(uri)
|
request = Net::HTTP::Patch.new(uri)
|
||||||
request['Authorization'] = "Bearer #{access_token}"
|
request['Authorization'] = "Bearer #{access_token}"
|
||||||
request.form_data = contact_update_api_params
|
request['Content-type'] = 'application/json'
|
||||||
|
request.body = contact_update_api_params.to_json
|
||||||
|
|
||||||
Net::HTTP.start(uri.hostname, uri.port, use_ssl: (uri.scheme == 'https')) do |http|
|
Net::HTTP.start(uri.hostname, uri.port, use_ssl: (uri.scheme == 'https')) do |http|
|
||||||
http.request(request)
|
http.request(request)
|
||||||
|
|
|
@ -12,4 +12,5 @@
|
||||||
|
|
||||||
ActiveSupport::Inflector.inflections(:en) do |inflect|
|
ActiveSupport::Inflector.inflections(:en) do |inflect|
|
||||||
inflect.acronym 'DNS'
|
inflect.acronym 'DNS'
|
||||||
|
inflect.irregular 'business_registry_cache', 'business_registry_caches'
|
||||||
end
|
end
|
||||||
|
|
5
test/fixtures/business_registry_caches.yml
vendored
5
test/fixtures/business_registry_caches.yml
vendored
|
@ -1,8 +1,7 @@
|
||||||
first:
|
one:
|
||||||
ident: 1234
|
ident: 1234
|
||||||
ident_country_code: US
|
ident_country_code: US
|
||||||
associated_businesses:
|
associated_businesses: []
|
||||||
- 1234
|
|
||||||
retrieved_on: 2010-07-05 10:30
|
retrieved_on: 2010-07-05 10:30
|
||||||
created_at: 2010-07-05 10:30
|
created_at: 2010-07-05 10:30
|
||||||
updated_at: 2010-07-05 10:30
|
updated_at: 2010-07-05 10:30
|
||||||
|
|
|
@ -9,6 +9,8 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest
|
||||||
@original_business_registry_cache_setting = Setting.days_to_keep_business_registry_cache
|
@original_business_registry_cache_setting = Setting.days_to_keep_business_registry_cache
|
||||||
@original_fax_enabled_setting = ENV['fax_enabled']
|
@original_fax_enabled_setting = ENV['fax_enabled']
|
||||||
|
|
||||||
|
@current_user = users(:registrant)
|
||||||
|
|
||||||
Setting.days_to_keep_business_registry_cache = 1
|
Setting.days_to_keep_business_registry_cache = 1
|
||||||
travel_to Time.zone.parse('2010-07-05')
|
travel_to Time.zone.parse('2010-07-05')
|
||||||
end
|
end
|
||||||
|
@ -157,19 +159,24 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest
|
||||||
assert_empty @contact.disclosed_attributes
|
assert_empty @contact.disclosed_attributes
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_legal_persons_data_cannot_be_concealed
|
def test_legal_persons_disclosed_attributes_cannot_be_changed
|
||||||
|
business_registry_caches(:one).update!(associated_businesses: %w[1234])
|
||||||
@contact.update!(ident_type: Contact::ORG,
|
@contact.update!(ident_type: Contact::ORG,
|
||||||
|
ident: '1234',
|
||||||
disclosed_attributes: %w[])
|
disclosed_attributes: %w[])
|
||||||
|
|
||||||
assert_no_changes -> { @contact.disclosed_attributes } do
|
assert_no_changes -> { @contact.disclosed_attributes } do
|
||||||
patch api_v1_registrant_contact_path(@contact.uuid), { disclosed_attributes: %w[name] }.to_json,
|
patch api_v1_registrant_contact_path(@contact.uuid), { disclosed_attributes: %w[name] }
|
||||||
|
.to_json,
|
||||||
'HTTP_AUTHORIZATION' => auth_token,
|
'HTTP_AUTHORIZATION' => auth_token,
|
||||||
'Accept' => Mime::JSON,
|
'Accept' => Mime::JSON,
|
||||||
'Content-Type' => Mime::JSON.to_s
|
'Content-Type' => Mime::JSON.to_s
|
||||||
@contact.reload
|
@contact.reload
|
||||||
end
|
end
|
||||||
assert_response :bad_request
|
assert_response :bad_request
|
||||||
error_msg = "Legal person's data cannot be concealed. Please remove this parameter."
|
|
||||||
|
error_msg = "Legal person's data is visible by default and cannot be concealed." \
|
||||||
|
' Please remove this parameter.'
|
||||||
assert_equal ({ errors: [{ disclosed_attributes: [error_msg] }] }),
|
assert_equal ({ errors: [{ disclosed_attributes: [error_msg] }] }),
|
||||||
JSON.parse(response.body, symbolize_names: true)
|
JSON.parse(response.body, symbolize_names: true)
|
||||||
end
|
end
|
||||||
|
@ -214,17 +221,18 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest
|
||||||
symbolize_names: true)
|
symbolize_names: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_contact_of_another_user_cannot_be_updated
|
def test_unmanaged_contact_cannot_be_updated
|
||||||
@contact = contacts(:jack)
|
@current_user.update!(registrant_ident: 'US-1234')
|
||||||
|
@contact.update!(ident: '12345')
|
||||||
|
|
||||||
patch api_v1_registrant_contact_path(@contact.uuid), { name: 'any' }.to_json,
|
patch api_v1_registrant_contact_path(@contact.uuid), { name: 'new name' }.to_json,
|
||||||
'HTTP_AUTHORIZATION' => auth_token,
|
'HTTP_AUTHORIZATION' => auth_token,
|
||||||
'Accept' => Mime::JSON,
|
'Accept' => Mime::JSON,
|
||||||
'Content-Type' => Mime::JSON.to_s
|
'Content-Type' => Mime::JSON.to_s
|
||||||
|
@contact.reload
|
||||||
|
|
||||||
assert_response :not_found
|
assert_response :not_found
|
||||||
@contact.reload
|
assert_not_equal 'new name', @contact.name
|
||||||
assert_not_equal 'any', @contact.name
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_non_existent_contact
|
def test_non_existent_contact
|
||||||
|
@ -244,7 +252,7 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest
|
||||||
private
|
private
|
||||||
|
|
||||||
def auth_token
|
def auth_token
|
||||||
token_creator = AuthTokenCreator.create_with_defaults(users(:registrant))
|
token_creator = AuthTokenCreator.create_with_defaults(@current_user)
|
||||||
hash = token_creator.token_in_hash
|
hash = token_creator.token_in_hash
|
||||||
"Bearer #{hash[:access_token]}"
|
"Bearer #{hash[:access_token]}"
|
||||||
end
|
end
|
||||||
|
|
|
@ -34,8 +34,9 @@ class RegistrantAreaContactUpdateTest < ApplicationIntegrationTest
|
||||||
def test_update_contact
|
def test_update_contact
|
||||||
stub_auth_request
|
stub_auth_request
|
||||||
|
|
||||||
request_body = { name: 'new name', email: 'new@inbox.test', phone: '+666.6' }
|
request_body = { name: 'new name', email: 'new@inbox.test', phone: '+666.6' }.to_json
|
||||||
headers = { 'Authorization' => 'Bearer test-access-token' }
|
headers = { 'Content-Type' => Mime::JSON,
|
||||||
|
'Authorization' => 'Bearer test-access-token' }
|
||||||
url = "https://api.test/api/v1/registrant/contacts/#{@contact.uuid}"
|
url = "https://api.test/api/v1/registrant/contacts/#{@contact.uuid}"
|
||||||
update_request_stub = stub_request(:patch, url).with(body: request_body, headers: headers)
|
update_request_stub = stub_request(:patch, url).with(body: request_body, headers: headers)
|
||||||
.to_return(body: '{}', status: 200)
|
.to_return(body: '{}', status: 200)
|
||||||
|
@ -104,17 +105,18 @@ class RegistrantAreaContactUpdateTest < ApplicationIntegrationTest
|
||||||
Setting.address_processing = true
|
Setting.address_processing = true
|
||||||
stub_auth_request
|
stub_auth_request
|
||||||
|
|
||||||
request_body = { email: 'john@inbox.test',
|
request_body = { name: 'John',
|
||||||
name: 'John',
|
email: 'john@inbox.test',
|
||||||
phone: '+555.555',
|
phone: '+555.555',
|
||||||
address: {
|
address: {
|
||||||
|
city: 'new city',
|
||||||
street: 'new street',
|
street: 'new street',
|
||||||
zip: '93742',
|
zip: '93742',
|
||||||
city: 'new city',
|
country_code: 'AT',
|
||||||
state: 'new state',
|
state: 'new state',
|
||||||
country_code: 'AT'
|
} }.to_json
|
||||||
} }
|
headers = { 'Content-type' => 'application/json',
|
||||||
headers = { 'Authorization' => 'Bearer test-access-token' }
|
'Authorization' => 'Bearer test-access-token' }
|
||||||
url = "https://api.test/api/v1/registrant/contacts/#{@contact.uuid}"
|
url = "https://api.test/api/v1/registrant/contacts/#{@contact.uuid}"
|
||||||
update_request_stub = stub_request(:patch, url).with(body: request_body, headers: headers)
|
update_request_stub = stub_request(:patch, url).with(body: request_body, headers: headers)
|
||||||
.to_return(body: '{}', status: 200)
|
.to_return(body: '{}', status: 200)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue