-
-
Notifications
You must be signed in to change notification settings - Fork 463
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: move behavior out of rake tasks (#5881)
- Loading branch information
1 parent
b010c18
commit 81298e1
Showing
7 changed files
with
105 additions
and
117 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
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,13 @@ | ||
class VolunteerBirthdayReminderService | ||
def send_reminders | ||
if Time.now.utc.to_date.day == 15 | ||
Volunteer.active.with_supervisor.birthday_next_month.each do |volunteer| | ||
VolunteerBirthdayNotifier | ||
.with(volunteer:) | ||
.deliver(volunteer.supervisor) | ||
end | ||
else | ||
puts "Volunteer Birthday Reminder Rake task skipped. Today is not the 15th of the month." | ||
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,13 +1,4 @@ | ||
desc "Create a notification for supervisors when a volunteer has a birthday coming in the next month, scheduled for the 15th of each month in Heroku Scheduler" | ||
task volunteer_birthday_reminder: :environment do | ||
# Check if the current day of the month is the 15th | ||
if Time.now.utc.to_date.day == 15 | ||
Volunteer.active.with_supervisor.birthday_next_month.each do |volunteer| | ||
VolunteerBirthdayNotifier | ||
.with(volunteer: volunteer) | ||
.deliver(volunteer.supervisor) | ||
end | ||
else | ||
puts "Volunteer Birthday Reminder Rake task skipped. Today is not the 15th of the month." | ||
end | ||
VolunteerBirthdayReminder.new.send_reminders | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
68 changes: 68 additions & 0 deletions
68
spec/services/emancipation_checklist_reminder_service_spec.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe EmancipationChecklistReminderService do | ||
include ActiveJob::TestHelper | ||
|
||
let(:send_reminders) { described_class.new.send_reminders } | ||
|
||
before do | ||
travel_to Date.new(2022, 10, 1) | ||
end | ||
|
||
after do | ||
travel_back | ||
clear_enqueued_jobs | ||
end | ||
|
||
context "with only two eligible cases" do | ||
subject(:task) { described_class.new } | ||
let!(:eligible_case1) { create(:case_assignment) } | ||
let!(:eligible_case2) { create(:case_assignment) } | ||
let!(:ineligible_case1) { create(:case_assignment, pre_transition: true) } | ||
let!(:inactive_case) { create(:case_assignment, :inactive) } | ||
|
||
it "#initialize correctly captures the eligible cases" do | ||
expect(CasaCase.count).to eq(4) | ||
expect(task.cases).to_not be_empty | ||
expect(task.cases.length).to eq(2) | ||
end | ||
end | ||
|
||
context "volunteer with transition age youth case" do | ||
let!(:casa_case) { create(:casa_case, :with_one_case_assignment) } | ||
|
||
it "should send notification" do | ||
expect { send_reminders }.to change { casa_case.case_assignments.first.volunteer.notifications.count }.by(1) | ||
end | ||
end | ||
|
||
context "volunteer with multiple transition age youth cases" do | ||
let!(:volunteer) { create(:volunteer, :with_casa_cases) } | ||
|
||
it "sends notification for each case" do | ||
expect { send_reminders }.to change { volunteer.notifications.count }.by(2) | ||
end | ||
end | ||
|
||
context "volunteer without transition age youth case" do | ||
let!(:casa_case) { create(:casa_case, :with_one_case_assignment, birth_month_year_youth: 13.years.ago) } | ||
|
||
it "should not send notification" do | ||
expect { send_reminders }.not_to change { casa_case.case_assignments.first.volunteer.notifications.count } | ||
end | ||
end | ||
|
||
context "when the case assignment is inactive" do | ||
let!(:case_assignment) { create(:case_assignment, :inactive) } | ||
|
||
it "should not send notification" do | ||
expect { send_reminders }.not_to change { case_assignment.volunteer.notifications.count } | ||
end | ||
end | ||
|
||
context "when there are no case assignments" do | ||
it "does not raise error" do | ||
expect { send_reminders }.not_to raise_error | ||
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