mirror of
https://github.com/internetee/registry.git
synced 2025-06-10 06:34:46 +02:00
REPP: Contact update test
This commit is contained in:
parent
9cfa1c2989
commit
33f6da53c1
3 changed files with 92 additions and 8 deletions
|
@ -41,7 +41,7 @@ module Repp
|
|||
|
||||
## PUT /repp/v1/contacts/1
|
||||
def update
|
||||
action = Actions::ContactUpdate.new(@contact, contact_params_with_address,
|
||||
action = Actions::ContactUpdate.new(@contact, contact_params_with_address(required: false),
|
||||
params[:legal_document],
|
||||
contact_ident_params(required: false), current_user)
|
||||
|
||||
|
@ -84,16 +84,16 @@ module Repp
|
|||
@contact = Epp::Contact.find_by!(code: code, registrar: current_user.registrar)
|
||||
end
|
||||
|
||||
def contact_params_with_address
|
||||
return contact_create_params unless contact_addr_params.key?(:addr)
|
||||
def contact_params_with_address(required: true)
|
||||
return contact_create_params(required: required) unless contact_addr_params.key?(:addr)
|
||||
|
||||
addr = {}
|
||||
contact_addr_params[:addr].each_key { |k| addr[k] = contact_addr_params[:addr][k] }
|
||||
contact_create_params.merge(addr)
|
||||
contact_create_params(required: required).merge(addr)
|
||||
end
|
||||
|
||||
def contact_create_params
|
||||
params.require(:contact).require(%i[name email phone])
|
||||
def contact_create_params(required: true)
|
||||
params.require(:contact).require(%i[name email phone]) if required
|
||||
params.require(:contact).permit(:name, :email, :phone)
|
||||
end
|
||||
|
||||
|
@ -102,8 +102,10 @@ module Repp
|
|||
params.require(:contact).require(:ident).require(%i[ident ident_type ident_country_code])
|
||||
params.require(:contact).require(:ident).permit(:ident, :ident_type, :ident_country_code)
|
||||
else
|
||||
params.permit(ident: %i[ident ident_type ident_country_code])
|
||||
params.permit(contact: { ident: %i[ident ident_type ident_country_code] })
|
||||
end
|
||||
|
||||
params[:contact][:ident]
|
||||
end
|
||||
|
||||
def contact_addr_params
|
||||
|
|
|
@ -17,7 +17,7 @@ module Actions
|
|||
def call
|
||||
maybe_remove_address
|
||||
maybe_update_statuses
|
||||
maybe_update_ident
|
||||
maybe_update_ident if ident
|
||||
maybe_attach_legal_doc
|
||||
commit
|
||||
end
|
||||
|
|
82
test/integration/repp/v1/contacts/update_test.rb
Normal file
82
test/integration/repp/v1/contacts/update_test.rb
Normal file
|
@ -0,0 +1,82 @@
|
|||
require 'test_helper'
|
||||
|
||||
class ReppV1ContactsUpdateTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
@contact = contacts(:john)
|
||||
@user = users(:api_bestnames)
|
||||
token = Base64.encode64("#{@user.username}:#{@user.plain_text_password}")
|
||||
token = "Basic #{token}"
|
||||
|
||||
@auth_headers = { 'Authorization' => token }
|
||||
end
|
||||
|
||||
def test_updates_contact
|
||||
request_body = {
|
||||
"contact": {
|
||||
"email": "donaldtrump@yandex.ru"
|
||||
}
|
||||
}
|
||||
|
||||
put "/repp/v1/contacts/#{@contact.code}", headers: @auth_headers, params: request_body
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :ok
|
||||
assert_equal 1000, json[:code]
|
||||
assert_equal 'Command completed successfully', json[:message]
|
||||
|
||||
contact = Contact.find_by(code: json[:data][:contact][:id])
|
||||
assert contact.present?
|
||||
|
||||
assert_equal(request_body[:contact][:email], contact.email)
|
||||
end
|
||||
|
||||
def test_removes_postal_info_when_updated
|
||||
request_body = {
|
||||
"contact": {
|
||||
"addr": {
|
||||
"city": "Tallinn",
|
||||
"street": "Wismari 13",
|
||||
"zip": "12345",
|
||||
"country_code": "EE"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
put "/repp/v1/contacts/#{@contact.code}", headers: @auth_headers, params: request_body
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :ok
|
||||
assert_equal 1100, json[:code]
|
||||
assert_equal 'Command completed successfully; Postal address data discarded', json[:message]
|
||||
|
||||
contact = Contact.find_by(code: json[:data][:contact][:id])
|
||||
assert contact.present?
|
||||
|
||||
assert_nil contact.city
|
||||
assert_nil contact.street
|
||||
assert_nil contact.zip
|
||||
assert_nil contact.country_code
|
||||
end
|
||||
|
||||
def test_can_not_change_ident_code
|
||||
request_body = {
|
||||
"contact": {
|
||||
"name": "Donald Trumpster",
|
||||
"ident": {
|
||||
"ident_type": "priv",
|
||||
"ident_country_code": "US",
|
||||
"ident": "12345"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
put "/repp/v1/contacts/#{@contact.code}", headers: @auth_headers, params: request_body
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
@contact.reload
|
||||
assert_not @contact.ident == 12345
|
||||
assert_response :bad_request
|
||||
assert_equal 2308, json[:code]
|
||||
assert json[:message].include? 'Ident update is not allowed. Consider creating new contact object'
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue