diff --git a/app/controllers/api/v1/registrant/contacts_controller.rb b/app/controllers/api/v1/registrant/contacts_controller.rb index 2c8a1f70e..5db175265 100644 --- a/app/controllers/api/v1/registrant/contacts_controller.rb +++ b/app/controllers/api/v1/registrant/contacts_controller.rb @@ -48,7 +48,7 @@ module Api @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"] }] }, + render json: { errors: [{ base: ["Business Registry not available"] }] }, status: :service_unavailable and return end end diff --git a/test/integration/api/registrant/registrant_api_contacts_test.rb b/test/integration/api/registrant/registrant_api_contacts_test.rb index 28dd50d76..ddeaee9f3 100644 --- a/test/integration/api/registrant/registrant_api_contacts_test.rb +++ b/test/integration/api/registrant/registrant_api_contacts_test.rb @@ -50,6 +50,17 @@ class RegistrantApiContactsTest < ApplicationIntegrationTest assert_equal('william@inbox.test', contact[:email]) end + def test_root_returns_503_when_business_registry_is_not_available + raise_not_available = -> (a, b) { raise Soap::Arireg::NotAvailableError.new({}) } + BusinessRegistryCache.stub :fetch_by_ident_and_cc, raise_not_available do + get '/api/v1/registrant/contacts', {}, @auth_headers + + assert_equal(503, response.status) + response_json = JSON.parse(response.body, symbolize_names: true) + assert_equal({ errors: [base: ['Business Registry not available']] }, response_json) + end + 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)