Skip to content

Commit

Permalink
Merge branch 'master' into tdc/add-totals-rows-to-monthly-report
Browse files Browse the repository at this point in the history
  • Loading branch information
tycol7 authored Sep 10, 2024
2 parents 635da40 + 723a612 commit 85170aa
Show file tree
Hide file tree
Showing 15 changed files with 182 additions and 26 deletions.
10 changes: 10 additions & 0 deletions app/controllers/concerns/form_attachment_create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

module FormAttachmentCreate
extend ActiveSupport::Concern
include SentryLogging

def create
validate_file_upload_class!
Expand All @@ -22,14 +23,23 @@ def validate_file_upload_class!
unless filtered_params[:file_data].class.name.include? 'UploadedFile'
raise Common::Exceptions::InvalidFieldValue.new('file_data', filtered_params[:file_data].class.name)
end
rescue => e
log_exception_to_sentry(e, { context: 'FAC_validate', class: filtered_params[:file_data].class.name })
raise e
end

def save_attachment_to_cloud!
form_attachment.set_file_data!(filtered_params[:file_data], filtered_params[:password])
rescue => e
log_exception_to_sentry(e, { context: 'FAC_cloud' })
raise e
end

def save_attachment_to_db!
form_attachment.save!
rescue => e
log_exception_to_sentry(e, { context: 'FAC_db', errors: form_attachment.errors })
raise e
end

def form_attachment
Expand Down
8 changes: 7 additions & 1 deletion app/controllers/v0/benefits_claims_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ def submit5103
# for file number here
::Rails.logger.info('[5103 Submission] No file number') if @current_user.birls_id.nil?

res = service.submit5103(params[:id])
json_payload = request.body.read

data = JSON.parse(json_payload)

tracked_item_id = data['trackedItemId'] || nil

res = service.submit5103(params[:id], tracked_item_id)

render json: res
end
Expand Down
12 changes: 4 additions & 8 deletions config/features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -818,10 +818,6 @@ features:
actor_type: user
description: Enables MHV integration to point the Medical Records application on VA.gov
enable_in_development: true
mhv_secure_messaging_to_phase_1:
actor_type: user
description: Enables/disables Secure Messaging Phase 1 on VA.gov
enable_in_development: true
mhv_secure_messaging_cerner_pilot:
actor_type: user
description: Enables/disables Secure Messaging Cerner Transition Pilot environment on VA.gov
Expand Down Expand Up @@ -902,6 +898,10 @@ features:
actor_type: user
description: Enables/disables allergies and reactions data
enable_in_development: true
mhv_medications_display_filter:
actor_type: user
description: Enables/disables filter feature for medications list
enable_in_development: true
mhv_to_logingov_account_transition:
actor_type: cookie_id
description: Enables/disables MHV to Login.gov account transfer experience (Identity)
Expand Down Expand Up @@ -937,10 +937,6 @@ features:
organic_conversion_experiment:
actor_type: user
description: Toggle to enable login.gov create account experiment
pdf_warning_banner:
description: When enabled, will allow display of PDF cert warnings in find-a-form
actor_type: user
enable_in_development: true
pension_income_and_assets_clarification:
actor_type: user
description: >
Expand Down
3 changes: 3 additions & 0 deletions config/redis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ development: &defaults
brd_response_store:
namespace: brd_response_store
each_ttl: 82800
bgs_find_poas_response:
namespace: bgs_find_poas_response
each_ttl: 86400
test:
<<: *defaults
redis:
Expand Down
18 changes: 11 additions & 7 deletions lib/lighthouse/benefits_claims/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ def initialize(icn)
end

def get_claims(lighthouse_client_id = nil, lighthouse_rsa_key_path = nil, options = {})
Rails.logger.info("Get claims - icn: #{@icn.present?}, client_id: #{lighthouse_client_id.present?},
lighthouse_rsa: #{lighthouse_rsa_key_path.present?}")
claims = config.get("#{@icn}/claims", lighthouse_client_id, lighthouse_rsa_key_path, options).body
claims['data'] = filter_by_status(claims['data'])
claims
Expand All @@ -34,9 +32,6 @@ def get_claims(lighthouse_client_id = nil, lighthouse_rsa_key_path = nil, option
end

def get_claim(id, lighthouse_client_id = nil, lighthouse_rsa_key_path = nil, options = {})
Rails.logger.info("Get claim - icn: #{@icn.present?}, get_claim: #{id.present?},
client_id: #{lighthouse_client_id.present?},
lighthouse_rsa: #{lighthouse_rsa_key_path.present?}")
config.get("#{@icn}/claims/#{id}", lighthouse_client_id, lighthouse_rsa_key_path, options).body
rescue Faraday::TimeoutError
raise BenefitsClaims::ServiceException.new({ status: 504 }), 'Lighthouse Error'
Expand All @@ -52,8 +47,17 @@ def get_power_of_attorney(lighthouse_client_id = nil, lighthouse_rsa_key_path =
raise BenefitsClaims::ServiceException.new(e.response), 'Lighthouse Error'
end

def submit5103(id, options = {})
config.post("#{@icn}/claims/#{id}/5103", {}, nil, nil, options).body
def submit5103(id, tracked_item_id = nil, options = {})
config.post("#{@icn}/claims/#{id}/5103", {
data: {
type: 'form/5103',
attributes: {
trackedItemIds: [
tracked_item_id
]
}
}
}, nil, nil, options).body
rescue Faraday::TimeoutError
raise BenefitsClaims::ServiceException.new({ status: 504 }), 'Lighthouse Error'
rescue Faraday::ClientError, Faraday::ServerError => e
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ def begin_date_exception(idx)
)
end

def validate_form_526_location_codes(service_information)
def validate_form_526_location_codes(service_information) # rubocop:disable Metrics/MethodLength
service_periods = service_information['servicePeriods']
any_code_present = service_periods.any? do |service_period|
service_period['separationLocationCode'].present?
Expand All @@ -727,7 +727,12 @@ def validate_form_526_location_codes(service_information)
separation_location_ids = separation_locations.pluck(:id).to_set(&:to_s)

service_periods.each_with_index do |service_period, idx|
next if separation_location_ids.include?(service_period['separationLocationCode'])
separation_location_code = service_period['separationLocationCode']

next if separation_location_ids.include?(separation_location_code)

ClaimsApi::Logger.log('separation_location_codes', detail: 'Separation location code not found',
separation_locations:, separation_location_code:)

collect_error_messages(
source: "/serviceInformation/servicePeriods/#{idx}/separationLocationCode",
Expand Down
15 changes: 15 additions & 0 deletions modules/claims_api/lib/bgs_service/redis/find_poas_response.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module ClaimsApi
class FindPOAsResponse
attr_reader :response

def initialize(response)
@response = response
end

def cache?
@response.is_a?(Array) && @response.size.positive?
end
end
end
41 changes: 41 additions & 0 deletions modules/claims_api/lib/bgs_service/redis/find_poas_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# frozen_string_literal: true

require 'common/models/redis_store'
require 'common/models/concerns/cache_aside'
require 'bgs_service/standard_data_web_service'
require 'bgs_service/redis/find_poas_response'

module ClaimsApi
class FindPOAsService < ::Common::RedisStore
include ::Common::CacheAside

redis_config_key :bgs_find_poas_response

def response
@response ||= response_from_redis_or_service.response
end

private

def todays_date
Time.zone.now.to_date.to_s
end

def response_from_redis_or_service
do_cached_with(key: todays_date) do
response = standard_data_web_service.find_poas

ClaimsApi::FindPOAsResponse.new(filter_response(response))
end
end

def filter_response(response)
response.map { |poa| poa.slice(:legacy_poa_cd, :ptcpnt_id) }
end

def standard_data_web_service
@service ||= ClaimsApi::StandardDataWebService.new(external_uid: 'find_poas_service_uid',
external_key: 'find_poas_service_key')
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# frozen_string_literal: true

require 'rails_helper'
require 'bgs_service/redis/find_poas_service'

describe ClaimsApi::FindPOAsService do
describe '#response' do
context 'when the response is not cached' do
it 'calls bgs and returns the response' do
VCR.use_cassette('claims_api/bgs/standard_data_web_service/find_poas') do
service = described_class.new
allow(service).to receive(:standard_data_web_service).and_call_original
response = service.response

expect(service).to have_received(:standard_data_web_service)
expect(response).to be_an_instance_of(Array)
expect(response.first).to include(:legacy_poa_cd, :ptcpnt_id)
end
end
end

context 'when the response is cached' do
it 'does not call bgs and returns the cached response' do
VCR.use_cassette('claims_api/bgs/standard_data_web_service/find_poas') do
# Call BGS and cache the response
first_service = described_class.new
first_service.response

# The second service should not call BGS
second_service = described_class.new
allow(second_service).to receive(:standard_data_web_service).and_call_original
second_service.response

expect(second_service).not_to have_received(:standard_data_web_service)
expect(second_service.response).to be_an_instance_of(Array)
expect(second_service.response.first).to include(:legacy_poa_cd, :ptcpnt_id)
end
end
end
end
end
6 changes: 3 additions & 3 deletions spec/controllers/v0/benefits_claims_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,15 @@
describe '#submit5103' do
it 'returns a status of 200' do
VCR.use_cassette('lighthouse/benefits_claims/submit5103/200_response') do
post(:submit5103, params: { id: '600397108' })
post(:submit5103, params: { id: '600397108', trackedItemId: 12_345 }, as: :json)
end

expect(response).to have_http_status(:ok)
end

it 'returns a status of 404' do
VCR.use_cassette('lighthouse/benefits_claims/submit5103/404_response') do
post(:submit5103, params: { id: '600397108' })
post(:submit5103, params: { id: '600397108', trackedItemId: 12_345 }, as: :json)
end

expect(response).to have_http_status(:not_found)
Expand All @@ -235,7 +235,7 @@
context 'when LH takes too long to respond' do
it 'returns a status of 504' do
allow_any_instance_of(BenefitsClaims::Configuration).to receive(:post).and_raise(Faraday::TimeoutError)
post(:submit5103, params: { id: '60038334' })
post(:submit5103, params: { id: '600397108', trackedItemId: 12_345 }, as: :json)

expect(response).to have_http_status(:gateway_timeout)
end
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 85170aa

Please sign in to comment.