Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pmclaren19 committed Feb 15, 2025
1 parent 3b58ad1 commit 115b78a
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ def notify_client

def send_failed_evidence_submissions
failed_uploads.each do |upload|
personalisation = create_personalisation_from_upload(upload)

personalisation = BenefitsDocuments::Utilities::Helpers.create_personalisation_from_upload(upload)
# NOTE: The file_name in the personalisation that is passed in is obscured
response = notify_client.send_email(
recipient_identifier: { id_value: upload.user_account.icn, id_type: 'ICN' },
Expand All @@ -55,16 +54,6 @@ def send_failed_evidence_submissions
nil
end

# This will be used to send an upload failure email
# We created a new personalisation with the obfuscated_file_name so the filename is hidden in the email
def create_personalisation_from_upload(upload)
personalisation = JSON.parse(upload.template_metadata)['personalisation']
personalisation['file_name'] = personalisation['obfuscated_filename']
personalisation.delete('obfuscated_filename')

personalisation
end

def record_email_send_success(upload, response)
# Update evidence_submissions table record with the va_notify_id and va_notify_date
upload.update(va_notify_id: response.id, va_notify_date: DateTime.now)
Expand Down
11 changes: 11 additions & 0 deletions lib/lighthouse/benefits_documents/utilities/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ def self.format_date_for_mailers(date)
# We display dates in mailers in the format "May 1, 2024 3:01 p.m. EDT"
timestamp.strftime('%B %-d, %Y %-l:%M %P %Z').sub(/([ap])m/, '\1.m.')
end

# Used to take the current personalisation from an evidence_submission records template_metadata
# and return a new personalisation with a file_name field that is obscured and doesnt have the field
# obfuscated_file_name. This will be used in the failed notification email template.
def self.create_personalisation_from_upload(upload)
personalisation = JSON.parse(upload.template_metadata)['personalisation']
personalisation['file_name'] = personalisation['obfuscated_file_name']
personalisation.delete('obfuscated_file_name')

personalisation
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

require 'rails_helper'
require 'va_notify/service'
require 'lighthouse/benefits_documents/utilities/helpers'


Check failure on line 7 in spec/sidekiq/lighthouse/evidence_submissions/failure_notification_email_job_spec.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Layout/EmptyLines: Extra blank line detected.
RSpec.describe Lighthouse::EvidenceSubmissions::FailureNotificationEmailJob, type: :job do
subject { described_class }
Expand Down Expand Up @@ -69,7 +71,18 @@
let(:tags) { ['service:claim-status', "function: #{message}"] }
let(:message) { "#{evidence_submission_failed.job_class} va notify failure email queued" }
let!(:evidence_submission_failed) { create(:bd_evss_evidence_submission_failed_type1_error) }

let(:personalisation) {BenefitsDocuments::Utilities::Helpers.create_personalisation_from_upload(evidence_submission_failed)}

Check failure on line 74 in spec/sidekiq/lighthouse/evidence_submissions/failure_notification_email_job_spec.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Layout/SpaceInsideBlockBraces: Space missing inside {.

Check failure on line 74 in spec/sidekiq/lighthouse/evidence_submissions/failure_notification_email_job_spec.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Layout/LineLength: Line is too long. [130/120]

Check failure on line 74 in spec/sidekiq/lighthouse/evidence_submissions/failure_notification_email_job_spec.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Layout/SpaceInsideBlockBraces: Space missing inside }.

let(:send_email_params) do

Check failure on line 76 in spec/sidekiq/lighthouse/evidence_submissions/failure_notification_email_job_spec.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Layout/TrailingWhitespace: Trailing whitespace detected.
{
recipient_identifier: {
id_value: evidence_submission_failed.user_account.icn,
id_type: 'ICN'
},
template_id: Settings.vanotify.services.benefits_management_tools.template_id.evidence_submission_failure_email,

Check failure on line 82 in spec/sidekiq/lighthouse/evidence_submissions/failure_notification_email_job_spec.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Layout/LineLength: Line is too long. [122/120]
personalisation:

Check failure on line 83 in spec/sidekiq/lighthouse/evidence_submissions/failure_notification_email_job_spec.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Layout/TrailingWhitespace: Trailing whitespace detected.
}
end

Check failure on line 85 in spec/sidekiq/lighthouse/evidence_submissions/failure_notification_email_job_spec.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

RSpec/EmptyLineAfterFinalLet: Add an empty line after the last `let`.
before do
allow(VaNotify::Service).to receive(:new).and_return(vanotify_service)
allow(EvidenceSubmission).to receive(:va_notify_email_not_queued).and_return([evidence_submission_failed])
Expand All @@ -80,7 +93,7 @@
it 'successfully enqueues a failure notification mailer to send to the veteran' do
expect(EvidenceSubmission.count).to eq(1)
expect(EvidenceSubmission.va_notify_email_not_queued.length).to eq(1)
expect(vanotify_service).to receive(:send_email)
expect(vanotify_service).to receive(:send_email).with(send_email_params)
expect(evidence_submission_failed).to receive(:update).and_call_original
expect(Rails.logger).to receive(:info).with(message)
expect(StatsD).to receive(:increment).with('silent_failure_avoided_no_confirmation', tags: tags)
Expand Down Expand Up @@ -119,7 +132,19 @@
let(:tags) { ['service:claim-status', "function: #{message}"] }
let(:message) { "#{evidence_submission_failed.job_class} va notify failure email queued" }
let!(:evidence_submission_failed) { create(:bd_lh_evidence_submission_failed_type1_error) }

let(:personalisation) {BenefitsDocuments::Utilities::Helpers.create_personalisation_from_upload(evidence_submission_failed)}

Check failure on line 135 in spec/sidekiq/lighthouse/evidence_submissions/failure_notification_email_job_spec.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Layout/SpaceInsideBlockBraces: Space missing inside {.

Check failure on line 135 in spec/sidekiq/lighthouse/evidence_submissions/failure_notification_email_job_spec.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Layout/LineLength: Line is too long. [130/120]

let(:send_email_params) do
{
recipient_identifier: {
id_value: evidence_submission_failed.user_account.icn,
id_type: 'ICN'
},
template_id: Settings.vanotify.services.benefits_management_tools.template_id.evidence_submission_failure_email,
personalisation:
}
end

before do
allow(VaNotify::Service).to receive(:new).and_return(vanotify_service)
allow(EvidenceSubmission).to receive(:va_notify_email_not_queued).and_return([evidence_submission_failed])
Expand All @@ -130,7 +155,7 @@
it 'successfully enqueues a failure notification mailer to send to the veteran' do
expect(EvidenceSubmission.count).to eq(1)
expect(EvidenceSubmission.va_notify_email_not_queued.length).to eq(1)
expect(vanotify_service).to receive(:send_email)
expect(vanotify_service).to receive(:send_email).with(send_email_params)
expect(evidence_submission_failed).to receive(:update).and_call_original
expect(Rails.logger).to receive(:info).with(message)
expect(StatsD).to receive(:increment).with('silent_failure_avoided_no_confirmation', tags: tags)
Expand Down Expand Up @@ -169,7 +194,18 @@
let(:tags) { ['service:claim-status', "function: #{message}"] }
let(:message) { "#{evidence_submission_failed.job_class} va notify failure email queued" }
let!(:evidence_submission_failed) { create(:bd_lh_evidence_submission_failed_type2_error) }

let(:personalisation) {BenefitsDocuments::Utilities::Helpers.create_personalisation_from_upload(evidence_submission_failed)}

let(:send_email_params) do
{
recipient_identifier: {
id_value: evidence_submission_failed.user_account.icn,
id_type: 'ICN'
},
template_id: Settings.vanotify.services.benefits_management_tools.template_id.evidence_submission_failure_email,
personalisation:
}
end
before do
allow(VaNotify::Service).to receive(:new).and_return(vanotify_service)
allow(EvidenceSubmission).to receive(:va_notify_email_not_queued).and_return([evidence_submission_failed])
Expand All @@ -180,7 +216,7 @@
it 'successfully enqueues a failure notification mailer to send to the veteran' do
expect(EvidenceSubmission.count).to eq(1)
expect(EvidenceSubmission.va_notify_email_not_queued.length).to eq(1)
expect(vanotify_service).to receive(:send_email)
expect(vanotify_service).to receive(:send_email).with(send_email_params)
expect(evidence_submission_failed).to receive(:update).and_call_original
expect(Rails.logger).to receive(:info).with(message)
expect(StatsD).to receive(:increment).with('silent_failure_avoided_no_confirmation', tags: tags)
Expand Down

0 comments on commit 115b78a

Please sign in to comment.