mirror of
https://github.com/internetee/registry.git
synced 2025-07-28 05:26:17 +02:00
Merge pull request #2741 from internetee/disclose-phone-num-for-org-registrants
Update company_register gem and fix logger dependency
This commit is contained in:
commit
268b942042
9 changed files with 282 additions and 19 deletions
|
@ -253,4 +253,32 @@ class ReppV1ContactsCreateTest < ActionDispatch::IntegrationTest
|
|||
|
||||
CompanyRegister::Client.define_singleton_method(:new, original_new_method)
|
||||
end
|
||||
|
||||
def test_validates_phone_number_after_create
|
||||
request_body = {
|
||||
contact: {
|
||||
name: 'Test Company',
|
||||
phone: '+372.51111112',
|
||||
email: 'test@company.com',
|
||||
ident: {
|
||||
ident_type: 'org',
|
||||
ident_country_code: 'EE',
|
||||
ident: '12345678',
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
assert_enqueued_with(job: OrgRegistrantPhoneCheckerJob) do
|
||||
post '/repp/v1/contacts', headers: @auth_headers, params: request_body
|
||||
end
|
||||
|
||||
assert_response :ok
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
assert_equal 1000, json[:code]
|
||||
assert_equal 'Command completed successfully', json[:message]
|
||||
|
||||
contact = Contact.find_by(code: json[:data][:contact][:code])
|
||||
assert contact.present?
|
||||
assert_equal '+372.51111112', contact.phone
|
||||
end
|
||||
end
|
||||
|
|
|
@ -142,4 +142,31 @@ class ReppV1ContactsUpdateTest < ActionDispatch::IntegrationTest
|
|||
ENV["shunter_default_threshold"] = '10000'
|
||||
ENV["shunter_enabled"] = 'false'
|
||||
end
|
||||
|
||||
def test_validates_phone_number_after_update
|
||||
@contact.update!(
|
||||
phone: '+372.555666777',
|
||||
ident_type: 'org',
|
||||
ident_country_code: 'EE',
|
||||
ident: '12345678'
|
||||
)
|
||||
|
||||
request_body = {
|
||||
contact: {
|
||||
phone: '+372.123456789'
|
||||
}
|
||||
}
|
||||
|
||||
assert_enqueued_with(job: OrgRegistrantPhoneCheckerJob) do
|
||||
put "/repp/v1/contacts/#{@contact.code}", headers: @auth_headers, params: request_body
|
||||
end
|
||||
|
||||
assert_response :ok
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
assert_equal 1000, json[:code]
|
||||
assert_equal 'Command completed successfully', json[:message]
|
||||
|
||||
@contact.reload
|
||||
assert_equal '+372.123456789', @contact.phone
|
||||
end
|
||||
end
|
||||
|
|
109
test/jobs/org_registrant_phone_checker_job_test.rb
Normal file
109
test/jobs/org_registrant_phone_checker_job_test.rb
Normal file
|
@ -0,0 +1,109 @@
|
|||
require 'test_helper'
|
||||
|
||||
class OrgRegistrantPhoneCheckerJobTest < ActiveSupport::TestCase
|
||||
include ActionMailer::TestHelper
|
||||
|
||||
setup do
|
||||
@contact = contacts(:acme_ltd)
|
||||
@original_phone = '+372.555666777'
|
||||
@contact.update!(
|
||||
phone: @original_phone,
|
||||
ident_type: 'org',
|
||||
ident_country_code: 'EE',
|
||||
ident: '12345678'
|
||||
)
|
||||
end
|
||||
|
||||
def test_bulk_checker_processes_all_ee_org_contacts
|
||||
original_new_method = CompanyRegister::Client.method(:new)
|
||||
CompanyRegister::Client.define_singleton_method(:new) do
|
||||
object = original_new_method.call
|
||||
def object.company_details(registration_number:)
|
||||
[OpenStruct.new(phone_numbers: ['+372.555666777'])]
|
||||
end
|
||||
object
|
||||
end
|
||||
|
||||
assert_not @contact.disclosed_attributes.include?('phone')
|
||||
|
||||
OrgRegistrantPhoneCheckerJob.perform_now(type: 'bulk')
|
||||
@contact.reload
|
||||
|
||||
assert @contact.disclosed_attributes.include?('phone')
|
||||
|
||||
CompanyRegister::Client.define_singleton_method(:new, original_new_method)
|
||||
end
|
||||
|
||||
def test_single_checker_processes_specific_contact
|
||||
original_new_method = CompanyRegister::Client.method(:new)
|
||||
CompanyRegister::Client.define_singleton_method(:new) do
|
||||
object = original_new_method.call
|
||||
def object.company_details(registration_number:)
|
||||
[OpenStruct.new(phone_numbers: ['+372.555666777'])]
|
||||
end
|
||||
object
|
||||
end
|
||||
|
||||
assert_not @contact.disclosed_attributes.include?('phone')
|
||||
|
||||
OrgRegistrantPhoneCheckerJob.perform_now(
|
||||
type: 'single',
|
||||
registrant_user_code: @contact.code
|
||||
)
|
||||
@contact.reload
|
||||
|
||||
assert @contact.disclosed_attributes.include?('phone')
|
||||
|
||||
CompanyRegister::Client.define_singleton_method(:new, original_new_method)
|
||||
end
|
||||
|
||||
def test_removes_phone_disclosure_when_numbers_do_not_match
|
||||
original_new_method = CompanyRegister::Client.method(:new)
|
||||
CompanyRegister::Client.define_singleton_method(:new) do
|
||||
object = original_new_method.call
|
||||
def object.company_details(registration_number:)
|
||||
[OpenStruct.new(phone_numbers: ['+372.999888777'])]
|
||||
end
|
||||
object
|
||||
end
|
||||
|
||||
@contact.disclosed_attributes = ['phone']
|
||||
@contact.save!
|
||||
assert @contact.disclosed_attributes.include?('phone')
|
||||
|
||||
OrgRegistrantPhoneCheckerJob.perform_now(type: 'bulk')
|
||||
@contact.reload
|
||||
|
||||
assert_not @contact.disclosed_attributes.include?('phone')
|
||||
|
||||
CompanyRegister::Client.define_singleton_method(:new, original_new_method)
|
||||
end
|
||||
|
||||
def test_handles_invalid_job_type
|
||||
assert_raises(RuntimeError) do
|
||||
OrgRegistrantPhoneCheckerJob.perform_now(type: 'invalid')
|
||||
end
|
||||
end
|
||||
|
||||
def test_phone_number_formatting_matches_different_formats
|
||||
original_new_method = CompanyRegister::Client.method(:new)
|
||||
CompanyRegister::Client.define_singleton_method(:new) do
|
||||
object = original_new_method.call
|
||||
def object.company_details(registration_number:)
|
||||
[OpenStruct.new(phone_numbers: ['+372 555 666 777'])]
|
||||
end
|
||||
object
|
||||
end
|
||||
|
||||
@contact.phone = '+372.555666777'
|
||||
@contact.save(validate: false)
|
||||
assert_not @contact.disclosed_attributes.include?('phone')
|
||||
|
||||
OrgRegistrantPhoneCheckerJob.perform_now(type: 'bulk')
|
||||
@contact.reload
|
||||
|
||||
assert @contact.disclosed_attributes.include?('phone')
|
||||
|
||||
CompanyRegister::Client.define_singleton_method(:new, original_new_method)
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue