mirror of
https://github.com/internetee/registry.git
synced 2025-08-15 14:03:49 +02:00
Support only JSON
This commit is contained in:
parent
d695d95ad7
commit
8425481091
2 changed files with 15 additions and 10 deletions
|
@ -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)
|
||||||
|
|
|
@ -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