Support only JSON

This commit is contained in:
Artur Beljajev 2018-12-17 15:04:52 +02:00
parent d695d95ad7
commit 8425481091
2 changed files with 15 additions and 10 deletions

View file

@ -106,13 +106,15 @@ class Registrant::ContactsController < RegistrantController
def normalize_address_attributes_for_api(params)
normalized = params
address_parts = {}
Contact.address_attribute_names.each do |attr|
attr = attr.to_sym
normalized["address[#{attr}]"] = params[attr]
address_parts[attr] = params[attr]
normalized.delete(attr)
end
normalized[:address] = address_parts
normalized
end
@ -120,7 +122,8 @@ class Registrant::ContactsController < RegistrantController
uri = URI.parse("#{ENV['registrant_api_base_url']}/api/v1/registrant/contacts/#{uuid}")
request = Net::HTTP::Patch.new(uri)
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|
http.request(request)

View file

@ -34,8 +34,9 @@ class RegistrantAreaContactUpdateTest < ApplicationIntegrationTest
def test_update_contact
stub_auth_request
request_body = { name: 'new name', email: 'new@inbox.test', phone: '+666.6' }
headers = { 'Authorization' => 'Bearer test-access-token' }
request_body = { name: 'new name', email: 'new@inbox.test', phone: '+666.6' }.to_json
headers = { 'Content-Type' => Mime::JSON,
'Authorization' => 'Bearer test-access-token' }
url = "https://api.test/api/v1/registrant/contacts/#{@contact.uuid}"
update_request_stub = stub_request(:patch, url).with(body: request_body, headers: headers)
.to_return(body: '{}', status: 200)
@ -104,17 +105,18 @@ class RegistrantAreaContactUpdateTest < ApplicationIntegrationTest
Setting.address_processing = true
stub_auth_request
request_body = { email: 'john@inbox.test',
name: 'John',
request_body = { name: 'John',
email: 'john@inbox.test',
phone: '+555.555',
address: {
city: 'new city',
street: 'new street',
zip: '93742',
city: 'new city',
country_code: 'AT',
state: 'new state',
country_code: 'AT'
} }
headers = { 'Authorization' => 'Bearer test-access-token' }
} }.to_json
headers = { 'Content-type' => 'application/json',
'Authorization' => 'Bearer test-access-token' }
url = "https://api.test/api/v1/registrant/contacts/#{@contact.uuid}"
update_request_stub = stub_request(:patch, url).with(body: request_body, headers: headers)
.to_return(body: '{}', status: 200)