Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Email selected users when reimbursement requests are entered #5208

Merged
merged 8 commits into from
Oct 24, 2023

Conversation

sarvaiyanidhi
Copy link
Contributor

@sarvaiyanidhi sarvaiyanidhi commented Sep 14, 2023

Resolves #4476

What changed, and why?

This PR implements feature of sending email on creation of new reimbursement request to Supervisor if reimbursement notifications enabled

How will this affect user permissions?

  • Volunteer permissions: Not effected
  • Supervisor permissions: Not effected
  • Admin permissions: Not effected

How is this tested? (please write tests!) 💖💪

Have added required tests for email feature.

Screenshots please :)

reimbursement_request_email

Copy link
Collaborator

@littleforest littleforest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this!

@@ -181,6 +185,12 @@ def create_case_contact_for_every_selected_casa_case(selected_cases)
end
end

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
SupervisorMailer.reimbursement_request_email(current_user, current_user.supervisor).deliver
SupervisorMailer.reimbursement_request_email(current_user, current_user.supervisor).deliver_later

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add/modify spec/requests/case_contacts_spec.rb and add an expectation that SupervisorMailer.reimbursement_request_email is called when those conditions are met, and another expection that it is not called when the conditions are not met?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the feedback. Have done the required changes and pushed the updated code.

spec/mailers/supervisor_mailer_spec.rb Show resolved Hide resolved
@@ -3,6 +3,7 @@

RSpec.describe SupervisorMailerPreview do
let!(:supervisor) { create(:supervisor) }
let!(:volunteer) { create(:volunteer) }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make it explicit that the volunteer's supervisor is the supervisor created above? Might get flaky in the future if we don't.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @schoork for the feedback. I have addressed the reported point and pushed the fix. Docker check is failing due to other issue, can you trigger it again and review the changes again to merge it.

@schoork schoork self-assigned this Oct 20, 2023
Comment on lines +27 to +29
if supervisor.receive_reimbursement_email
mail(to: @supervisor.email, subject: "New reimbursement request from #{@volunteer.display_name}")
end
Copy link

@javiguerra777 javiguerra777 Oct 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good use of an if conditional to make sure that receive_reimbursement_email is part of the supervisor parameter before sending mail to the supervisor email

Copy link
Collaborator

@schoork schoork left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work on this!


describe ".reimbursement_request_email" do
let(:supervisor) { create(:supervisor, receive_reimbursement_email: true) }
let(:volunteer) { create(:volunteer) }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make it explicit that the volunteer's supervisor is the supervisor created above? Might get flaky in the future if we don't.

@@ -181,6 +185,12 @@ def create_case_contact_for_every_selected_casa_case(selected_cases)
end
end

def send_reimbursement_email(case_contact)
if case_contact.want_driving_reimbursement_changed? && case_contact.want_driving_reimbursement? && !current_user.supervisor.blank?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you switched this !current_user.supervisor.blank? to reference the case contact's supervisor, you could move the whole if statement into a method on case contact, unit test it, and ensure there are no problems in the future if we allow admins/someone else to submit these on behalf of volunteers. In that case, the current user's supervisor and case contact's supervisor might not be the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the great feedback and changes done in this PR. I have gone through the commit and understood the fixes done in the code.

@@ -19,4 +19,13 @@ def weekly_digest(supervisor)
subject: "Weekly summary of volunteers' activities for the week of #{Date.today - 7.days}"
)
end

def reimbursement_request_email(volunteer, supervisor)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be better to pass the case contact here. You still get volunteer and supervisor, but further down the road we could get more info into the email.

Also see comment for send_reimbursement_email method.

@schoork schoork merged commit 03b4e10 into rubyforgood:main Oct 24, 2023
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
erb ruby Pull requests that update Ruby code Tests! 🎉💖👏
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Email selected users when reimbursement requests are entered
4 participants