Skip to content

Commit

Permalink
Merge branch 'vebt-194' of github.com:department-of-veterans-affairs/…
Browse files Browse the repository at this point in the history
…vets-api into vebt-194
  • Loading branch information
GcioGregg committed Sep 4, 2024
2 parents 512d368 + 64d3cfe commit cac2288
Show file tree
Hide file tree
Showing 20 changed files with 348 additions and 224 deletions.
12 changes: 4 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -857,8 +857,7 @@ GEM
hashie (>= 1.2.0, < 6.0)
jwt (>= 1.5.6)
retriable (3.1.2)
rexml (3.3.6)
strscan
rexml (3.3.7)
rgeo (3.0.1)
rgeo-activerecord (7.0.1)
activerecord (>= 5.0)
Expand Down Expand Up @@ -914,18 +913,17 @@ GEM
actionpack (>= 5.2, < 8.0)
railties (>= 5.2, < 8.0)
rtesseract (3.1.3)
rubocop (1.65.1)
rubocop (1.66.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.4, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-ast (>= 1.32.2, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.32.1)
rubocop-ast (1.32.2)
parser (>= 3.3.1.0)
rubocop-capybara (2.21.0)
rubocop (~> 1.41)
Expand Down Expand Up @@ -1019,8 +1017,6 @@ GEM
stringio (3.1.1)
strong_migrations (2.0.0)
activerecord (>= 6.1)
strscan (3.1.0)
strscan (3.1.0-java)
super_diff (0.12.1)
attr_extras (>= 6.2.4)
diff-lcs
Expand Down
10 changes: 5 additions & 5 deletions config/features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ features:
hca_enrollment_status_override_enabled:
actor_type: user
description: Enables override of enrollment status for a user, to allow multiple submissions with same user.
hca_insurance_v2_enabled:
actor_type: user
description: Enables the the upgraded insurance section of the Health Care Application
enable_in_development: true
hca_performance_alert_enabled:
actor_type: user
description: Enables alert notifying users of a potential issue with application performance.
Expand Down Expand Up @@ -1345,10 +1349,6 @@ features:
actor_type: user
enable_in_development: true
description: Toggle for routing appointment requests to the VetsAPI Gateway Service(VPG) instead of vaos-service.
va_online_scheduling_appointment_details_redesign:
actor_type: user
enable_in_development: true
description: Toggle for redesigning the appointment details page.
va_online_scheduling_recent_locations_filter:
actor_type: user
enable_in_development: true
Expand Down Expand Up @@ -1667,7 +1667,7 @@ features:
description: >-
A frontend-focused switch that toggles visibility of and access to the Travel Pay claim details page and entry point (features toggled together).
Enabled - Entry point link and claim details page are viewable.
Disabled - Entry point link and claim details page are not viewable.
Disabled - Entry point link and claim details page are not viewable.
travel_pay_submit_mileage_expense:
actor_type: user
enable_in_development: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,38 @@ module FindPersonBySSN
end
end

##
# TrackedItemService
#
# Adding 'Bean' to the end to differentiate from the service
module TrackedItemServiceBean
DEFINITION =
Bean.new(
path: 'TrackedItemService',
namespaces: Namespaces.new(
target: 'http://services.mapd.benefits.vba.va.gov/',
data: nil
)
)
end

module TrackedItemService
DEFINITION =
Service.new(
bean: TrackedItemServiceBean::DEFINITION,
path: 'TrackedItemService'
)

module FindTrackedItems
DEFINITION =
Action.new(
service: TrackedItemService::DEFINITION,
name: 'findTrackedItems',
key: 'BenefitClaim'
)
end
end

##
# VdcBean
#
Expand Down
21 changes: 0 additions & 21 deletions modules/claims_api/config/initializers/okcomputer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,6 @@ def name
end
end

class VbmsCheck < BaseCheck
def check
connection = Faraday::Connection.new
connection.options.timeout = 10
response = connection.get("#{Settings.vbms.url}/vbms-efolder-svc/upload-v1/eFolderUploadService?wsdl")
response.status == 200 ? process_success : process_failure
rescue
process_failure
end

protected

def name
'VBMS'
end
end

OkComputer::Registry.register 'mpi', MpiCheck.new
OkComputer::Registry.register 'bgs-vet_record', BgsCheck.new('vet_record')
OkComputer::Registry.register 'bgs-corporate_update', BgsCheck.new('corporate_update')
Expand All @@ -119,7 +102,3 @@ def name
FaradayBGSCheck.new('IntentToFileWebServiceBean/IntentToFileWebService')
OkComputer::Registry.register 'localbgs-trackeditem',
FaradayBGSCheck.new('TrackedItemService/TrackedItemService')

OkComputer::Registry.register 'vbms', VbmsCheck.new

OkComputer.make_optional %w[vbms bgs-vet_record bgs-corporate_update bgs-contention]
1 change: 1 addition & 0 deletions modules/claims_api/lib/bgs_service/local_bgs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class LocalBGS
IntentToFileWebServiceBean/IntentToFileWebService
OrgWebServiceBean/OrgWebService
PersonWebServiceBean/PersonWebService
TrackedItemService/TrackedItemService
VDC/VeteranRepresentativeService
VdcBean/ManageRepresentativeService
VnpAtchmsWebServiceBean/VnpAtchmsService
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

module ClaimsApi
module Common
module Exceptions
module Lighthouse
class BadGateway < StandardError
def errors
errors_array = []
errors_array << {
status: status_code.to_s, # LH standards want this be a string
title: 'Bad gateway',
detail: 'The server received an invalid or null response from an upstream server.'
}
errors_array
end

def status_code
502
end
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
require 'claims_api/common/exceptions/lighthouse/unprocessable_entity'
require 'claims_api/common/exceptions/lighthouse/resource_not_found'
require 'claims_api/common/exceptions/lighthouse/bad_request'
require 'claims_api/common/exceptions/lighthouse/bad_gateway'
require 'claims_api/common/exceptions/lighthouse/timeout'

module ClaimsApi
Expand All @@ -28,6 +29,7 @@ def self.included(clazz) # rubocop:disable Metrics/MethodLength
::ClaimsApi::Common::Exceptions::Lighthouse::BadRequest,
::Common::Exceptions::BackendServiceException,
::ClaimsApi::Common::Exceptions::Lighthouse::Timeout,
::ClaimsApi::Common::Exceptions::Lighthouse::BadGateway,
::ClaimsApi::Common::Exceptions::Lighthouse::BackendServiceException do |err|
render_non_source_error(err)
end
Expand Down
8 changes: 8 additions & 0 deletions modules/claims_api/lib/custom_error.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# frozen_string_literal: true

require 'claims_api/common/exceptions/lighthouse/backend_service_exception'
require 'claims_api/common/exceptions/lighthouse/bad_gateway'
require 'claims_api/common/exceptions/lighthouse/timeout'
require 'claims_api/v2/error/lighthouse_error_mapper'

module ClaimsApi
class CustomError
def initialize(error, detail = nil, async = true) # rubocop:disable Style/OptionalBooleanParameter
Expand All @@ -29,6 +31,7 @@ def build_error
when ::Common::Exceptions::BackendServiceException
raise ::Common::Exceptions::Forbidden if @original_status == 403

raise_bad_gateway_exception if @original_status == 504
raise_backend_exception if @original_status == 400
raise ::Common::Exceptions::Unauthorized if @original_status == 401

Expand All @@ -50,6 +53,11 @@ def raise_timeout_exception
raise ::ClaimsApi::Common::Exceptions::Lighthouse::Timeout, error_details
end

def raise_bad_gateway_exception
error_details = get_error_info if @original_body.present?
raise ::ClaimsApi::Common::Exceptions::Lighthouse::BadGateway, error_details
end

def get_error_info
all_errors = []

Expand Down
27 changes: 27 additions & 0 deletions modules/claims_api/spec/lib/claims_api/find_definition_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,21 @@
end
end

# This one doesn't have `Bean` at the end
context 'TrackedItemService' do
let(:endpoint) { 'TrackedItemService/TrackedItemService' }
let(:action) { 'findTrackedItems' }
let(:key) { 'BenefitClaim' }

it 'response with the correct attributes' do
result = subject.for_action(endpoint, action)
parsed_result = JSON.parse(result.to_json)
expect(parsed_result['service']['bean']['path']).to eq 'TrackedItemService'
expect(parsed_result['service']['path']).to eq 'TrackedItemService'
expect(parsed_result['service']['bean']['namespaces']['target']).to eq 'http://services.mapd.benefits.vba.va.gov/'
end
end

context 'VdcBean' do
let(:endpoint) { 'VDC/ManageRepresentativeService' }
let(:action) { 'readPOARequest' }
Expand Down Expand Up @@ -249,6 +264,18 @@
end
end

context 'TrackedItemService' do
let(:endpoint) { 'TrackedItemService/TrackedItemService' }

it 'response with the correct namespace' do
result = subject.for_service(endpoint)
parsed_result = JSON.parse(result.to_json)
expect(parsed_result['bean']['path']).to eq 'TrackedItemService'
expect(parsed_result['path']).to eq 'TrackedItemService'
expect(parsed_result['bean']['namespaces']['target']).to eq 'http://services.mapd.benefits.vba.va.gov/'
end
end

context 'VdcBean' do
let(:endpoint) { 'VDC/ManageRepresentativeService' }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ def raise_expired_token_signature
def raise_timeout
raise ClaimsApi::Common::Exceptions::Lighthouse::Timeout
end

def raise_bad_gateway
raise ClaimsApi::Common::Exceptions::Lighthouse::BadGateway
end
end

before do
Expand All @@ -62,6 +66,7 @@ def raise_timeout
get 'raise_invalid_token' => 'anonymous#raise_invalid_token'
get 'raise_expired_token_signature' => 'anonymous#raise_expired_token_signature'
get 'raise_timeout' => 'anonymous#raise_timeout'
get 'raise_bad_gateway' => 'anonymous#raise_bad_gateway'
end
end

Expand Down Expand Up @@ -169,4 +174,21 @@ def raise_timeout
expect(parsed_body['errors'][0]['status']).to be_a(String)
end
end

it 'catches an external timeout and returns bad gateway' do
mock_ccg(scopes) do |auth_header|
request.headers.merge!(auth_header)

get :raise_bad_gateway

expect(response).to have_http_status(:bad_gateway)
parsed_body = JSON.parse(response.body)
expect(parsed_body['errors'][0]['title']).to eq('Bad gateway')
expect(parsed_body['errors'][0]['detail']).to eq(
'The server received an invalid or null response from an upstream server.'
)
expect(parsed_body['errors'][0]['status']).to eq('502')
expect(parsed_body['errors'][0]['status']).to be_a(String)
end
end
end
47 changes: 29 additions & 18 deletions modules/claims_api/spec/requests/metadata_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,36 @@
expect(response).to have_http_status(:ok)
end

required_upstream_services = %w[mpi]
optional_upstream_services = %w[vbms bgs-vet_record bgs-corporate_update bgs-contention
localbgs-healthcheck]
(required_upstream_services + optional_upstream_services).each do |upstream_service|
it "returns correct status when #{upstream_service} is not healthy" do
allow(MPI::Service).to receive(:service_is_up?).and_return(upstream_service != 'mpi')
allow_any_instance_of(BGS::Services).to receive(:vet_record)
.and_return(Struct.new(:healthy?).new(upstream_service != 'bgs-vet_record'))
allow_any_instance_of(BGS::Services).to receive(:corporate_update)
.and_return(Struct.new(:healthy?).new(upstream_service != 'bgs-corporate_update'))
allow_any_instance_of(BGS::Services).to receive(:contention)
.and_return(Struct.new(:healthy?).new(upstream_service != 'bgs-contention'))
allow_any_instance_of(ClaimsApi::LocalBGS).to receive(:healthcheck)
.and_return(200)
allow_any_instance_of(Faraday::Connection).to receive(:get)
.and_return(upstream_service == 'vbms' ? Struct.new(:status).new(500) : Struct.new(:status).new(200))
it 'returns the correct status when MPI is not healthy' do
allow(MPI::Service).to receive(:service_is_up?).and_return(false)
get "/services/claims/#{version}/upstream_healthcheck"
result = JSON.parse(response.body)
expect(result['mpi']['success']).to eq(false)
end

local_bgs_services = %i[claimant person org ebenefitsbenftclaim intenttofile trackeditem].freeze
local_bgs_methods = %i[find_poa_by_participant_id find_by_ssn find_poa_history_by_ptcpnt_id
find_benefit_claims_status_by_ptcpnt_id insert_intent_to_file find_tracked_items].freeze
local_bgs_services.each do |local_bgs_service|
it "returns the correct status when the local bgs #{local_bgs_service} is not healthy" do
local_bgs_methods.each do |local_bgs_method|
allow_any_instance_of(ClaimsApi::LocalBGS).to receive(local_bgs_method.to_sym)
.and_return(Struct.new(:healthy?).new(false))
get "/services/claims/#{version}/upstream_healthcheck"
result = JSON.parse(response.body)
expect(result["localbgs-#{local_bgs_service}"]['success']).to eq(false)
end
end
end

bgs_services = %i[vet_record corporate_update contention].freeze
bgs_services.each do |service|
it "returns the correct status when the BGS #{service} is not healthy" do
allow_any_instance_of(BGS::Services).to receive(service.to_sym)
.and_return(Struct.new(:healthy?).new(false))
get "/services/claims/#{version}/upstream_healthcheck"
expected_status = required_upstream_services.include?(upstream_service) ? :internal_server_error : :success
expect(response).to have_http_status(expected_status)
result = JSON.parse(response.body)
expect(result["bgs-#{service}"]['success']).to eq(false)
end
end
end
Expand Down
31 changes: 31 additions & 0 deletions modules/claims_api/spec/sidekiq/claim_custom_error_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,35 @@
end
end
end

context 'an external service returns a 504' do
error_original_body = {
messages: [
{
'key' => 'timeout',
'severity' => 'ERROR',
'text' => 'external service timeout'
}
]
}

let(:external_timeout) do
Common::Exceptions::BackendServiceException.new(
backtrace.backtrace,
{ status: 504, detail: 'timeout' },
504,
error_original_body
)
end

let(:external_timeout_submit) { ClaimsApi::CustomError.new(external_timeout) }

it 'raises a 502' do
external_timeout_submit.build_error
rescue => e
expect(e.errors[0][:status]).to eq('502')
expect(e.errors[0][:title]).to eq('Bad gateway')
expect(e.errors[0][:detail]).to eq('The server received an invalid or null response from an upstream server.')
end
end
end
Loading

0 comments on commit cac2288

Please sign in to comment.