Skip to content

Commit

Permalink
Test error handling for entity match requests
Browse files Browse the repository at this point in the history
Add some more tests to cover various errors we might get when making a request.

Also remove the :not_found response, as this was copied from the address lookup but doesn't apply here.
  • Loading branch information
irisfaraway committed Jun 22, 2018
1 parent 322c6fc commit e3e96b4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
5 changes: 1 addition & 4 deletions app/services/entity_matching_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,13 @@ def query_service(url)
Rails.logger.error "Entity Matching JSON error: " + e.to_s
:error
end
rescue RestClient::BadRequest
Rails.logger.debug "Entity Matching: resource not found"
:not_found
rescue RestClient::ExceptionWithResponse => e
Airbrake.notify(e)
Rails.logger.error "Entity Matching response error: " + e.to_s
:error
rescue Errno::ECONNREFUSED => e
Airbrake.notify(e)
Rails.logger.error "Entity Matching response error: " + e.to_s
Rails.logger.error "Entity Matching connection error: " + e.to_s
:error
rescue SocketError => e
Airbrake.notify(e)
Expand Down
40 changes: 40 additions & 0 deletions spec/services/entity_matching_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,45 @@
end
end
end

context "when the response cannot be parsed as JSON" do
before do
allow_any_instance_of(RestClient::Request).to receive(:execute).and_return("foo")
end

it "returns :error" do
expect(entity_matching_service.check_people_for_matches).to eq(:error)
end
end

context "when the request times out" do
it "returns :error" do
VCR.turned_off do
host = Rails.configuration.wcrs_services_url
stub_request(:any, /.*#{host}.*/).to_timeout
expect(entity_matching_service.check_people_for_matches).to eq(:error)
end
end
end

context "when the request returns a connection refused error" do
it "returns :error" do
VCR.turned_off do
host = Rails.configuration.wcrs_services_url
stub_request(:any, /.*#{host}.*/).to_raise(Errno::ECONNREFUSED)
expect(entity_matching_service.check_people_for_matches).to eq(:error)
end
end
end

context "when the request returns a socket error" do
it "returns :error" do
VCR.turned_off do
host = Rails.configuration.wcrs_services_url
stub_request(:any, /.*#{host}.*/).to_raise(SocketError)
expect(entity_matching_service.check_people_for_matches).to eq(:error)
end
end
end
end
end

0 comments on commit e3e96b4

Please sign in to comment.