mirror of
https://github.com/internetee/registry.git
synced 2025-06-06 04:37:30 +02:00
Add business registry support for contacts controller
This commit is contained in:
parent
b18db19035
commit
4cc0669286
4 changed files with 45 additions and 10 deletions
|
@ -1,6 +1,3 @@
|
|||
require 'rails5_api_controller_backport'
|
||||
require 'auth_token/auth_token_decryptor'
|
||||
|
||||
module Api
|
||||
module V1
|
||||
module Registrant
|
||||
|
@ -39,7 +36,20 @@ module Api
|
|||
|
||||
def set_contacts_pool
|
||||
country_code, ident = current_user.registrant_ident.to_s.split '-'
|
||||
@contacts_pool = Contact.where(country_code: country_code, ident: ident)
|
||||
associated_domain_ids = begin
|
||||
BusinessRegistryCache.fetch_by_ident_and_cc(ident, country_code).associated_domain_ids
|
||||
end
|
||||
|
||||
available_contacts_ids = begin
|
||||
DomainContact.where(domain_id: associated_domain_ids).pluck(:contact_id) |
|
||||
Domain.where(id: associated_domain_ids).pluck(:registrant_id)
|
||||
end
|
||||
|
||||
@contacts_pool = Contact.where(id: available_contacts_ids)
|
||||
rescue Soap::Arireg::NotAvailableError => error
|
||||
Rails.logger.fatal("[EXCEPTION] #{error}")
|
||||
render json: { errors: [{ base: ["Business Registry Not Available"] }] },
|
||||
status: :service_unavailable and return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
require 'rails5_api_controller_backport'
|
||||
|
||||
module Api
|
||||
module V1
|
||||
module Registrant
|
||||
|
|
|
@ -5,19 +5,30 @@ class RegistrantApiContactsTest < ApplicationIntegrationTest
|
|||
def setup
|
||||
super
|
||||
|
||||
@original_registry_time = Setting.days_to_keep_business_registry_cache
|
||||
Setting.days_to_keep_business_registry_cache = 1
|
||||
travel_to Time.zone.parse('2010-07-05')
|
||||
|
||||
@user = users(:registrant)
|
||||
@auth_headers = { 'HTTP_AUTHORIZATION' => auth_token }
|
||||
end
|
||||
|
||||
def teardown
|
||||
super
|
||||
|
||||
Setting.days_to_keep_business_registry_cache = @original_registry_time
|
||||
travel_back
|
||||
end
|
||||
|
||||
def test_root_returns_domain_list
|
||||
get '/api/v1/registrant/contacts', {}, @auth_headers
|
||||
assert_equal(200, response.status)
|
||||
|
||||
json_body = JSON.parse(response.body, symbolize_names: true)
|
||||
assert_equal(2, json_body.count)
|
||||
assert_equal(5, json_body.count)
|
||||
array_of_contact_codes = json_body.map { |x| x[:code] }
|
||||
assert(array_of_contact_codes.include?('william-001'))
|
||||
assert(array_of_contact_codes.include?('william-002'))
|
||||
assert(array_of_contact_codes.include?('jane-001'))
|
||||
end
|
||||
|
||||
def test_root_accepts_limit_and_offset_parameters
|
||||
|
@ -28,7 +39,23 @@ class RegistrantApiContactsTest < ApplicationIntegrationTest
|
|||
|
||||
get '/api/v1/registrant/contacts', {}, @auth_headers
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
assert_equal(2, response_json.count)
|
||||
assert_equal(5, response_json.count)
|
||||
end
|
||||
|
||||
def test_get_contact_details_by_uuid
|
||||
get '/api/v1/registrant/contacts/0aa54704-d6f7-4ca9-b8ca-2827d9a4e4eb', {}, @auth_headers
|
||||
assert_equal(200, response.status)
|
||||
|
||||
contact = JSON.parse(response.body, symbolize_names: true)
|
||||
assert_equal('william@inbox.test', contact[:email])
|
||||
end
|
||||
|
||||
def test_get_contact_details_by_uuid_returns_404_for_non_existent_contact
|
||||
get '/api/v1/registrant/contacts/nonexistent-uuid', {}, @auth_headers
|
||||
assert_equal(404, response.status)
|
||||
|
||||
response_json = JSON.parse(response.body, symbolize_names: true)
|
||||
assert_equal({ errors: [{ base: ['Contact not found'] }] }, response_json)
|
||||
end
|
||||
|
||||
def test_root_does_not_accept_limit_higher_than_200
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue