mirror of
https://github.com/internetee/registry.git
synced 2025-06-05 20:27:30 +02:00
Add tests, show papertrail whodunnit properly on repp api
This commit is contained in:
parent
7d08e22f6f
commit
38f86225ca
3 changed files with 28 additions and 3 deletions
|
@ -4,9 +4,10 @@ module Repp
|
|||
rescue_from ActiveRecord::RecordNotFound, with: :not_found_error
|
||||
before_action :authenticate_user
|
||||
before_action :check_ip_restriction
|
||||
before_action :set_paper_trail_whodunnit
|
||||
attr_reader :current_user
|
||||
|
||||
before_action :set_paper_trail_whodunnit
|
||||
|
||||
rescue_from ActionController::ParameterMissing do |exception|
|
||||
render json: { code: 2003, message: exception }, status: :bad_request
|
||||
end
|
||||
|
@ -23,6 +24,10 @@ module Repp
|
|||
|
||||
private
|
||||
|
||||
def set_paper_trail_whodunnit
|
||||
::PaperTrail.request.whodunnit = current_user
|
||||
end
|
||||
|
||||
def render_success(code: nil, message: nil, data: nil)
|
||||
@response = { code: code || 1000, message: message || 'Command completed successfully',
|
||||
data: data || {} }
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
module ObjectVersionsHelper
|
||||
def attach_existing_fields(version, new_object)
|
||||
destroy_event = version.event == 'destroy'
|
||||
version.object_changes.to_h.each do |key, value|
|
||||
method_name = "#{key}=".to_sym
|
||||
if new_object.respond_to?(method_name)
|
||||
new_object.public_send(method_name, destroy_event ? value.first : value.last)
|
||||
new_object.public_send(method_name, event_value(event, value))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -13,4 +12,10 @@ module ObjectVersionsHelper
|
|||
field_names = model.column_names
|
||||
version.object.to_h.select { |key, _value| field_names.include?(key) }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def event_value(version, val)
|
||||
version.event == 'destroy' ? val.first : val.last
|
||||
end
|
||||
end
|
||||
|
|
|
@ -101,4 +101,19 @@ class ReppV1ContactsUpdateTest < ActionDispatch::IntegrationTest
|
|||
@contact.reload
|
||||
assert @contact.legal_documents.any?
|
||||
end
|
||||
|
||||
def test_returns_error_if_ident_wrong_format
|
||||
request_body = {
|
||||
"contact": {
|
||||
"ident": "123"
|
||||
}
|
||||
}
|
||||
|
||||
put "/repp/v1/contacts/#{@contact.code}", headers: @auth_headers, params: request_body
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :bad_request
|
||||
assert_equal 2308, json[:code]
|
||||
assert_equal 'Ident update is not allowed. Consider creating new contact object', json[:message]
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue