Skip to content

Commit

Permalink
remove company creation validation
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegPhenomenon committed Nov 25, 2024
1 parent d23b66e commit d0a39bf
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 65 deletions.
29 changes: 8 additions & 21 deletions app/interactions/actions/contact_create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def call
maybe_attach_legal_doc
validate_ident
maybe_change_email
maybe_company_is_relevant
# maybe_company_is_relevant
commit
validate_contact
end
Expand Down Expand Up @@ -78,29 +78,16 @@ def validate_ident_birthday
@error = true
end

def maybe_company_is_relevant
return true unless contact.org?
# def maybe_company_is_relevant
# return true unless contact.org?

Rails.logger.info "======= I AM HERE"
Rails.logger.info ENV['company_register_username']
Rails.logger.info ENV['company_register_password']
Rails.logger.info ENV['company_register_cache_period_days']
Rails.logger.info ENV['company_register_test_mode']
# company_status = contact.return_company_status

company_status = contact.return_company_status
Rails.logger.info "company_status: #{company_status}"
# return if [Contact::REGISTERED, Contact::LIQUIDATED].include? company_status
# contact.add_epp_error('2003', nil, 'ident', I18n.t('errors.messages.company_not_registered'))

return if [Contact::REGISTERED, Contact::LIQUIDATED].include? company_status
Rails.logger.info Contact::REGISTERED
Rails.logger.info Contact::LIQUIDATED
Rails.logger.info "======= I AM HERE 2"

contact.add_epp_error('2003', nil, 'ident', I18n.t('errors.messages.company_not_registered'))

Rails.logger.info "======="

@error = true
end
# @error = true
# end

def maybe_attach_legal_doc
::Actions::BaseAction.attach_legal_doc_to_new(contact, legal_document, domain: false)
Expand Down
12 changes: 1 addition & 11 deletions app/models/contact/company_register.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,16 @@ def company_is_relevant?
end

def return_company_status
Rails.logger.info "ident: #{ident}"
Rails.logger.info "org?: #{org?}"
Rails.logger.info "return_company_data: #{return_company_data.inspect}"

return if return_company_data.blank?

return_company_data.first[:status]
end

def return_company_data
Rails.logger.info "inside return_company_data"
Rails.logger.info "ident: #{ident}"
Rails.logger.info "org?: #{org?}"
return unless org?

res = company_register.simple_data(registration_number: ident.to_s)
Rails.logger.info "res: #{res.inspect}"
res
company_register.simple_data(registration_number: ident.to_s)
rescue CompanyRegister::NotAvailableError
Rails.logger.info "ERROR HAPPENED: CompanyRegister::NotAvailableError"
[]
end

Expand Down
66 changes: 33 additions & 33 deletions test/integration/repp/v1/contacts/create_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,39 +188,39 @@ def test_returns_error_response_if_throttled
ENV['shunter_enabled'] = 'false'
end

def test_returns_error_response_if_company_not_existed
original_new_method = CompanyRegister::Client.method(:new)
CompanyRegister::Client.define_singleton_method(:new) do
object = original_new_method.call
def object.simple_data(registration_number:)
[Company.new('1234567', 'ACME Ltd', 'K')]
end
object
end

request_body = {
"contact": {
"name": 'Donald Trump',
"phone": '+372.51111112',
"email": '[email protected]',
"ident": {
"ident_type": 'org',
"ident_country_code": 'EE',
"ident": '70000313',
},
},
}

post '/repp/v1/contacts', headers: @auth_headers, params: request_body
json = JSON.parse(response.body, symbolize_names: true)

assert_response :bad_request
assert_equal 2003, json[:code]
puts json[:message]
assert json[:message].include? 'Company is not registered'

CompanyRegister::Client.define_singleton_method(:new, original_new_method)
end
# def test_returns_error_response_if_company_not_existed
# original_new_method = CompanyRegister::Client.method(:new)
# CompanyRegister::Client.define_singleton_method(:new) do
# object = original_new_method.call
# def object.simple_data(registration_number:)
# [Company.new('1234567', 'ACME Ltd', 'K')]
# end
# object
# end

# request_body = {
# "contact": {
# "name": 'Donald Trump',
# "phone": '+372.51111112',
# "email": '[email protected]',
# "ident": {
# "ident_type": 'org',
# "ident_country_code": 'EE',
# "ident": '70000313',
# },
# },
# }

# post '/repp/v1/contacts', headers: @auth_headers, params: request_body
# json = JSON.parse(response.body, symbolize_names: true)

# assert_response :bad_request
# assert_equal 2003, json[:code]
# puts json[:message]
# assert json[:message].include? 'Company is not registered'

# CompanyRegister::Client.define_singleton_method(:new, original_new_method)
# end

def test_contact_created_with_existed_company
original_new_method = CompanyRegister::Client.method(:new)
Expand Down

0 comments on commit d0a39bf

Please sign in to comment.