From 0a9a5e2a85429ce6255444d02b72da8e032e603a Mon Sep 17 00:00:00 2001 From: Matt Christianson <95487885+mchristiansonVA@users.noreply.github.com> Date: Thu, 19 Dec 2024 16:20:36 -0500 Subject: [PATCH 1/2] Initial commit, working implementation --- .../v2/veterans/power_of_attorney/base_controller.rb | 10 +++++++--- .../claims_api/poa_assign_dependent_claimant_job.rb | 4 +++- .../claims_api/app/sidekiq/claims_api/poa_updater.rb | 8 -------- .../claims_api/app/sidekiq/claims_api/service_base.rb | 8 ++++++++ .../app/sidekiq/claims_api/v2/poa_form_builder_job.rb | 2 +- .../app/sidekiq/claims_api/va_notify_accepted_job.rb | 7 ++++++- 6 files changed, 25 insertions(+), 14 deletions(-) diff --git a/modules/claims_api/app/controllers/claims_api/v2/veterans/power_of_attorney/base_controller.rb b/modules/claims_api/app/controllers/claims_api/v2/veterans/power_of_attorney/base_controller.rb index 2b9a942b801..974ec2cff79 100644 --- a/modules/claims_api/app/controllers/claims_api/v2/veterans/power_of_attorney/base_controller.rb +++ b/modules/claims_api/app/controllers/claims_api/v2/veterans/power_of_attorney/base_controller.rb @@ -114,7 +114,7 @@ def set_auth_headers if allow_dependent_claimant? add_dependent_to_auth_headers(headers) else - auth_headers + headers end end @@ -228,11 +228,11 @@ def user_profile end def icn_for_vanotify - params[:veteranId] + dependent_claimant_icn = claimant_icn + dependent_claimant_icn || params[:veteranId] end def fetch_claimant - claimant_icn = form_attributes.dig('claimant', 'claimantId') if claimant_icn.present? mpi_profile = mpi_service.find_profile_by_identifier(identifier: claimant_icn, identifier_type: MPI::Constants::ICN) @@ -241,6 +241,10 @@ def fetch_claimant mpi_profile end + def claimant_icn + @claimant_icn ||= form_attributes.dig('claimant', 'claimantId') + end + def disable_jobs? Settings.claims_api&.poa_v2&.disable_jobs end diff --git a/modules/claims_api/app/sidekiq/claims_api/poa_assign_dependent_claimant_job.rb b/modules/claims_api/app/sidekiq/claims_api/poa_assign_dependent_claimant_job.rb index 2cace86cb5f..e01ab4ba50f 100644 --- a/modules/claims_api/app/sidekiq/claims_api/poa_assign_dependent_claimant_job.rb +++ b/modules/claims_api/app/sidekiq/claims_api/poa_assign_dependent_claimant_job.rb @@ -4,7 +4,7 @@ module ClaimsApi class PoaAssignDependentClaimantJob < ClaimsApi::ServiceBase LOG_TAG = 'poa_assign_dependent_claimant_job' - def perform(poa_id) + def perform(poa_id, rep) poa = ClaimsApi::PowerOfAttorney.find(poa_id) service = dependent_claimant_poa_assignment_service( @@ -29,6 +29,8 @@ def perform(poa_id) poa.id, 'POA assigned for dependent' ) + + ClaimsApi::VANotifyAcceptedJob.perform_async(poa.id, rep) if vanotify?(poa.auth_headers, rep) end private 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 2de49c6885f..24eb6308855 100644 --- a/modules/claims_api/app/sidekiq/claims_api/poa_updater.rb +++ b/modules/claims_api/app/sidekiq/claims_api/poa_updater.rb @@ -37,14 +37,6 @@ def perform(power_of_attorney_id, rep = nil) private - def vanotify?(auth_headers, rep) - if Flipper.enabled?(:lighthouse_claims_api_v2_poa_va_notify) - auth_headers.key?(ClaimsApi::V2::Veterans::PowerOfAttorney::BaseController::VA_NOTIFY_KEY) && rep.present? - else - false - end - end - def bgs_ext_service(poa_form) BGS::Services.new( external_uid: poa_form.external_uid, diff --git a/modules/claims_api/app/sidekiq/claims_api/service_base.rb b/modules/claims_api/app/sidekiq/claims_api/service_base.rb index 326265f8306..167578e94bd 100644 --- a/modules/claims_api/app/sidekiq/claims_api/service_base.rb +++ b/modules/claims_api/app/sidekiq/claims_api/service_base.rb @@ -227,6 +227,14 @@ def extract_poa_code(poa_form_data) end end + def vanotify?(auth_headers, rep) + if Flipper.enabled?(:lighthouse_claims_api_v2_poa_va_notify) + auth_headers.key?(ClaimsApi::V2::Veterans::PowerOfAttorney::BaseController::VA_NOTIFY_KEY) && rep.present? + else + false + end + end + def evss_mapper_service(auto_claim) ClaimsApi::V2::DisabilityCompensationEvssMapper.new(auto_claim) end diff --git a/modules/claims_api/app/sidekiq/claims_api/v2/poa_form_builder_job.rb b/modules/claims_api/app/sidekiq/claims_api/v2/poa_form_builder_job.rb index 6e5eea0c0ef..960d4fbb626 100644 --- a/modules/claims_api/app/sidekiq/claims_api/v2/poa_form_builder_job.rb +++ b/modules/claims_api/app/sidekiq/claims_api/v2/poa_form_builder_job.rb @@ -32,7 +32,7 @@ def perform(power_of_attorney_id, form_number, rep_id, action) end if dependent_filing?(power_of_attorney) - ClaimsApi::PoaAssignDependentClaimantJob.perform_async(power_of_attorney.id) + ClaimsApi::PoaAssignDependentClaimantJob.perform_async(power_of_attorney.id, rep) else ClaimsApi::PoaUpdater.perform_async(power_of_attorney.id, rep) end diff --git a/modules/claims_api/app/sidekiq/claims_api/va_notify_accepted_job.rb b/modules/claims_api/app/sidekiq/claims_api/va_notify_accepted_job.rb index 2710975d28c..464ae730a22 100644 --- a/modules/claims_api/app/sidekiq/claims_api/va_notify_accepted_job.rb +++ b/modules/claims_api/app/sidekiq/claims_api/va_notify_accepted_job.rb @@ -173,7 +173,12 @@ def build_address(line1, line2, line3) end def claimant_first_name(poa) - poa.auth_headers['va_eauth_firstName'] + claimant = poa.form_data['claimant'].present? + if claimant + poa.form_data['claimant']['firstName'] + else + poa.auth_headers['va_eauth_firstName'] + end end def organization_filing?(form_data) From 7251cdd2f8137cebc25b336f97268b96a15df42d Mon Sep 17 00:00:00 2001 From: Matt Christianson <95487885+mchristiansonVA@users.noreply.github.com> Date: Fri, 20 Dec 2024 11:22:16 -0500 Subject: [PATCH 2/2] Add tests for VANotify for dependent assignment, fix typo in context description --- .../poa_assign_dependent_claimant_job_spec.rb | 52 ++++++++++++++++++- .../spec/sidekiq/poa_updater_spec.rb | 2 +- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/modules/claims_api/spec/sidekiq/poa_assign_dependent_claimant_job_spec.rb b/modules/claims_api/spec/sidekiq/poa_assign_dependent_claimant_job_spec.rb index 369967b3b4f..106be9b1ee0 100644 --- a/modules/claims_api/spec/sidekiq/poa_assign_dependent_claimant_job_spec.rb +++ b/modules/claims_api/spec/sidekiq/poa_assign_dependent_claimant_job_spec.rb @@ -68,10 +68,60 @@ ) expect(poa.status).to eq(ClaimsApi::PowerOfAttorney::SUBMITTED) - described_class.new.perform(poa.id) + described_class.new.perform(poa.id, 'Rep Data') poa.reload expect(poa.status).to eq(ClaimsApi::PowerOfAttorney::UPDATED) end end + + context 'Sending the 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) do + FactoryBot.create(:power_of_attorney, + auth_headers: auth_headers, + form_data: claimant_form_data, + status: ClaimsApi::PowerOfAttorney::SUBMITTED) + end + let(:header_key) { ClaimsApi::V2::Veterans::PowerOfAttorney::BaseController::VA_NOTIFY_KEY } + + context 'when the header key and rep are present' do + it 'sends the vanotify job' do + poa.auth_headers.merge!({ + header_key => 'this_value' + }) + poa.save! + allow_any_instance_of(ClaimsApi::DependentClaimantPoaAssignmentService).to receive(:assign_poa_to_dependent!) + .and_return(nil) + expect(ClaimsApi::VANotifyAcceptedJob).to receive(:perform_async) + + described_class.new.perform(poa.id, 'Rep Data') + end + end + + context 'when the flipper is off' 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 + poa.auth_headers.merge!({ + header_key => 'this_value' + }) + poa.save! + allow_any_instance_of(ClaimsApi::DependentClaimantPoaAssignmentService).to receive(:assign_poa_to_dependent!) + .and_return(nil) + expect(ClaimsApi::VANotifyAcceptedJob).not_to receive(:perform_async) + + described_class.new.perform(poa.id, 'Rep Data') + end + end + end + + def create_mock_lighthouse_service + allow_any_instance_of(ClaimsApi::StandardDataWebService).to receive(:find_poas) + .and_return([{ legacy_poa_cd: '002', nm: "MAINE VETERANS' SERVICES", org_type_nm: 'POA State Organization', + ptcpnt_id: '46004' }]) + end end diff --git a/modules/claims_api/spec/sidekiq/poa_updater_spec.rb b/modules/claims_api/spec/sidekiq/poa_updater_spec.rb index 877c8042720..aa995d369ea 100644 --- a/modules/claims_api/spec/sidekiq/poa_updater_spec.rb +++ b/modules/claims_api/spec/sidekiq/poa_updater_spec.rb @@ -105,7 +105,7 @@ end end - context 'when the flipper is on' do + context 'when the flipper is off' 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)