From c77a4d494d55c8c560a86d3fa2fba5317526dd9f Mon Sep 17 00:00:00 2001 From: oleghasjanov Date: Tue, 1 Apr 2025 12:26:53 +0300 Subject: [PATCH] feat: add ability to skip business contact validation - Add environment variable 'allow_validate_business_contacts' to control business contact validation - Remove redundant company_is_relevant? method - Add integration test for skipping company validation --- app/interactions/actions/contact_create.rb | 1 + app/models/contact/company_register.rb | 4 --- config/application.yml.sample | 2 ++ .../repp/v1/contacts/create_test.rb | 36 +++++++++++++++++++ 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/app/interactions/actions/contact_create.rb b/app/interactions/actions/contact_create.rb index dfa2d1299..ca1b4d7c5 100644 --- a/app/interactions/actions/contact_create.rb +++ b/app/interactions/actions/contact_create.rb @@ -80,6 +80,7 @@ module Actions end def maybe_company_is_relevant + return true if ENV['allow_validate_business_contacts'] && ENV['allow_validate_business_contacts'] == 'false' return true unless contact.org? return true unless contact.ident_country_code == 'EE' diff --git a/app/models/contact/company_register.rb b/app/models/contact/company_register.rb index 803867ecf..e0d2e822f 100644 --- a/app/models/contact/company_register.rb +++ b/app/models/contact/company_register.rb @@ -6,10 +6,6 @@ module Contact::CompanyRegister BANKRUPT = 'N'.freeze DELETED = 'K'.freeze - def company_is_relevant? - company_register_status == REGISTERED && company_register_status == LIQUIDATED - end - def return_company_status return if return_company_data.blank? diff --git a/config/application.yml.sample b/config/application.yml.sample index c90631866..10531adcc 100644 --- a/config/application.yml.sample +++ b/config/application.yml.sample @@ -265,3 +265,5 @@ priv_ident_service_client_id: 123 priv_ident_service_client_secret: 321 birthday_ident_service_client_id: 456 birthday_ident_service_client_secret: 654 + +allow_validate_business_contacts: 'true' \ No newline at end of file diff --git a/test/integration/repp/v1/contacts/create_test.rb b/test/integration/repp/v1/contacts/create_test.rb index 505aabfe1..a57e0d0d7 100644 --- a/test/integration/repp/v1/contacts/create_test.rb +++ b/test/integration/repp/v1/contacts/create_test.rb @@ -221,6 +221,42 @@ class ReppV1ContactsCreateTest < ActionDispatch::IntegrationTest CompanyRegister::Client.define_singleton_method(:new, original_new_method) end + def test_skip_company_validation_if_flag_is_set + ENV['allow_validate_business_contacts'] = 'false' + 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": 'donald@trumptower.com', + "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 :ok + assert_equal 1000, json[:code] + assert_equal 'Command completed successfully', json[:message] + + CompanyRegister::Client.define_singleton_method(:new, original_new_method) + ENV['allow_validate_business_contacts'] = 'true' + end + + def test_contact_created_with_existed_company original_new_method = CompanyRegister::Client.method(:new) CompanyRegister::Client.define_singleton_method(:new) do