From eb6f23ecad17f92f52411e0e64d99bd93490d1d1 Mon Sep 17 00:00:00 2001 From: rockwellwindsor-va Date: Wed, 6 Mar 2024 13:10:16 -0600 Subject: [PATCH] API-34542 2122a update poa fix * 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 --- .../app/sidekiq/claims_api/poa_updater.rb | 38 +++++++++--- .../spec/sidekiq/poa_updater_spec.rb | 61 +++++++++++++++++++ 2 files changed, 91 insertions(+), 8 deletions(-) diff --git a/modules/claims_api/app/sidekiq/claims_api/poa_updater.rb b/modules/claims_api/app/sidekiq/claims_api/poa_updater.rb index 5fc1f8294da..91038ace6d7 100644 --- a/modules/claims_api/app/sidekiq/claims_api/poa_updater.rb +++ b/modules/claims_api/app/sidekiq/claims_api/poa_updater.rb @@ -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? @@ -29,9 +33,11 @@ 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 @@ -39,6 +45,22 @@ def perform(power_of_attorney_id) # rubocop:disable Metrics/MethodLength 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 diff --git a/modules/claims_api/spec/sidekiq/poa_updater_spec.rb b/modules/claims_api/spec/sidekiq/poa_updater_spec.rb index a76cc88f29b..1820be7d5d9 100644 --- a/modules/claims_api/spec/sidekiq/poa_updater_spec.rb +++ b/modules/claims_api/spec/sidekiq/poa_updater_spec.rb @@ -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