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 43135 poa updated notification dependent #19972

Merged
merged 20 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
0a9a5e2
Initial commit, working implementation
mchristiansonVA Dec 19, 2024
671a71b
Merge remote-tracking branch 'origin/master' into API-43135-POA-updat…
mchristiansonVA Dec 19, 2024
57a5031
Merge remote-tracking branch 'origin/master' into API-43135-POA-updat…
mchristiansonVA Dec 20, 2024
7251cdd
Add tests for VANotify for dependent assignment, fix typo in context …
mchristiansonVA Dec 20, 2024
f32c804
Merge remote-tracking branch 'origin/master' into API-43135-POA-updat…
mchristiansonVA Dec 20, 2024
892cff7
Merge remote-tracking branch 'origin/master' into API-43135-POA-updat…
mchristiansonVA Dec 27, 2024
fd65741
Pass rep_id instead of rep object for async processing
mchristiansonVA Dec 27, 2024
5b799bc
Merge remote-tracking branch 'origin/master' into API-43135-POA-updat…
mchristiansonVA Dec 30, 2024
aa23847
Misc cleanup for clarity, logic reduction
mchristiansonVA Dec 31, 2024
9c97af7
Updates to use rep_id instead of rep for poa_updater
mchristiansonVA Dec 31, 2024
1e486de
Fix test for recent updates
mchristiansonVA Dec 31, 2024
7aef3ba
Fix header handling
mchristiansonVA Dec 31, 2024
37f6a55
Merge remote-tracking branch 'origin/master' into API-43135-POA-updat…
mchristiansonVA Dec 31, 2024
9ef0e0b
Merge branch 'master' into API-43135-POA-updated-notification-dependent
mchristiansonVA Jan 2, 2025
a6ea655
Merge branch 'master' into API-43135-POA-updated-notification-dependent
mchristiansonVA Jan 6, 2025
a600d9b
Merge branch 'master' into API-43135-POA-updated-notification-dependent
mchristiansonVA Jan 6, 2025
dded5d5
Merge branch 'master' into API-43135-POA-updated-notification-dependent
mchristiansonVA Jan 6, 2025
6ef938b
Merge branch 'master' into API-43135-POA-updated-notification-dependent
mchristiansonVA Jan 6, 2025
4b19c16
Merge branch 'master' into API-43135-POA-updated-notification-dependent
mchristiansonVA Jan 7, 2025
f49888c
Merge branch 'master' into API-43135-POA-updated-notification-dependent
mchristiansonVA Jan 7, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,9 @@ def submit_power_of_attorney(poa_code, form_number)
def set_auth_headers
headers = auth_headers.merge!({ VA_NOTIFY_KEY => icn_for_vanotify })

if allow_dependent_claimant?
add_dependent_to_auth_headers(headers)
else
auth_headers
end
add_dependent_to_auth_headers(headers) if allow_dependent_claimant?

headers
end

def add_dependent_to_auth_headers(headers)
Expand Down Expand Up @@ -228,11 +226,11 @@ def user_profile
end

def icn_for_vanotify
params[:veteranId]
dependent_claimant_icn = claimant_icn
dependent_claimant_icn.presence || 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)
Expand All @@ -241,6 +239,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_id)
poa = ClaimsApi::PowerOfAttorney.find(poa_id)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could potentially extract some commonly used attributes into local variables here:

poa_id = poa.id
form_data = poa.form_data
auth_headers = poa.auth_headers

service = dependent_claimant_poa_assignment_service(
Expand All @@ -29,6 +29,8 @@ def perform(poa_id)
poa.id,
'POA assigned for dependent'
)

ClaimsApi::VANotifyAcceptedJob.perform_async(poa.id, rep_id) if vanotify?(poa.auth_headers, rep_id)
end

private
Expand Down
12 changes: 2 additions & 10 deletions modules/claims_api/app/sidekiq/claims_api/poa_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

module ClaimsApi
class PoaUpdater < ClaimsApi::ServiceBase
def perform(power_of_attorney_id, rep = nil)
def perform(power_of_attorney_id, rep_id = nil)
poa_form = ClaimsApi::PowerOfAttorney.find(power_of_attorney_id)

ssn = poa_form.auth_headers['va_eauth_pnid']
Expand All @@ -23,7 +23,7 @@ def perform(power_of_attorney_id, rep = nil)

ClaimsApi::Logger.log('poa', poa_id: poa_form.id, detail: 'BIRLS Success')

ClaimsApi::VANotifyAcceptedJob.perform_async(poa_form.id, rep) if vanotify?(poa_form.auth_headers, rep)
ClaimsApi::VANotifyAcceptedJob.perform_async(poa_form.id, rep_id) if vanotify?(poa_form.auth_headers, rep_id)

ClaimsApi::PoaVBMSUpdater.perform_async(poa_form.id)
else
Expand All @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions modules/claims_api/app/sidekiq/claims_api/service_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ def extract_poa_code(poa_form_data)
end
end

def vanotify?(auth_headers, rep_id)
rep = ::Veteran::Service::Representative.where(representative_id: rep_id).order(created_at: :desc).first
Flipper.enabled?(:lighthouse_claims_api_v2_poa_va_notify) &&
auth_headers.key?(ClaimsApi::V2::Veterans::PowerOfAttorney::BaseController::VA_NOTIFY_KEY) && rep.present?
end

def evss_mapper_service(auto_claim)
ClaimsApi::V2::DisabilityCompensationEvssMapper.new(auto_claim)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ 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_id)
else
ClaimsApi::PoaUpdater.perform_async(power_of_attorney.id, rep)
ClaimsApi::PoaUpdater.perform_async(power_of_attorney.id, rep_id)
end
rescue VBMS::Unknown
rescue_vbms_error(power_of_attorney)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module ClaimsApi
class VANotifyAcceptedJob < ClaimsApi::ServiceBase
LOG_TAG = 'va_notify_accepted_job'

def perform(poa_id, rep)
def perform(poa_id, rep_id)
return if skip_notification_email?

poa = ClaimsApi::PowerOfAttorney.find(poa_id)
Expand All @@ -14,10 +14,12 @@ def perform(poa_id, rep)
detail: "Could not find Power of Attorney with id: #{poa_id}"
)
end

if organization_filing?(poa.form_data)
org = find_org(poa, '2122')
res = send_organization_notification(poa, org)
else
rep = ::Veteran::Service::Representative.where(representative_id: rep_id).order(created_at: :desc).first
poa_code_from_form('2122a', poa)
res = send_representative_notification(poa, rep)
end
Expand Down Expand Up @@ -173,7 +175,7 @@ def build_address(line1, line2, line3)
end

def claimant_first_name(poa)
poa.auth_headers['va_eauth_firstName']
poa.form_data.dig('claimant', 'firstName').presence || poa.auth_headers['va_eauth_firstName']
end

def organization_filing?(form_data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,61 @@
)

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)
allow_any_instance_of(ClaimsApi::ServiceBase).to receive(:vanotify?).and_return true
expect(ClaimsApi::VANotifyAcceptedJob).to receive(:perform_async)

described_class.new.perform(poa.id, '12345678')
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, '12345678')
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
3 changes: 2 additions & 1 deletion modules/claims_api/spec/sidekiq/poa_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,14 @@
})
poa.save!

allow_any_instance_of(ClaimsApi::ServiceBase).to receive(:vanotify?).and_return true
expect(ClaimsApi::VANotifyAcceptedJob).to receive(:perform_async)

subject.new.perform(poa.id, 'Rep Data')
end
end

context 'when the flipper is on' do
context 'when the flipper is off' do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

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)
Expand Down
Loading