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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -114,7 +114,7 @@ def set_auth_headers
if allow_dependent_claimant?
add_dependent_to_auth_headers(headers)
else
auth_headers
headers
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I missed this subtlety earlier, but we shouldnʼt need the intermediate headers variable since Ruby modifies hashes in-place. We could simplify these two methods as:

def set_auth_headers
  auth_headers.merge!(VA_NOTIFY_KEY => icn_for_vanotify)

  add_dependent_to_auth_headers if allow_dependent_claimant?

  auth_headers
end

def add_dependent_to_auth_headers
  claimant = user_profile.profile

  auth_headers.merge!({
                        dependent: {
                          participant_id: claimant.participant_id,
                          ssn: claimant.ssn,
                          first_name: claimant.given_names[0],
                          last_name: claimant.family_name
                        }
                      })
end

end
end

Expand Down Expand Up @@ -228,11 +228,11 @@ def user_profile
end

def icn_for_vanotify
params[:veteranId]
dependent_claimant_icn = claimant_icn
dependent_claimant_icn || params[:veteranId]
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: we could make our intent clearer with presence.

Suggested change
dependent_claimant_icn || params[:veteranId]
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 +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
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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of passing the rep object, should we plumb the rep ID and query the database again in VANotifyAcceptedJob? Have been burned before passing objects between sidekiq jobs.

poa = ClaimsApi::PowerOfAttorney.find(poa_id)

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) if vanotify?(poa.auth_headers, rep)
end

private
Expand Down
8 changes: 0 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 @@ -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
8 changes: 8 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,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
Comment on lines +231 to +235
Copy link
Contributor

Choose a reason for hiding this comment

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

nit

Suggested change
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
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,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines +176 to +181
Copy link
Contributor

Choose a reason for hiding this comment

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

nit

Suggested change
claimant = poa.form_data['claimant'].present?
if claimant
poa.form_data['claimant']['firstName']
else
poa.auth_headers['va_eauth_firstName']
end
poa.form_data.dig('claimant', 'firstName').presence || poa.auth_headers['va_eauth_firstName']

end

def organization_filing?(form_data)
Expand Down
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion modules/claims_api/spec/sidekiq/poa_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
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