Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api 28113 replace bgs ext poa updater #19325

Merged
merged 26 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b12ef93
Adds flipper feature.
stiehlrod Nov 7, 2024
f0a1f1a
Moves the find_by_ssn call to PersonWebService from LocalBgs.
stiehlrod Nov 7, 2024
a90687b
Adds VetRecordService to LocalBgs.
stiehlrod Nov 7, 2024
f0ee6f4
Adds ability to switch between bgs-ext & local_bgs for vet_record & p…
stiehlrod Nov 7, 2024
ea04590
Getting successful responses, but getting 'BGS Error: update_birls_re…
stiehlrod Nov 7, 2024
2f24fc0
Reverts instance variable. Adds definition. Adds PAYEE_NUMBER value.
stiehlrod Nov 7, 2024
2e791c6
Merge branch 'master' into API-28113-replace-bgs-ext-poa-updater
stiehlrod Nov 8, 2024
293079f
Refactors poa_updater. Replaces find_by_ssn in local_bgs due to many …
stiehlrod Nov 12, 2024
ce86efa
WIP: switching branches.
stiehlrod Nov 14, 2024
75ca22c
Merge branch 'master' into API-28113-replace-bgs-ext-poa-updater
stiehlrod Nov 14, 2024
c34f23c
Cleans up poa_updater. Adds definitions. Updates vcr cassette.
stiehlrod Nov 15, 2024
8fd6d88
Merge branch 'master' into API-28113-replace-bgs-ext-poa-updater
stiehlrod Nov 15, 2024
04755e0
Removes find_birls_record
stiehlrod Nov 15, 2024
8f94b9f
Corrects vet record service. Updates tests with flipper feature, and …
stiehlrod Nov 18, 2024
fa2c15f
Merge branch 'master' into API-28113-replace-bgs-ext-poa-updater
stiehlrod Nov 19, 2024
0c55339
Updates person web service
stiehlrod Nov 19, 2024
60cbe54
Merge branch 'master' into API-28113-replace-bgs-ext-poa-updater
stiehlrod Nov 19, 2024
53a1388
Merge branch 'master' into API-28113-replace-bgs-ext-poa-updater
stiehlrod Nov 21, 2024
d94268f
Removes method definitions.
stiehlrod Nov 21, 2024
ae13148
Merge branch 'API-28113-replace-bgs-ext-poa-updater' of https://githu…
stiehlrod Nov 21, 2024
107e6c3
Renames flippers, separates features into two flippers. Adds two test…
stiehlrod Nov 21, 2024
a6a97f2
Merge branch 'master' into API-28113-replace-bgs-ext-poa-updater
stiehlrod Nov 22, 2024
384dfa7
Updates test and shared vcr cassette.
stiehlrod Nov 22, 2024
8736614
Adds flipper test.
stiehlrod Nov 22, 2024
23aabb1
Resolves merge conflict
stiehlrod Nov 26, 2024
62ecd17
Adds tests for flipper.
stiehlrod Nov 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config/features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,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
stiehlrod marked this conversation as resolved.
Show resolved Hide resolved
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
Loading