Skip to content

Commit

Permalink
Api 28113 replace bgs ext poa updater (#19325)
Browse files Browse the repository at this point in the history
* Adds flipper feature.

* Moves the find_by_ssn call to PersonWebService from LocalBgs.

* Adds VetRecordService to LocalBgs.

* Adds ability to switch between bgs-ext & local_bgs for vet_record & person_web_service.

* Getting successful responses, but getting 'BGS Error: update_birls_record failed with code BPNQ0100'

* Reverts instance variable. Adds definition. Adds PAYEE_NUMBER value.

* Refactors poa_updater. Replaces find_by_ssn in local_bgs due to many failing tests. Created a ticket to remove that method from local_bgs since it exists in two places.

* WIP: switching branches.

* Cleans up poa_updater. Adds definitions. Updates vcr cassette.

* Removes find_birls_record

* Corrects vet record service. Updates tests with flipper feature, and replaces vcr cassette.

* Updates person web service

* Removes method definitions.

* Renames flippers, separates features into two flippers. Adds two tests. Need to re-record vcr cassette.

* Updates test and shared vcr cassette.

* Adds flipper test.

* Adds tests for flipper.
  • Loading branch information
stiehlrod authored Dec 2, 2024
1 parent 929ee51 commit fc06924
Show file tree
Hide file tree
Showing 7 changed files with 1,026 additions and 294 deletions.
4 changes: 4 additions & 0 deletions config/features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ features:
actor_type: user
description: Uses person web service rather than local bgs
enable_in_development: true
claims_api_use_vet_record_service:
actor_type: user
description: Uses local_bgs rather than bgs-ext
enable_in_development: true
claims_api_526_v2_uploads_bd_refactor:
actor_type: user
description: When enabled, sends 526 forms to BD via the refactored logic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,27 @@ module CreateVeteranRepresentative
end

##
# VetRecordService
##
module VetRecordServiceBean
DEFINITION =
Bean.new(
path: 'VetRecordServiceBean',
namespaces: Namespaces.new(
target: 'http://services.share.benefits.vba.va.gov/',
data: nil
)
)
end

module VetRecordWebService
DEFINITION =
Service.new(
bean: VetRecordServiceBean::DEFINITION,
path: 'VetRecordWebService'
)
end

# VnpAtchmsWebServiceBean
#
module VnpAtchmsWebServiceBean
Expand Down
62 changes: 51 additions & 11 deletions modules/claims_api/app/sidekiq/claims_api/poa_updater.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
# frozen_string_literal: true

require 'bgs'
require 'bgs_service/person_web_service'
require 'bgs_service/vet_record_web_service'

module ClaimsApi
class PoaUpdater < ClaimsApi::ServiceBase
def perform(power_of_attorney_id, rep = nil) # rubocop:disable Metrics/MethodLength
def perform(power_of_attorney_id, rep = nil)
poa_form = ClaimsApi::PowerOfAttorney.find(power_of_attorney_id)
service = BGS::Services.new(
external_uid: poa_form.external_uid,
external_key: poa_form.external_key
)

ssn = poa_form.auth_headers['va_eauth_pnid']
file_number = service.people.find_by_ssn(ssn)[:file_nbr] # rubocop:disable Rails/DynamicFindBy

file_number = find_by_ssn(ssn, poa_form)
poa_code = extract_poa_code(poa_form.form_data)

response = service.vet_record.update_birls_record(
file_number:,
ssn:,
poa_code:
)
response = update_birls_record(file_number, ssn, poa_code, poa_form)

if response[:return_code] == 'BMOD0001'
poa_form.status = ClaimsApi::PowerOfAttorney::UPDATED
Expand Down Expand Up @@ -49,5 +44,50 @@ def vanotify?(auth_headers, rep)
false
end
end

def bgs_ext_service(poa_form)
BGS::Services.new(
external_uid: poa_form.external_uid,
external_key: poa_form.external_key
)
end

def person_web_service(poa_form)
ClaimsApi::PersonWebService.new(
external_uid: poa_form.external_uid,
external_key: poa_form.external_key
)
end

def vet_record_service(poa_form)
ClaimsApi::VetRecordWebService.new(
external_uid: poa_form.external_uid,
external_key: poa_form.external_key
)
end

def find_by_ssn(ssn, poa_form)
if Flipper.enabled? :claims_api_use_person_web_service
person_web_service(poa_form).find_by_ssn(ssn)[:file_nbr] # rubocop:disable Rails/DynamicFindBy
else
bgs_ext_service(poa_form).people.find_by_ssn(ssn)[:file_nbr] # rubocop:disable Rails/DynamicFindBy
end
end

def update_birls_record(file_number, ssn, poa_code, poa_form)
if Flipper.enabled? :claims_api_use_vet_record_service
vet_record_service(poa_form).update_birls_record(
file_number:,
ssn:,
poa_code:
)
else
bgs_ext_service(poa_form).vet_record.update_birls_record(
file_number:,
ssn:,
poa_code:
)
end
end
end
end
9 changes: 0 additions & 9 deletions modules/claims_api/lib/bgs_service/person_web_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,4 @@ def find_by_ssn(ssn)
make_request(endpoint: bean_name, action: 'findPersonBySSN', body:, key: 'PersonDTO')
end
end

# finds a PERSON row by SSN
def find_by_ssn(ssn)
body = Nokogiri::XML::DocumentFragment.parse <<~EOXML
<ssn>#{ssn}</ssn>
EOXML

make_request(endpoint: bean_name, action: 'findPersonBySSN', body:, key: 'PersonDTO')
end
end
24 changes: 24 additions & 0 deletions modules/claims_api/lib/bgs_service/vet_record_web_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

module ClaimsApi
class VetRecordWebService < ClaimsApi::LocalBGS
def bean_name
'VetRecordServiceBean/VetRecordWebService'
end

def update_birls_record(**options)
poa_code = options[:poa_code]
body = Nokogiri::XML::DocumentFragment.parse <<~EOML
<birlsUpdateInput>
<CLAIM_NUMBER>#{options[:file_number]}</CLAIM_NUMBER>
<SOC_SEC_NUM>#{options[:ssn]}</SOC_SEC_NUM>
<POWER_OF_ATTY_CODE1>#{poa_code[0]}</POWER_OF_ATTY_CODE1>
<POWER_OF_ATTY_CODE2>#{poa_code[1]}#{poa_code[2]}</POWER_OF_ATTY_CODE2>
<PAYEE_NUMBER>00</PAYEE_NUMBER>
</birlsUpdateInput>
EOML

make_request(endpoint: bean_name, body:, action: 'updateBirlsRecord', key: 'return')
end
end
end
46 changes: 45 additions & 1 deletion modules/claims_api/spec/sidekiq/poa_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

require 'rails_helper'

RSpec.describe ClaimsApi::PoaUpdater, type: :job do
RSpec.describe ClaimsApi::PoaUpdater, type: :job, vcr: 'bgs/person_web_service/find_by_ssn' do
subject { described_class }

before do
Sidekiq::Job.clear_all
allow(Flipper).to receive(:enabled?).with(:claims_api_use_vet_record_service).and_return false
allow(Flipper).to receive(:enabled?).with(:claims_api_use_person_web_service).and_return false
allow(Flipper).to receive(:enabled?).with(:lighthouse_claims_api_v2_poa_va_notify).and_return false
end

let(:user) { FactoryBot.create(:user, :loa3) }
Expand All @@ -19,6 +22,7 @@
context "when call to BGS 'update_birls_record' is successful" do
context 'and the poaCode is retrieved successfully from the V2 2122a form data' do
it "updates the form's status and creates 'ClaimsApi::PoaVBMSUpdater' job" do
allow(Flipper).to receive(:enabled?).with(:claims_api_use_person_web_service).and_return false
create_mock_lighthouse_service
expect(ClaimsApi::PoaVBMSUpdater).to receive(:perform_async)

Expand Down Expand Up @@ -114,6 +118,7 @@
context 'deciding to send a VA Notify email' do
before do
create_mock_lighthouse_service
allow(Flipper).to receive(:enabled?).with(:lighthouse_claims_api_v2_poa_va_notify).and_return true
end

let(:poa) { create_poa }
Expand All @@ -134,6 +139,7 @@

context 'when the flipper is on' do
it 'does not send the vanotify job' do
allow(Flipper).to receive(:enabled?).with(:lighthouse_claims_api_v2_poa_va_notify).and_return false
Flipper.disable(:lighthouse_claims_api_v2_poa_va_notify)

poa.auth_headers.merge!({
Expand Down Expand Up @@ -186,6 +192,44 @@
end
end

describe 'when the claims_api_use_person_web_service flipper is on' do
let(:person_web_service) { instance_double(ClaimsApi::PersonWebService) }

before do
allow(Flipper).to receive(:enabled?).with(:claims_api_use_person_web_service).and_return true
allow(ClaimsApi::PersonWebService).to receive(:new).with(external_uid: anything,
external_key: anything)
.and_return(person_web_service)
allow(person_web_service).to receive(:find_by_ssn).and_return({ file_nbr: '796111863' })
end

it 'calls local bgs person web service instead of bgs-ext' do
poa = create_poa
subject.new.perform(poa.id)

expect(person_web_service).to have_received(:find_by_ssn)
end
end

describe 'when the claims_api_use_vet_record_service flipper is on' do
let(:vet_record_web_service) { instance_double(ClaimsApi::VetRecordWebService) }

before do
allow(Flipper).to receive(:enabled?).with(:claims_api_use_vet_record_service).and_return true
allow(ClaimsApi::VetRecordWebService).to receive(:new).with(external_uid: anything,
external_key: anything)
.and_return(vet_record_web_service)
allow(vet_record_web_service).to receive(:update_birls_record).and_return({ return_code: 'BMOD0001' })
end

it 'calls local bgs vet record service instead of bgs-ext' do
poa = create_poa
subject.new.perform(poa.id)

expect(vet_record_web_service).to have_received(:update_birls_record)
end
end

private

def create_poa
Expand Down
Loading

0 comments on commit fc06924

Please sign in to comment.