Skip to content

Commit

Permalink
Merge branch 'master' into API-42322-Extract-OrgWebServiceBean-from-l…
Browse files Browse the repository at this point in the history
…ocalBGS
  • Loading branch information
mchristiansonVA authored Dec 17, 2024
2 parents fa663a7 + ef3c028 commit 4735c99
Show file tree
Hide file tree
Showing 14 changed files with 247 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ def separation_locations
:all_users,
:get_separation_locations
) do
provider = Flipper.enabled?(:disability_compensation_staging_lighthouse_brd) ? :lighthouse_staging : nil
api_provider = ApiProviderFactory.call(
type: ApiProviderFactory::FACTORIES[:brd],
provider: nil,
provider:,
options: {},
current_user: @current_user,
feature_toggle: ApiProviderFactory::FEATURE_TOGGLE_BRD
Expand Down
3 changes: 3 additions & 0 deletions config/features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ features:
caregiver_retry_form_validation:
actor_type: user
description: Enables 1010CG to retry schema validation
disability_compensation_staging_lighthouse_brd:
actor_type: user
description: Switches to Lighthouse Staging BRD Service. NEVER ENABLE IN PRODUCTION.
hca_browser_monitoring_enabled:
actor_type: user
description: Enables browser monitoring for the health care application.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
require 'disability_compensation/providers/brd/brd_provider'
require 'disability_compensation/providers/brd/evss_brd_provider'
require 'disability_compensation/providers/brd/lighthouse_brd_provider'
require 'disability_compensation/providers/brd/lighthouse_staging_brd_provider'
require 'disability_compensation/providers/generate_pdf/generate_pdf_provider'
require 'disability_compensation/providers/generate_pdf/evss_generate_pdf_provider'
require 'disability_compensation/providers/generate_pdf/lighthouse_generate_pdf_provider'
Expand All @@ -28,7 +29,8 @@ class UndefinedFactoryTypeError < StandardError; end

API_PROVIDER = {
evss: :evss,
lighthouse: :lighthouse
lighthouse: :lighthouse,
lighthouse_staging: :lighthouse_staging
}.freeze

FACTORIES = {
Expand Down Expand Up @@ -166,6 +168,8 @@ def brd_service_provider
EvssBRDProvider.new(@current_user)
when API_PROVIDER[:lighthouse]
LighthouseBRDProvider.new(@current_user)
when API_PROVIDER[:lighthouse_staging]
LighthouseStagingBRDProvider.new(@current_user)
else
raise NotImplementedError, 'No known BRD Api Provider type provided'
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

require 'disability_compensation/providers/brd/lighthouse_brd_provider'
require 'lighthouse/benefits_reference_data_staging/service'

class LighthouseStagingBRDProvider < LighthouseBRDProvider
def initialize(_current_user)
super
@service = BenefitsReferenceData::Staging::Service.new
end
end
68 changes: 68 additions & 0 deletions lib/lighthouse/benefits_reference_data_staging/configuration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# frozen_string_literal: true

require 'common/client/configuration/rest'
require 'faraday/multipart'

module BenefitsReferenceData
##
# HTTP client configuration for the {BenefitsReferenceData::Service},
# sets the base path, the base request headers, and a service name for breakers and metrics.

module Staging
class Configuration < Common::Client::Configuration::REST
self.read_timeout = Settings.lighthouse.benefits_reference_data.timeout || 20

##
# @return [String] Base path for benefits_reference_data URLs.
#
def base_path
settings = Settings.lighthouse.benefits_reference_data
url = settings.staging_url
path = settings.path
version = settings.version
safe_slash_merge(url, path, version)
end

##
# @return [String] Service name to use in breakers and metrics.
#
def service_name
'BenefitsReferenceDataStaging'
end

##
# @return [Hash] The basic headers required for any benefits_reference_data API call.
#
def self.base_request_headers
key = Settings.lighthouse.staging_api_key
message = "No api_key set for LH benefits_reference_data_staging. Please set 'lighthouse.staging_api_key'"
raise message if key.nil?

super.merge('apiKey' => key)
end

##
# Creates the a connection with parsing json and adding breakers functionality.
#
# @return [Faraday::Connection] a Faraday connection instance.
#
def connection
@conn ||= Faraday.new(base_path, headers: base_request_headers, request: request_options) do |faraday|
faraday.use :breakers
faraday.use Faraday::Response::RaiseError

faraday.request :multipart
faraday.request :json
faraday.response :json
faraday.adapter Faraday.default_adapter
end
end

private

def safe_slash_merge(*url_segments)
url_segments.map { |segment| segment.sub(%r{^/}, '').chomp('/') }.join('/')
end
end
end
end
45 changes: 45 additions & 0 deletions lib/lighthouse/benefits_reference_data_staging/service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# frozen_string_literal: true

require 'common/client/base'
require 'common/client/concerns/monitoring'
require 'common/client/errors'
require 'common/exceptions/forbidden'
require 'common/exceptions/schema_validation_errors'
require 'lighthouse/benefits_reference_data_staging/configuration'
require 'lighthouse/benefits_reference_data/service_exception'

module BenefitsReferenceData
##
# Proxy Service for the Lighthouse Benefits Reference Data API.

module Staging
class Service < Common::Client::Base
include SentryLogging
include Common::Client::Concerns::Monitoring

configuration BenefitsReferenceData::Staging::Configuration

# ap @configuration.base_request_headers; exit

STATSD_KEY_PREFIX = 'api.benefits_reference_data_staging'

##
# Hit a Benefits Reference Data End-point
#
# @path end-point [string|symbol] a string or symbol of the end-point you wish to hit.
# @params params hash [Hash] a hash of key-value pairs of parameters
#
# @return [Faraday::Response]
#
def get_data(path:, params: {})
headers = config.base_request_headers
begin
response = perform :get, path, params, headers
rescue => e
raise BenefitsReferenceData::ServiceException.new(e), 'Lighthouse Error'
end
response
end
end
end
end
11 changes: 9 additions & 2 deletions modules/ivc_champva/app/services/ivc_champva/attachments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module IvcChampva
module Attachments
attr_accessor :form_id, :uuid, :data

def handle_attachments(file_path)
def handle_attachments(file_path) # rubocop:disable Metrics/MethodLength
file_paths = [file_path]
attachments = get_attachments

Expand All @@ -22,7 +22,14 @@ def handle_attachments(file_path)
File.join(File.dirname(attachment), new_file_name)
end

File.rename(attachment, new_file_path)
if Flipper.enabled?(:champva_pdf_decrypt, @current_user)
# Use FileUtils.mv to handle `Errno::EXDEV` error since encrypted PDFs
# get stashed in the clamav_tmp dir which is a different device on staging, apparently
FileUtils.mv(attachment, new_file_path) # Performs a copy automatically if mv fails
else
File.rename(attachment, new_file_path)
end

file_paths << new_file_path
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,9 @@ def get_first_name_from_user

def get_personalization(first_name)
if @form_number.start_with? 'vba_21_0966'
default_personalization(first_name).merge(form21_0966_personalization)
personalization = default_personalization(first_name).merge(form21_0966_personalization)
personalization.except!('lighthouse_updated_at') unless lighthouse_updated_at
personalization
else
default_personalization(first_name)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,6 @@
'first_name' => 'Veteran',
'date_submitted' => Time.zone.today.strftime('%B %d, %Y'),
'confirmation_number' => confirmation_number,
'lighthouse_updated_at' => nil,
'intent_to_file_benefits' => 'survivors pension benefits',
'intent_to_file_benefits_links' => '[Apply for DIC, Survivors Pension, and/or Accrued Benefits ' \
'(VA Form 21P-534EZ)](https://www.va.gov/find-forms/about-form-21p-534ez/)',
Expand All @@ -942,7 +941,6 @@
'first_name' => 'Veteran',
'date_submitted' => Time.zone.today.strftime('%B %d, %Y'),
'confirmation_number' => confirmation_number,
'lighthouse_updated_at' => nil,
'intent_to_file_benefits' => 'survivors pension benefits',
'intent_to_file_benefits_links' => '[Apply for DIC, Survivors Pension, and/or Accrued Benefits ' \
'(VA Form 21P-534EZ)](https://www.va.gov/find-forms/about-form-21p-534ez/)',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,7 @@
end

describe '21_0966' do
let(:lighthouse_updated_at) { 1.day.ago }
let(:date_submitted) { Time.zone.today.strftime('%B %d, %Y') }
let(:data) do
fixture_path = Rails.root.join(
Expand All @@ -794,7 +795,7 @@
end
let(:config) do
{ form_data: data, form_number: 'vba_21_0966',
confirmation_number: 'confirmation_number', date_submitted: }
confirmation_number: 'confirmation_number', date_submitted:, lighthouse_updated_at: }
end
let(:user) { create(:user, :loa3) }

Expand All @@ -812,7 +813,7 @@
'first_name' => 'Veteran',
'date_submitted' => date_submitted,
'confirmation_number' => 'confirmation_number',
'lighthouse_updated_at' => nil,
'lighthouse_updated_at' => lighthouse_updated_at,
'intent_to_file_benefits' => 'survivors pension benefits',
'intent_to_file_benefits_links' => '[Apply for DIC, Survivors Pension, and/or Accrued Benefits ' \
'(VA Form 21P-534EZ)](https://www.va.gov/find-forms/about-form-21p-534ez/)',
Expand Down Expand Up @@ -841,7 +842,7 @@
'first_name' => 'I',
'date_submitted' => date_submitted,
'confirmation_number' => 'confirmation_number',
'lighthouse_updated_at' => nil,
'lighthouse_updated_at' => lighthouse_updated_at,
'intent_to_file_benefits' => 'survivors pension benefits',
'intent_to_file_benefits_links' => '[Apply for DIC, Survivors Pension, and/or Accrued Benefits ' \
'(VA Form 21P-534EZ)](https://www.va.gov/find-forms/about-form-21p-534ez/)',
Expand Down Expand Up @@ -884,7 +885,6 @@
'first_name' => 'Veteran',
'date_submitted' => date_submitted,
'confirmation_number' => 'confirmation_number',
'lighthouse_updated_at' => nil,
'intent_to_file_benefits' => 'survivors pension benefits',
'intent_to_file_benefits_links' => '[Apply for DIC, Survivors Pension, and/or Accrued Benefits ' \
'(VA Form 21P-534EZ)](https://www.va.gov/find-forms/about-form-21p-534ez/)',
Expand Down Expand Up @@ -913,7 +913,6 @@
'first_name' => 'I',
'date_submitted' => date_submitted,
'confirmation_number' => 'confirmation_number',
'lighthouse_updated_at' => nil,
'intent_to_file_benefits' => 'survivors pension benefits',
'intent_to_file_benefits_links' => '[Apply for DIC, Survivors Pension, and/or Accrued Benefits ' \
'(VA Form 21P-534EZ)](https://www.va.gov/find-forms/about-form-21p-534ez/)',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
context 'evss' do
before do
Flipper.disable('disability_compensation_lighthouse_brd')
Flipper.disable('disability_compensation_staging_lighthouse_brd')
end

it 'returns separation locations' do
Expand All @@ -39,6 +40,7 @@
context 'lighthouse' do
before do
Flipper.enable('disability_compensation_lighthouse_brd')
Flipper.disable('disability_compensation_staging_lighthouse_brd')
end

after(:all) do
Expand All @@ -61,6 +63,34 @@
end
end
end

context 'lighthouse staging' do
before do
Flipper.enable('disability_compensation_lighthouse_brd')
Flipper.enable('disability_compensation_staging_lighthouse_brd')
end

after(:all) do
Flipper.disable('disability_compensation_lighthouse_brd')
Flipper.disable('disability_compensation_staging_lighthouse_brd')
end

it 'returns separation locations' do
VCR.use_cassette('brd/separation_locations_staging') do
get(:separation_locations)
expect(JSON.parse(response.body)['separation_locations'].present?).to eq(true)
end
end

it 'uses the cached response on the second request' do
VCR.use_cassette('brd/separation_locations_staging') do
2.times do
get(:separation_locations)
expect(response.status).to eq(200)
end
end
end
end
end

describe '#rating_info' do
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

require 'rails_helper'
require 'disability_compensation/factories/api_provider_factory'
require 'disability_compensation/providers/brd/lighthouse_staging_brd_provider'
require 'support/disability_compensation_form/shared_examples/brd_provider'
require 'lighthouse/service_exception'

RSpec.describe LighthouseStagingBRDProvider do
let(:current_user) { build(:user, :loa3) }

before do
@provider = LighthouseStagingBRDProvider.new(current_user)
Flipper.enable(ApiProviderFactory::FEATURE_TOGGLE_BRD)
Flipper.enable(:disability_compensation_staging_lighthouse_brd)
end

after do
Flipper.disable(ApiProviderFactory::FEATURE_TOGGLE_BRD)
Flipper.disable(:disability_compensation_staging_lighthouse_brd)
end

it_behaves_like 'brd provider'

it 'retrieves separation locations from the Lighthouse API' do
VCR.use_cassette('brd/separation_locations_staging') do
response = @provider.get_separation_locations
expect(response.separation_locations.length).to eq(327)
end
end
end
1 change: 1 addition & 0 deletions spec/requests/swagger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,7 @@
Flipper.disable('disability_compensation_prevent_submission_job')
Flipper.disable(ApiProviderFactory::FEATURE_TOGGLE_BRD)
Flipper.disable('disability_compensation_production_tester')
Flipper.disable(:disability_compensation_staging_lighthouse_brd)
end

let(:form526v2) do
Expand Down
Loading

0 comments on commit 4735c99

Please sign in to comment.