Skip to content

Commit

Permalink
unmix miscellaneous LocalBGS operations
Browse files Browse the repository at this point in the history
...and turn it into its own service
  • Loading branch information
nihil2501 committed Apr 22, 2024
1 parent bb11a03 commit 5c8bec4
Show file tree
Hide file tree
Showing 34 changed files with 97 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def claims_service
end

def local_bgs_service
@local_bgs_service ||= ClaimsApi::LocalBGS.new(
@local_bgs_service ||= ClaimsApi::MiscellaneousBGSOperations.new(
external_uid: target_veteran.participant_id,
external_key: target_veteran.participant_id
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def bgs_service

def local_bgs_service
external_key = target_veteran.participant_id.to_s
@local_bgs_service ||= ClaimsApi::LocalBGS.new(
@local_bgs_service ||= ClaimsApi::MiscellaneousBGSOperations.new(
external_uid: external_key,
external_key:
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

require 'evss/intent_to_file/service'
require 'bgs_service/local_bgs'
require 'bgs_service/miscellaneous_bgs_operations'

module ClaimsApi
module V1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

require 'bgs/power_of_attorney_verifier'
require 'bgs_service/local_bgs'
require 'bgs_service/miscellaneous_bgs_operations'

module ClaimsApi
module V1
Expand Down Expand Up @@ -227,7 +227,7 @@ def build_representative_info(poa_code)

def find_by_ssn(ssn)
# rubocop:disable Rails/DynamicFindBy
ClaimsApi::LocalBGS.new(
ClaimsApi::MiscellaneousBGSOperations.new(
external_uid: target_veteran.participant_id,
external_key: target_veteran.participant_id
).find_by_ssn(ssn)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require 'token_validation/v2/client'
require 'claims_api/error/error_handler'
require 'claims_api/claim_logger'
require 'bgs_service/local_bgs'
require 'bgs_service/miscellaneous_bgs_operations'
require 'claims_api/form_schemas'
require 'claims_api/v2/benefits_documents/service'
require 'bd/bd'
Expand Down Expand Up @@ -81,7 +81,7 @@ def bgs_service
end

def local_bgs_service
@local_bgs_service ||= ClaimsApi::LocalBGS.new(
@local_bgs_service ||= ClaimsApi::MiscellaneousBGSOperations.new(
external_uid: target_veteran.participant_id,
external_key: target_veteran.participant_id
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

require 'claims_api/v2/params_validation/intent_to_file'
require 'bgs_service/local_bgs'
require 'bgs_service/miscellaneous_bgs_operations'

module ClaimsApi
module V2
Expand Down
31 changes: 31 additions & 0 deletions modules/claims_api/lib/bgs_service/bgs_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

module ClaimsApi
module BGSHelpers
def convert_nil_values(options)
arg_strg = ''
options.each do |option|
arg = option[0].to_s.camelize(:lower)
arg_strg += (option[1].nil? ? "<#{arg} xsi:nil='true'/>" : "<#{arg}>#{option[1]}</#{arg}>")
end
arg_strg
end

def validate_opts!(opts, required_keys)
keys = opts.keys.map(&:to_s)
required_keys = required_keys.map(&:to_s)
missing_keys = required_keys - keys
raise ArgumentError, "Missing required keys: #{missing_keys.join(', ')}" if missing_keys.present?
end

def jrn
{
jrn_dt: Time.current.iso8601,
jrn_lctn_id: Settings.bgs.client_station_id,
jrn_status_type_cd: 'U',
jrn_user_id: Settings.bgs.client_username,
jrn_obj_id: Settings.bgs.application
}
end
end
end
2 changes: 1 addition & 1 deletion modules/claims_api/lib/bgs_service/local_bgs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

require 'claims_api/claim_logger'
require 'claims_api/error/soap_error_handler'
require_relative 'local_bgs/miscellaneous_operations'
require 'bgs_service/bgs_helpers'

module ClaimsApi
class LocalBGS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'claims_api/evss_bgs_mapper'

module ClaimsApi
class LocalBGS
class MiscellaneousBGSOperations < ClaimsApi::LocalBGS
def find_poa_by_participant_id(id)
body = Nokogiri::XML::DocumentFragment.parse <<~EOXML
<ptcpntId />
Expand Down Expand Up @@ -168,31 +168,5 @@ def transform_bgs_claims_to_evss(claims)
bgs_claim.map_and_build_object
end
end

def convert_nil_values(options)
arg_strg = ''
options.each do |option|
arg = option[0].to_s.camelize(:lower)
arg_strg += (option[1].nil? ? "<#{arg} xsi:nil='true'/>" : "<#{arg}>#{option[1]}</#{arg}>")
end
arg_strg
end

def validate_opts!(opts, required_keys)
keys = opts.keys.map(&:to_s)
required_keys = required_keys.map(&:to_s)
missing_keys = required_keys - keys
raise ArgumentError, "Missing required keys: #{missing_keys.join(', ')}" if missing_keys.present?
end

def jrn
{
jrn_dt: Time.current.iso8601,
jrn_lctn_id: Settings.bgs.client_station_id,
jrn_status_type_cd: 'U',
jrn_user_id: Settings.bgs.client_username,
jrn_obj_id: Settings.bgs.application
}
end
end
end
2 changes: 2 additions & 0 deletions modules/claims_api/lib/bgs_service/vnp_atchms_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

module ClaimsApi
class VnpAtchmsService < ClaimsApi::LocalBGS
include ClaimsApi::BGSHelpers

# Takes an object with a minimum of (other fields are camelized and passed to BGS):
# vnp_proc_id: BGS procID
# atchms_file_nm: File name
Expand Down
2 changes: 2 additions & 0 deletions modules/claims_api/lib/bgs_service/vnp_person_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

module ClaimsApi
class VnpPersonService < ClaimsApi::LocalBGS
include ClaimsApi::BGSHelpers

# Takes an object with a minimum of (other fields are camelized and passed to BGS):
# vnp_proc_id: BGS procID
# vnp_ptcpnt_id: Veteran's participant id
Expand Down
2 changes: 2 additions & 0 deletions modules/claims_api/lib/bgs_service/vnp_proc_form_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

module ClaimsApi
class VnpProcFormService < ClaimsApi::LocalBGS
include ClaimsApi::BGSHelpers

FORM_TYPE_CD = '21-22'

def vnp_proc_form_create(options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

module ClaimsApi
class VnpPtcpntAddrsService < ClaimsApi::LocalBGS
include ClaimsApi::BGSHelpers

def vnp_ptcpnt_addrs_create(options)
arg_strg = convert_nil_values(options)
body = Nokogiri::XML::DocumentFragment.parse <<~EOXML
Expand Down
2 changes: 2 additions & 0 deletions modules/claims_api/lib/bgs_service/vnp_ptcpnt_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

module ClaimsApi
class VnpPtcpntService < ClaimsApi::LocalBGS
include ClaimsApi::BGSHelpers

# vnpPtcpntCreate - This service is used to create VONAPP participant information
def vnp_ptcpnt_create(options)
arg_strg = convert_nil_values(options)
Expand Down
18 changes: 7 additions & 11 deletions modules/claims_api/spec/lib/claims_api/local_bgs_spec.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
# frozen_string_literal: true

require 'rails_helper'
require 'bgs_service/local_bgs'
require 'bgs_service/miscellaneous_bgs_operations'
require 'claims_api/error/soap_error_handler'

describe ClaimsApi::LocalBGS do
describe ClaimsApi::MiscellaneousBGSOperations do
subject { described_class.new external_uid: 'xUid', external_key: 'xKey' }

let(:soap_error_handler) { ClaimsApi::SoapErrorHandler.new }

describe '#find_poa_by_participant_id' do
it 'responds as expected, with extra ClaimsApi::Logger logging' do
VCR.use_cassette('claims_api/bgs/claimant_web_service/find_poa_by_participant_id') do
allow_any_instance_of(BGS::OrgWebService).to receive(:find_poa_history_by_ptcpnt_id).and_return({})

# Events logged:
# 1: establish_ssl_connection - how long to establish the connection
# 2: connection_wsdl_get - duration of WSDL request cycle
# 1: connection_wsdl_get - duration of WSDL request cycle
# 2: built_request - how long to build the request
# 3: connection_post - how long does the post itself take for the request cycle
# 4: parsed_response - how long to parse the response
expect(ClaimsApi::Logger).to receive(:log).exactly(4).times
Expand Down Expand Up @@ -44,9 +42,7 @@
it 'triggers StatsD measurements' do
VCR.use_cassette('claims_api/bgs/claimant_web_service/find_poa_by_participant_id',
allow_playback_repeats: true) do
allow_any_instance_of(BGS::OrgWebService).to receive(:find_poa_history_by_ptcpnt_id).and_return({})

%w[establish_ssl_connection connection_wsdl_get connection_post parsed_response].each do |event|
%w[connection_wsdl_get built_request connection_post parsed_response].each do |event|
expect { subject.find_poa_by_participant_id('does-not-matter') }
.to trigger_statsd_measure("api.claims_api.local_bgs.#{event}.duration")
end
Expand Down Expand Up @@ -107,9 +103,9 @@
),
key: 'PersonDTO').and_return(:bgs_unknown_error_message)
begin
allow(soap_error_handler).to receive(:handle_errors)
allow(soap_error_handler).to receive(:handle_errors!)
.with(:bgs_unknown_error_message).and_raise(Common::Exceptions::UnprocessableEntity)
ret = soap_error_handler.send(:handle_errors, :bgs_unknown_error_message)
ret = soap_error_handler.send(:handle_errors!, :bgs_unknown_error_message)
expect(ret.class).to_be Array
expect(ret.size).to eq 1
rescue => e
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
)
end

let(:ows) { ClaimsApi::LocalBGS }
let(:ows) { ClaimsApi::MiscellaneousBGSOperations }

it 'initializes from a user' do
VCR.use_cassette('claims_api/bgs/claimant_web_service/find_poa_by_participant_id') do
Expand Down
2 changes: 1 addition & 1 deletion modules/claims_api/spec/requests/v1/claims_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
end
let(:claims_service) do
if Flipper.enabled? :claims_status_v1_bgs_enabled
ClaimsApi::LocalBGS
ClaimsApi::MiscellaneousBGSOperations
else
ClaimsApi::UnsynchronizedEVSSClaimService
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'rails_helper'
require_relative '../../rails_helper'
require 'bgs_service/local_bgs'
require 'bgs_service/miscellaneous_bgs_operations'

RSpec.describe 'Intent to file', type: :request do
let(:headers) do
Expand Down Expand Up @@ -151,7 +151,7 @@
describe 'handling the claimant fields' do
context "when 'participant_claimant_id' is provided" do
it 'that field and value are sent to BGS' do
expect_any_instance_of(ClaimsApi::LocalBGS)
expect_any_instance_of(ClaimsApi::MiscellaneousBGSOperations)
.to receive(:insert_intent_to_file).with(hash_including(participant_claimant_id: '123')).and_return({})

mock_acg(scopes) do |auth_header|
Expand All @@ -163,7 +163,7 @@

context "when 'claimant_ssn' is provided" do
it 'that field and value are sent to BGS' do
expect_any_instance_of(ClaimsApi::LocalBGS)
expect_any_instance_of(ClaimsApi::MiscellaneousBGSOperations)
.to receive(:insert_intent_to_file).with(hash_including(claimant_ssn: '123')).and_return({})

mock_acg(scopes) do |auth_header|
Expand All @@ -179,7 +179,7 @@
end

it "'participant_claimant_id' is set to the target_veteran.participant_id and sent to BGS " do
expect_any_instance_of(ClaimsApi::LocalBGS)
expect_any_instance_of(ClaimsApi::MiscellaneousBGSOperations)
.to receive(:insert_intent_to_file).with(hash_including(participant_claimant_id: '999')).and_return({})

mock_acg(scopes) do |auth_header|
Expand All @@ -190,7 +190,7 @@

context "when both 'participant_claimant_id' and 'claimant_ssn' are provided" do
it "both 'participant_claimant_id' and 'claimant_ssn' are sent to BGS " do
expect_any_instance_of(ClaimsApi::LocalBGS)
expect_any_instance_of(ClaimsApi::MiscellaneousBGSOperations)
.to receive(:insert_intent_to_file).with(
hash_including(
participant_claimant_id: '123', claimant_ssn: '456'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'rails_helper'
require_relative '../../rails_helper'
require 'bgs_service/local_bgs'
require 'bgs_service/miscellaneous_bgs_operations'

RSpec.describe 'Power of Attorney ', type: :request do
let(:headers) do
Expand All @@ -20,7 +20,7 @@
profile: FactoryBot.build(:mpi_profile, participant_id: nil, participant_ids: %w[123456789 987654321])
)
end
let(:pws) { ClaimsApi::LocalBGS }
let(:pws) { ClaimsApi::MiscellaneousBGSOperations }

before do
stub_poa_verification
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
before do |example|
stub_poa_verification

allow_any_instance_of(ClaimsApi::LocalBGS).to receive(:all).and_raise(
allow_any_instance_of(ClaimsApi::MiscellaneousBGSOperations).to receive(:all).and_raise(
Common::Exceptions::ResourceNotFound.new(detail: 'The Resource was not found.')
)
mock_acg(scopes) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
require_relative '../../support/swagger_shared_components/v1'

describe 'Power of Attorney', openapi_spec: 'modules/claims_api/app/swagger/claims_api/v1/swagger.json' do # rubocop:disable RSpec/DescribeClass
let(:pws) { ClaimsApi::LocalBGS }
let(:pws) { ClaimsApi::MiscellaneousBGSOperations }

path '/forms/2122' do
get 'Gets schema for POA form.' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'rails_helper'
require_relative '../../../rails_helper'
require 'token_validation/v2/client'
require 'bgs_service/local_bgs'
require 'bgs_service/miscellaneous_bgs_operations'

RSpec.describe 'Claims', type: :request do
let(:veteran_id) { '1013062086V794840' }
Expand All @@ -23,7 +23,7 @@
participant_ids: [])
)
end
let(:bcs) { ClaimsApi::LocalBGS }
let(:bcs) { ClaimsApi::MiscellaneousBGSOperations }
let(:profile_for_claimant_on_behalf_of_veteran) do
MPI::Responses::FindProfileResponse.new(
status: :ok,
Expand Down
Loading

0 comments on commit 5c8bec4

Please sign in to comment.