-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow emailing the PDF report to caseworkers
George/ffs 777 (#60) * Consolidating commits as to not expose the email address previously hardcoded, but has since replaced with an env var * fixing rubocop issues * formatting variable * addressing some feedback, cleaning up en translations, updated ApplicantMailer to use in-memory pdf attachment rather than a temp file * removed comment about retrieving the case_number from the session, it's irrelevant * no need for an http [PATCH] route * updating mailer attachment to be properly rendered * tests passing for pdf email attachment to caseworker * added body to caseworker summary email * updated applicant_mailer preview so that the view inherits the appropriate variables * updated share endpoint test to use pinwheel stub... merging main * cbv flows controller tests passing * following a few best practices for applicant_mailer, consolidated view related helpers into a single ViewHelper class, normalized en.yml * updated how the test email is resolved \n Added controller POST /share test * removed SLACK_TEST_EMAIL env var from tests * ran rubocop for linting
- Loading branch information
1 parent
c83417a
commit b36f114
Showing
17 changed files
with
294 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ NGROK_URL= | |
CBV_INVITE_SECRET=development | ||
DOMAIN_NAME=localhost | ||
PINWHEEL_API_TOKEN=API secret | ||
SLACK_TEST_EMAIL= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
app/app/helpers/application_helper.rb → app/app/helpers/view_helper.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,35 @@ | ||
class ApplicantMailer < ApplicationMailer | ||
attr_reader :email_address | ||
before_action :set_params | ||
helper :view | ||
|
||
def invitation_email | ||
@link = params[:link] | ||
mail(to: params[:email_address], subject: I18n.t("applicant_mailer.invitation_email.subject")) | ||
mail( | ||
to: @email_address, | ||
subject: I18n.t("applicant_mailer.invitation_email.subject") | ||
) | ||
end | ||
|
||
def caseworker_summary_email | ||
attachments["income_verification.pdf"] = generate_pdf | ||
mail( | ||
to: @email_address, | ||
subject: I18n.t("applicant_mailer.caseworker_summary_email.subject", case_number: @cbv_flow.case_number), | ||
body: I18n.t("applicant_mailer.caseworker_summary_email.body") | ||
) | ||
end | ||
|
||
private | ||
|
||
def set_params | ||
@cbv_flow = params[:cbv_flow] | ||
@email_address = params[:email_address] | ||
@link = params[:link] if params[:link] | ||
@payments = params[:payments] if params[:payments] | ||
end | ||
|
||
def generate_pdf | ||
WickedPdf.new.pdf_from_string( | ||
render_to_string(template: "cbv_flows/summary", formats: [ :pdf ]) | ||
) | ||
end | ||
end |
5 changes: 5 additions & 0 deletions
5
app/app/views/applicant_mailer/caseworker_summary_email.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<%= t('.greeting') %> | ||
<%= t('.body') %> | ||
<%= t('.thank_you') %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe CbvFlowsController do | ||
include PinwheelApiHelper | ||
|
||
around do |ex| | ||
stub_environment_variable("PINWHEEL_API_TOKEN", "foobar", &ex) | ||
stub_environment_variable("SLACK_TEST_EMAIL", "[email protected]", &ex) | ||
end | ||
|
||
describe "#entry" do | ||
|
@@ -17,8 +19,8 @@ | |
it "sets a CbvFlow object in the session" do | ||
expect { get :entry } | ||
.to change { session[:cbv_flow_id] } | ||
.from(nil) | ||
.to(be_an(Integer)) | ||
.from(nil) | ||
.to(be_an(Integer)) | ||
end | ||
|
||
context "when following a link from a flow invitation" do | ||
|
@@ -27,14 +29,14 @@ | |
it "sets a CbvFlow object based on the invitation" do | ||
expect { get :entry, params: { token: invitation.auth_token } } | ||
.to change { session[:cbv_flow_id] } | ||
.from(nil) | ||
.to(be_an(Integer)) | ||
.from(nil) | ||
.to(be_an(Integer)) | ||
|
||
cbv_flow = CbvFlow.find(session[:cbv_flow_id]) | ||
expect(cbv_flow).to have_attributes( | ||
case_number: "ABC1234", | ||
cbv_flow_invitation: invitation | ||
) | ||
case_number: "ABC1234", | ||
cbv_flow_invitation: invitation | ||
) | ||
end | ||
|
||
context "when returning to an already-visited flow invitation" do | ||
|
@@ -43,8 +45,8 @@ | |
it "uses the existing CbvFlow object" do | ||
expect { get :entry, params: { token: invitation.auth_token } } | ||
.to change { session[:cbv_flow_id] } | ||
.from(nil) | ||
.to(existing_cbv_flow.id) | ||
.from(nil) | ||
.to(existing_cbv_flow.id) | ||
end | ||
end | ||
|
||
|
@@ -58,8 +60,8 @@ | |
it "replaces the session's CbvFlow id with the one from the link token" do | ||
expect { get :entry, params: { token: invitation.auth_token } } | ||
.to change { session[:cbv_flow_id] } | ||
.from(other_cbv_flow.id) | ||
.to(be_an(Integer)) | ||
.from(other_cbv_flow.id) | ||
.to(be_an(Integer)) | ||
end | ||
end | ||
|
||
|
@@ -115,8 +117,8 @@ | |
skip "saves the token in the CbvFlow model" do | ||
expect { get :employer_search } | ||
.to change { cbv_flow.reload.pinwheel_token_id } | ||
.from(nil) | ||
.to(pinwheel_token_id) | ||
.from(nil) | ||
.to(pinwheel_token_id) | ||
end | ||
end | ||
end | ||
|
@@ -128,6 +130,8 @@ | |
|
||
before do | ||
session[:cbv_flow_id] = cbv_flow.id | ||
stub_request_end_user_accounts_response | ||
stub_request_end_user_paystubs_response | ||
end | ||
|
||
skip "renders properly" do | ||
|
@@ -142,8 +146,8 @@ | |
expect do | ||
patch :summary, params: { cbv_flow: { additional_information: additional_information } } | ||
end.to change { cbv_flow.reload.additional_information } | ||
.from(nil) | ||
.to(additional_information) | ||
.from(nil) | ||
.to(additional_information) | ||
|
||
expect(response).to redirect_to(cbv_flow_share_path) | ||
end | ||
|
@@ -157,11 +161,27 @@ | |
|
||
before do | ||
session[:cbv_flow_id] = cbv_flow.id | ||
stub_request_end_user_paystubs_response | ||
stub_request_end_user_accounts_response | ||
end | ||
|
||
it "renders" do | ||
get :share | ||
expect(response).to be_successful | ||
end | ||
|
||
context "when sending an email to the caseworker" do | ||
let(:email_address) { "[email protected]" } | ||
|
||
it "sends the email" do | ||
expect do | ||
post :share | ||
end.to change { ActionMailer::Base.deliveries.count }.by(1) | ||
|
||
email = ActionMailer::Base.deliveries.last | ||
expect(email.to).to eq([ email_address ]) | ||
expect(email.subject).to eq("Applicant Income Verification: ABC1234") | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe ApplicantMailer, type: :mailer do | ||
|
||
around do |ex| | ||
stub_environment_variable("SLACK_TEST_EMAIL", "[email protected]", &ex) | ||
end | ||
|
||
let(:payments) { stub_payments } | ||
let(:email) { '[email protected]' } | ||
let(:link) { 'www.google.com' } | ||
let(:mail) { ApplicantMailer.with(email_address: email, link: link).invitation_email } | ||
|
@@ -20,4 +26,32 @@ | |
it "renders the body" do | ||
expect(mail.body.encoded).to match(I18n.t('applicant_mailer.invitation_email.body')) | ||
end | ||
|
||
describe 'caseworker_summary_email' do | ||
let(:cbv_flow) { CbvFlow.create(case_number: "ABC1234", argyle_user_id: "abc-def-ghi") } | ||
let(:email_address) { "[email protected]" } | ||
let(:mail) { | ||
ApplicantMailer.with( | ||
email_address: email_address, | ||
cbv_flow: cbv_flow, | ||
payments: payments).caseworker_summary_email.deliver_now | ||
} | ||
|
||
it 'renders the subject with case number' do | ||
expect(mail.subject).to eq(I18n.t('applicant_mailer.caseworker_summary_email.subject', case_number: cbv_flow.case_number)) | ||
end | ||
|
||
it 'sends to the correct email' do | ||
expect(mail.to).to eq([ email_address ]) | ||
end | ||
|
||
it 'renders the body' do | ||
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') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,11 @@ class ApplicantMailerPreview < ActionMailer::Preview | |
def invitation_email | ||
ApplicantMailer.with(email_address: "[email protected]", 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: "[email protected]") | ||
ApplicantMailer.with(cbv_flow: cbv_flow, case_number: "12345", payments: payments).caseworker_summary_email | ||
end | ||
end |
23 changes: 23 additions & 0 deletions
23
app/spec/support/fixtures/pinwheel/request_end_user_accounts_response.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"data": [ | ||
{ | ||
"connected": true, | ||
"created_at": "2021-01-06T15:59:13.530178+00:00", | ||
"data_refreshed_at": { | ||
"direct_deposit_allocations": "2021-01-09T00:00:00.000000+00:00" | ||
}, | ||
"data_updated_at": { | ||
"direct_deposit_allocations": "2021-01-08T00:00:00.000000+00:00" | ||
}, | ||
"end_user_id": "my_user_12345", | ||
"id": "eb240ec6-a227-47ca-b7c7-fbbdfe7170a0", | ||
"link_token_id": "bd2c09e7-1303-46d5-87c0-0ffa572d7ae4", | ||
"monitoring_status": "active", | ||
"platform_id": "fce3eee0-285b-496f-9b36-30e976194736" | ||
} | ||
], | ||
"meta": { | ||
"count": 1, | ||
"next_cursor": "eyJuYW1lIjogImFtYXpvbiJ9" | ||
} | ||
} |
Oops, something went wrong.