Skip to content

Commit

Permalink
API-34542 2122a update poa fix
Browse files Browse the repository at this point in the history
* 2122a V2 form removed the organzation object so we need to get the poaCode from the representative object.
* Adds some tests to track this update
* Refactors diekiq job to check for both
* Adds a check for the poaCode to make sure this cannot silently fail in the backround in the event of any other changes
 Changes to be committed:
	modified:   modules/claims_api/app/sidekiq/claims_api/poa_updater.rb
	modified:   modules/claims_api/spec/sidekiq/poa_updater_spec.rb
  • Loading branch information
rockwellwindsor-va committed Mar 6, 2024
1 parent 66c2c61 commit eb6f23e
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 8 deletions.
38 changes: 30 additions & 8 deletions modules/claims_api/app/sidekiq/claims_api/poa_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ def perform(power_of_attorney_id) # rubocop:disable Metrics/MethodLength
ssn = poa_form.auth_headers['va_eauth_pnid']
file_number = service.people.find_by_ssn(ssn)[:file_nbr] # rubocop:disable Rails/DynamicFindBy

response = service.vet_record.update_birls_record(
file_number:,
ssn:,
poa_code: poa_form.form_data['serviceOrganization']['poaCode']
)
poa_code = extract_poa_code(poa_form.form_data)

unless poa_code.nil?
response = service.vet_record.update_birls_record(
file_number:,
ssn:,
poa_code:
)
end

if response[:return_code] == 'BMOD0001'
if response && response[:return_code] == 'BMOD0001'
poa_form.status = ClaimsApi::PowerOfAttorney::UPDATED
# Clear out the error message if there were previous failures
poa_form.vbms_error_message = nil if poa_form.vbms_error_message.present?
Expand All @@ -29,16 +33,34 @@ def perform(power_of_attorney_id) # rubocop:disable Metrics/MethodLength

ClaimsApi::PoaVBMSUpdater.perform_async(poa_form.id) if enable_vbms_access?(poa_form:)
else
error_response = set_error_message(response, power_of_attorney_id)

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])
poa_form.vbms_error_message = error_response
ClaimsApi::Logger.log('poa', poa_id: poa_form.id, detail: 'BIRLS Failed', error: error_response)
end

poa_form.save
end

private

def extract_poa_code(poa_form_data)
if poa_form_data.key?('serviceOrganization')
poa_form_data['serviceOrganization']['poaCode']
elsif poa_form_data.key?('representative') # V2 2122a
poa_form_data['representative']['poaCode']
end
end

def set_error_message(response, power_of_attorney_id)
if response&.[](:return_code)
"BGS Error: update_birls_record failed with code #{response[:return_code]}"
else
"No POA code found in form #{power_of_attorney_id}"
end
end

def enable_vbms_access?(poa_form:)
poa_form.form_data['recordConsent'] && poa_form.form_data['consentLimits'].blank?
end
Expand Down
61 changes: 61 additions & 0 deletions modules/claims_api/spec/sidekiq/poa_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,67 @@
end

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
create_mock_lighthouse_service
expect(ClaimsApi::PoaVBMSUpdater).to receive(:perform_async)

poa = create_poa
poa.form_data = {
representative: {
poaCode: '072',
firstName: 'my',
lastName: 'name',
type: 'ATTORNEY',
address: {
numberAndStreet: '123',
city: 'city',
country: 'US',
zipFirstFive: '12345'
}
},
recordConsent: true,
consentLimits: []
}
poa.save!

subject.new.perform(poa.id)
poa.reload
expect(poa.status).to eq('updated')
end
end

context 'and the poaCode is not retrieved successfully from the V2 2122a form data' do
it "updates the form's status and does not create a 'ClaimsApi::PoaVBMSUpdater' job" do
create_mock_lighthouse_service
expect(ClaimsApi::PoaVBMSUpdater).not_to receive(:perform_async)

poa = create_poa
poa.form_data = {
claimant: {
poaCode: '072',
firstName: 'my',
lastName: 'name',
type: 'ATTORNEY',
address: {
numberAndStreet: '123',
city: 'city',
country: 'US',
zipFirstFive: '12345'
}
},
recordConsent: true,
consentLimits: []
}
poa.save!

subject.new.perform(poa.id)
poa.reload
expect(poa.status).to eq('errored')
expect(poa.vbms_error_message).to eq("No POA code found in form #{poa.id}")
end
end

context 'and record consent is granted' do
it "updates the form's status and creates 'ClaimsApi::PoaVBMSUpdater' job" do
create_mock_lighthouse_service
Expand Down

0 comments on commit eb6f23e

Please sign in to comment.