Add test for error in business registry

This commit is contained in:
Maciej Szlosarczyk 2018-08-09 15:24:21 +03:00
parent 4cc0669286
commit 256d2b7de4
No known key found for this signature in database
GPG key ID: 41D62D42D3B0D765
2 changed files with 12 additions and 1 deletions

View file

@ -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

View file

@ -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)