Skip to content

Commit

Permalink
Updated ApplicationMailer so that it explicitly imports helpers (Rail…
Browse files Browse the repository at this point in the history
…s views don't have a 'helper' method). Added en localization entries for email and PDF generation. Updated tests pertaining to PDFs and mailing (#66)
  • Loading branch information
GeorgeCodes19 committed Jun 20, 2024
1 parent 7bff2a0 commit 99b56bb
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 8 deletions.
10 changes: 10 additions & 0 deletions app/app/helpers/view_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,14 @@ def format_date(timestamp_string)
timestamp_string
end
end

def format_view_datetime(timestamp_string)
begin
formatted_time = Time.parse(timestamp_string).strftime("%B %d, %Y")
raw_timestamp = Time.parse(timestamp_string).strftime("%I:%M %p %Z")
"#{formatted_time} - #{raw_timestamp}"
rescue => e
"Invalid timestamp"
end
end
end
6 changes: 4 additions & 2 deletions app/app/mailers/applicant_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class ApplicantMailer < ApplicationMailer
before_action :set_params
helper :view
before_action :set_params

def invitation_email
mail(
Expand All @@ -10,7 +10,9 @@ def invitation_email
end

def caseworker_summary_email
attachments["income_verification.pdf"] = generate_pdf
timestamp = Time.now.strftime("%Y%m%d%H%M%S")
filename = "#{@cbv_flow.case_number}_#{timestamp}_income_verification.pdf"
attachments[filename] = generate_pdf
mail(
to: @email_address,
subject: I18n.t("applicant_mailer.caseworker_summary_email.subject", case_number: @cbv_flow.case_number),
Expand Down
5 changes: 5 additions & 0 deletions app/app/views/cbv_flows/summary.pdf.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<p>
<%= t('cbv_flows.summary.case_number', case_number: @cbv_flow.case_number) %>
</p>
<p>
<%= t('cbv_flows.summary.document_timestamp', timestamp: format_view_datetime(Time.now.to_s)) %></p>
<h2>
<%= t('cbv_flows.summary.header') %>
</h2>
Expand Down
2 changes: 2 additions & 0 deletions app/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ en:
share_with_caseworker: Share with Case Worker
summary:
additional_information_title: Is there anything else you'd like your caseworker to know about your income?
case_number: 'Case number: %{case_number}'
description: Below is payment information from your employer for the past 90 days.
document_timestamp: 'Document origination: %{timestamp}'
form:
additional_info:
label: Is there anything else you'd like your caseworker to know about your income?
Expand Down
6 changes: 3 additions & 3 deletions app/spec/mailers/applicant_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@
expect(mail.body.encoded).to match(I18n.t('applicant_mailer.caseworker_summary_email.body'))
end

it 'attaches a PDF' do
expect(mail.attachments['income_verification.pdf']).to be_present
expect(mail.attachments['income_verification.pdf'].content_type).to start_with('application/pdf')
it 'attaches a PDF which has a file name prefix of {case_number}_timestamp_' do
expect(mail.attachments.any? { |attachment| attachment.filename =~ /\A#{cbv_flow.case_number}_\d{14}_income_verification\.pdf\z/ }).to be true
expect(mail.attachments.first.content_type).to start_with('application/pdf')
end
end
end
9 changes: 6 additions & 3 deletions app/spec/mailers/previews/applicant_mailer_preview.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# Preview all emails at http://localhost:3000/rails/mailers/applicant_mailer
require Rails.root.join('spec/support/test_helpers')
class ApplicantMailerPreview < ActionMailer::Preview
include ViewHelper
include TestHelpers # in order to use stub_payments

def invitation_email
ApplicantMailer.with(email_address: "test@example.com", link: "http://example.com").invitation_email
end

def caseworker_summary_email
payments = stub_payments

cbv_flow = CbvFlow.create(case_number: "ABC1234", argyle_user_id: "abc-def-ghi", email_address: "test@example.com")
payments = stub_payments
cbv_flow = CbvFlow.create(case_number: "ABC1234", argyle_user_id: "abc-def-ghi")
ApplicantMailer.with(cbv_flow: cbv_flow, case_number: "12345", payments: payments).caseworker_summary_email
end
end
Binary file modified docs/app/rendered/database-schema.pdf
Binary file not shown.

0 comments on commit 99b56bb

Please sign in to comment.