From c09e08c61e85874832e911669d4b6c767062e68e Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Thu, 15 Oct 2020 16:01:01 +0500 Subject: [PATCH 1/2] Change error handling to more humane --- .../api/v1/registrant/companies_controller.rb | 8 +++---- .../registrant_api_companies_test.rb | 22 +++++++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/v1/registrant/companies_controller.rb b/app/controllers/api/v1/registrant/companies_controller.rb index b11c06909..d2060276d 100644 --- a/app/controllers/api/v1/registrant/companies_controller.rb +++ b/app/controllers/api/v1/registrant/companies_controller.rb @@ -16,9 +16,9 @@ module Api end def current_user_companies - current_registrant_user.companies + [:ok, current_registrant_user.companies] rescue CompanyRegister::NotAvailableError - [] + [:service_unavailable, []] end def limit @@ -35,8 +35,8 @@ module Api end def companies_result(limit, offset) - @companies = current_user_companies.drop(offset).first(limit) - status = @companies.present? ? :ok : :not_found + status, all_companies = current_user_companies + @companies = all_companies.drop(offset).first(limit) serialized_companies = @companies.map do |item| country_code = current_registrant_user.country.alpha3 diff --git a/test/integration/api/registrant/registrant_api_companies_test.rb b/test/integration/api/registrant/registrant_api_companies_test.rb index b08383796..97e2fd3c2 100644 --- a/test/integration/api/registrant/registrant_api_companies_test.rb +++ b/test/integration/api/registrant/registrant_api_companies_test.rb @@ -1,3 +1,4 @@ +$VERBOSE=nil require 'test_helper' require 'auth_token/auth_token_creator' @@ -33,6 +34,18 @@ class RegistrantApiCompaniesTest < ApplicationIntegrationTest assert_equal(:companies, response_json.keys.first) end + def test_status_if_nil_result + contacts(:john).update!(ident: '12344321', ident_type: 'priv', ident_country_code: 'US') + + CompanyRegister.const_set(:Client, CompanyRegisterClientZeroStub) + + get '/api/v1/registrant/companies', headers: @auth_headers + response_json = JSON.parse(response.body, symbolize_names: true) + assert_equal(1, response_json.count) + assert_equal(200, response.status) + assert_equal(:companies, response_json.keys.first) + end + private def auth_token @@ -41,3 +54,12 @@ class RegistrantApiCompaniesTest < ApplicationIntegrationTest "Bearer #{hash[:access_token]}" end end + +class CompanyRegisterClientZeroStub + Company = Struct.new(:registration_number, :company_name) + + def representation_rights(citizen_personal_code:, citizen_country_code:) + [] + end +end + From f87b51ebe8fb5541a261221172272cd4d6232d89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Fri, 16 Oct 2020 12:45:49 +0300 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b2f2de6f..af19f4ad6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +16.10.2020 +* Improved error handling for registrant API comapnies endpoint [#1713](https://github.com/internetee/registry/pull/1713) + 15.10.2020 * Tara integration for registrant portal [#1698](https://github.com/internetee/registry/pull/1698)