Skip to content

Commit

Permalink
add process updates to poa_updater
Browse files Browse the repository at this point in the history
  • Loading branch information
tycol7 committed Jan 17, 2025
1 parent 7ece1fb commit 1b529e7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
10 changes: 8 additions & 2 deletions modules/claims_api/app/sidekiq/claims_api/poa_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

module ClaimsApi
class PoaUpdater < ClaimsApi::ServiceBase
def perform(power_of_attorney_id, rep_id = nil)
def perform(power_of_attorney_id, rep_id = nil) # rubocop:disable Metrics/MethodLength
poa_form = ClaimsApi::PowerOfAttorney.find(power_of_attorney_id)

process = ClaimsApi::Process.find_or_create_by(processable: poa_form,
step_type: 'POA_UPDATE')
process.update!(step_status: 'IN_PROGRESS')
ssn = poa_form.auth_headers['va_eauth_pnid']

file_number = find_by_ssn(ssn, poa_form)
Expand All @@ -26,10 +28,14 @@ def perform(power_of_attorney_id, rep_id = nil)
ClaimsApi::VANotifyAcceptedJob.perform_async(poa_form.id, rep_id) if vanotify?(poa_form.auth_headers, rep_id)

ClaimsApi::PoaVBMSUpdater.perform_async(poa_form.id)

process.update!(step_status: 'SUCCESS')
else
poa_form.status = ClaimsApi::PowerOfAttorney::ERRORED
poa_form.vbms_error_message = "BGS Error: update_birls_record failed with code #{response[:return_code]}"
ClaimsApi::Logger.log('poa', poa_id: poa_form.id, detail: 'BIRLS Failed', error: response[:return_code])

process.update!(step_status: 'FAILED')
end

poa_form.save
Expand Down
32 changes: 24 additions & 8 deletions modules/claims_api/spec/sidekiq/poa_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@

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
let(:poa) { create_poa }

before 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)

poa = create_poa
poa.form_data = {
representative: {
poaCode: '072',
Expand All @@ -44,11 +43,20 @@
consentLimits: []
}
poa.save!
end

it "updates the form's status and creates 'ClaimsApi::PoaVBMSUpdater' job" do
expect(ClaimsApi::PoaVBMSUpdater).to receive(:perform_async)
subject.new.perform(poa.id)
poa.reload
expect(poa.status).to eq('updated')
end

it 'updates the process status to SUCCESS' do
subject.new.perform(poa.id)
process = ClaimsApi::Process.find_by(processable: poa, step_type: 'POA_UPDATE')
expect(process.step_status).to eq('SUCCESS')
end
end

context 'and record consent is granted' do
Expand All @@ -68,19 +76,27 @@
end

context "when call to BGS 'update_birls_record' fails" do
it "updates the form's status and does not create a 'ClaimsApi::PoaVBMSUpdater' job" do
let(:poa) { create_poa }

before do
create_mock_lighthouse_service
allow_any_instance_of(BGS::VetRecordWebService).to receive(:update_birls_record).and_return(
return_code: 'some error code'
)
expect(ClaimsApi::PoaVBMSUpdater).not_to receive(:perform_async)

poa = create_poa
end

it "updates the form's status and does not create a 'ClaimsApi::PoaVBMSUpdater' job" do
expect(ClaimsApi::PoaVBMSUpdater).not_to receive(:perform_async)
subject.new.perform(poa.id)
poa.reload
expect(poa.status).to eq('errored')
end

it 'updates the process status to FAILED' do
subject.new.perform(poa.id)
process = ClaimsApi::Process.find_by(processable: poa, step_type: 'POA_UPDATE')
expect(process.step_status).to eq('FAILED')
end
end

context 'deciding to send a VA Notify email' do
Expand Down

0 comments on commit 1b529e7

Please sign in to comment.