Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions app/services/doc_auth/dos/responses/health_check_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
51 changes: 51 additions & 0 deletions spec/services/doc_auth/dos/responses/health_check_response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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