Skip to content

Commit

Permalink
Some cleanup, consolidated unit tests, moved confirmation email logic…
Browse files Browse the repository at this point in the history
… into separate function
  • Loading branch information
mchae-nava committed Nov 18, 2024
1 parent 41879fe commit f42bd48
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 27 deletions.
20 changes: 11 additions & 9 deletions app/sidekiq/lighthouse/poll_form526_pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,7 @@ def perform(submission_id)
form526_pdf = get_form526_pdf(submission)
if form526_pdf.present?
Rails.logger.info('Poll for form 526 PDF: PDF found')
if Flipper.enabled?(:disability_526_call_received_email_from_polling)
user_uuid = submission.user_uuid
user = User.find(user_uuid)
first_name = user&.first_name&.upcase.presence || auth_headers&.dig('va_eauth_firstName')&.upcase
Rails.logger.info("Form526ConfirmationEmailJob called for user #{user_uuid},
submission: #{submission_id} from poll_form526_pdf")
params = submission.personalization_parameters(first_name)
Form526ConfirmationEmailJob.perform_async(params)
end
send_confirmation_email(submission) if Flipper.enabled?(:disability_526_call_received_email_from_polling)
return
else
# Check the submission.created_at date, if it's more than 2 days old
Expand Down Expand Up @@ -146,6 +138,16 @@ def get_form526_pdf(submission)
d['documentTypeLabel'] == 'VA 21-526 Veterans Application for Compensation or Pension'
end
end

def send_confirmation_email(submission)
user_uuid = submission.user_uuid
user = User.find(user_uuid)
first_name = user&.first_name&.upcase.presence || auth_headers&.dig('va_eauth_firstName')&.upcase
Rails.logger.info("Form526ConfirmationEmailJob called for user #{user_uuid},
submission: #{submission_id} from poll_form526_pdf")
params = submission.personalization_parameters(first_name)
Form526ConfirmationEmailJob.perform_async(params)
end
end
# rubocop:enable Metrics/MethodLength
end
25 changes: 7 additions & 18 deletions spec/sidekiq/lighthouse/poll_form526_pdf_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
expect(job_status.status).to eq 'pdf_not_found'
end

it 'calls polling only for startedFormVersion present and does not retry because the form is there' do
it 'calls polling only for startedFormVersion present, does not retry because the form is there,
and triggers confirmation email' do
allow_any_instance_of(BenefitsClaims::Service).to receive(:get_claim)
.and_return(
{ 'data' =>
Expand All @@ -37,13 +38,17 @@
expect(Lighthouse::PollForm526Pdf).to receive(:perform_async).with(form526_submission.id)

form526_submission.send(:poll_form526_pdf)

expect do
Lighthouse::PollForm526Pdf.drain
job_status = form526_submission.form526_job_statuses.find_by(job_class: 'PollForm526Pdf')
job_status.reload
expect(job_status.status).to eq 'success'
end.not_to raise_error

form526_submission.send(:poll_form526_pdf)
expect do
Lighthouse::PollForm526Pdf.drain
end.to change(Form526ConfirmationEmailJob.jobs, :size).by(1)
end

it 'calls polling only for startedFormVersion present and retries' do
Expand Down Expand Up @@ -85,21 +90,5 @@
expect(form526_job_status.status).to eq 'pdf_not_found'
end
end

context 'with disability_526_call_received_email_from_polling enabled' do
let(:form526_submission) { create(:form526_submission, submitted_claim_id: 1) }

it 'identifies and formats first_name correctly' do
expect do
subject.first_name.to eq :disabilities_compensation_user.first_name&.upcase.presence
end
end

it 'triggers confirmation email' do
expect do
subject.perform_async(form526_submission.id)
end.to change(Form526ConfirmationEmailJob.jobs, :size).by(1)
end
end
end
end

0 comments on commit f42bd48

Please sign in to comment.