diff --git a/app/services/doc_auth/dos/responses/health_check_response.rb b/app/services/doc_auth/dos/responses/health_check_response.rb index 6705458148e..fc9df7aaf97 100644 --- a/app/services/doc_auth/dos/responses/health_check_response.rb +++ b/app/services/doc_auth/dos/responses/health_check_response.rb @@ -20,12 +20,23 @@ def initialize(faraday_response:) def success return false if faraday_error? return false if !parsed_body - parsed_body[:status].to_s.downcase == 'up' + + healthy?(parsed_body) + end + + def healthy?(status_body) + return false if status_body[:status].to_s.downcase != 'up' + + status_body[:downstreamHealth]&.each do |h| + return false unless healthy?(h) + end + + true end def extra { - body: body, + body:, } end @@ -35,7 +46,7 @@ def body end def parsed_body - body && JSON.parse(body, symbolize_names: true) + @parsed_body ||= body && JSON.parse(body, symbolize_names: true) end def errors diff --git a/spec/services/doc_auth/dos/responses/health_check_response_spec.rb b/spec/services/doc_auth/dos/responses/health_check_response_spec.rb index cc2604ad751..018da4aaf18 100644 --- a/spec/services/doc_auth/dos/responses/health_check_response_spec.rb +++ b/spec/services/doc_auth/dos/responses/health_check_response_spec.rb @@ -101,5 +101,56 @@ def make_faraday_response(status:) it 'includes the body in the extras' do expect(health_check_response.extra[:body]).to eq(health_check_down_body) end + + context 'when composite healthheck down stream system is down' do + let(:faraday_response) do + Faraday.get(composite_health_check_endpoint) + end + + let(:health_check_down_body) do + { + status: 'uP', + downstreamHealth: [ + { + status: 'up', + downstreamHealth: nil, + }, + { + status: 'up', + downstreamHealth: [], + }, + { + status: 'up', + downstreamHealth: [ + { + status: 'up', + downstreamHealth: nil, + }, + { + status: 'up', + downstreamHealth: [], + }, + { + status: 'down', + }, + ], + }, + ], + }.to_json + end + + before do + stub_request(:get, composite_health_check_endpoint) + .to_return_json(body: health_check_down_body) + end + + it 'is not successful' do + expect(health_check_response).not_to be_success + end + + it 'includes the body in the extras' do + expect(health_check_response.extra[:body]).to eq(health_check_down_body) + end + end end end