Skip to content

Commit

Permalink
Updated specs to check reimbursement mail condition and other fixes a…
Browse files Browse the repository at this point in the history
…s per PR feedback
  • Loading branch information
sarvaiyanidhi committed Sep 22, 2023
1 parent b5c1563 commit 97f0627
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/controllers/case_contacts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def create_case_contact_for_every_selected_casa_case(selected_cases)

def send_reimbursement_email(case_contact)
if case_contact.want_driving_reimbursement_changed? && case_contact.want_driving_reimbursement? && !current_user.supervisor.blank?
SupervisorMailer.reimbursement_request_email(current_user, current_user.supervisor).deliver
SupervisorMailer.reimbursement_request_email(current_user, current_user.supervisor).deliver_later
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<tr style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
<td class="content-block" style="font-family: Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px;" valign="top">
<%= @volunteer.display_name %> has submitted a reimbursement request, please follow up on the reimbursements page
<a href="<%= "#{reimbursements_url}" %>" target="_blank">using this link</a>.
<%= link_to "using this link", reimbursements_url %>.
</td>
</tr>
</table>
2 changes: 2 additions & 0 deletions spec/mailers/supervisor_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@
let(:mail) { SupervisorMailer.reimbursement_request_email(volunteer, supervisor) }

it "sends email reminder" do
expect(mail.subject).to eq("New reimbursement request from #{volunteer.display_name}")
expect(mail.to).to eq([supervisor.email])
expect(mail.body.encoded).to match("#{volunteer.display_name} has submitted a reimbursement request")
end
end
Expand Down
26 changes: 26 additions & 0 deletions spec/requests/case_contacts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,32 @@
end
end

context "reimbursement mail to supervisor" do
let(:case_contact) {create(:case_contact, :wants_reimbursement, casa_case: casa_case, creator: admin)}
let(:supervisor) {create(:supervisor, receive_email_notifications: true)}

it "sends reimbursement request email when conditions are met" do
allow(case_contact).to receive(:want_driving_reimbursement?).and_return(true)
allow(admin).to receive(:supervisor).and_return(supervisor)

mailer_double = double("SupervisorMailer")
allow(SupervisorMailer).to receive(:reimbursement_request_email).and_return(mailer_double)

expect(mailer_double).to receive(:deliver_later)
request
end

it "does not send reimbursement request email when conditions are not met" do
allow(case_contact).to receive(:want_driving_reimbursement?).and_return(false)

mailer_double = double("SupervisorMailer")
allow(SupervisorMailer).to receive(:reimbursement_request_email).and_return(mailer_double)

expect(mailer_double).not_to receive(:deliver_later)
request
end
end

context "with additional expense" do
let(:params) do
{
Expand Down

0 comments on commit 97f0627

Please sign in to comment.